pyopenapi / pyswagger

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.
MIT License
385 stars 89 forks source link

Parameter referencing in PathItemObject.parameters. #105

Closed mopaul closed 7 years ago

mopaul commented 7 years ago

My swagger definition defines a bunch of query parameters in the root.parameters which I then reference from the pathItem.parameters section. When I try to access the operation parameters using app.op.parameters, it looks like only the 1st parameter referenced in pathItem.parameters is associated with the path's Operation object.

If I understand the swagger definition, pathItems.parameters are applicable to all the operations in the path.

Am I missing something?

Referencing a parameter from operation.parameters works as expected.

mission-liao commented 7 years ago

It should work when each $ref points to one parameter definition under root.parameters. I just add a test case for it, could you check if this is what you expected? test-spec test-case

If this is not what you described, could you help to provide a sample swagger.json/yaml and code?

mopaul commented 7 years ago

I meant referencing a parameter in the path.parameter section. Something like this.

"paths":{
      "/a":{
         "get":{
            "parameters":[
               {
                  "name":"p2",
                  "in":"body",
                  "schema":{
                     "$ref":"#/definitions/d1"
                  }
               }
            ],
            "responses":{
               "default":{
                  "$ref":"#/responses/r1"
               }
            }
         },
         "parameters": [
            {
               "$ref":"#/parameters/p1"
            },
            {
               "$ref":"#/parameters/p2"
            }
         ]
      }
   }

The parameters p1 and p2 are being referenced from the path.parameters and not operation.parameters. I can only see p2 and p1_d associated with the operation but (if I understand the swagger spec correctly), p2, p1_d and p2_d are all valid parameters.

Let me know if you want me to send a PR with a test case.

mission-liao commented 7 years ago

The case you described is new to me, and yes, it's spec compliant. Any PR with test case is welcome, thanks.

mopaul commented 7 years ago

PR 106 has the test case.

mission-liao commented 7 years ago

OK, thanks. I'll work on this part tomorrow evening.

mission-liao commented 7 years ago

this bug is fixed in v0.8.26, please feel free to reopen it when it's still failed.

mopaul commented 7 years ago

Fix verified. Thanks for your quick responses.