pipermerriam/flex

Parameter in the uri segment matters.

Fufuhu opened this issue · 4 comments

Hi,

I faced a problem when I tried to get summary statement under paths.
Sample swagger snippet is following.

   /api/v1/search/:
        post:
            summary: search
            description: |
               search something
            consumes:
                - application/json
            produces:
                - application/json
            responses:
                200:
                    description: success
                500:
                    description: failure

    /api/v1/{vxlan_id}/:
        get:
            summary: id check
            description: |
                Check id.
            consumes:
                - application/json
            produces:
                - application/json
            parameters:
                - name: vxlan_id
                  in: path
                  description: logical_switch_id
                  required: true
                  type: string
                  pattern: ^[a-z]{1}[a-z0-9\-_]{0,63}$
                  maxLength: 64
                  minLength: 1
            responses:
                200:
                    description: success
                500:
                    description: failure

When I want to know the summary statement of '/api/v1/search/',
I use match_path_to_api_path('/api/v1/search/') to get the statements under '/api/v1/search/:'.

However, match_path_to_api_path('/api/v1/search/') returns '/api/v1/{vxlan_id}/'
because maybe '/api/v1/{vxlan_id}/' is longer than '/api/v1/search/' by 4 characters.

I don't know the specification of swagger well, but simple comparison should
take priority over regular expression comparison, I think.

I'm not accustomed to using English, so there might be problems to understand.
In the case, please ask a question.

To solve this issue I made a PR.

Regards,

I made a PR #151 .
I'm neigher an application engineer nor pythonista, so there might be bad implementation.
When you notice that there are bad things, please let me know.

Interesting. This is definitely problematic because a path can match to both. I haven't had a chance to read the swagger documentation yet, but is this really okay?

As long as I know, there's no rule for matching priority in swagger.
It's natural that exact matching should have higher priority over regular expression matching.

closed via #151