Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger:Issue with Path parameter

Tags:

swagger

apigee

I am try to create a swagger file with the following path: paths: /v1/customers/{id}/summary :

However I get the following error right off bat:

API requires path parameter but it is not defined: id at paths ▹ /v1/customers/{id}/summary

It does not seem to like the 'id' parameter. Could anybody tell me how I could rectify this?

If I drill down on this I see the following:

Details  Object  swaggerError: Object  errors: Array [1]  0: Object code:  "MISSING_API_PATH_PARAMETER" message:  "API requires path parameter but it is not defined: id" data:  "/v1/customers/{id}/summary"  path: Array [2]  warnings: Array [0] 
like image 576
user2825273 Avatar asked Nov 26 '14 17:11

user2825273


People also ask

How do I give a path to swagger?

Swagger supports path templating, meaning you can use curly braces {} to mark parts of a URL as path parameters: /users/{id} /organizations/{orgId}/members/{memberId}

How do you specify optional parameters in swagger?

You can use the default key to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter's data type.

What is path parameter in API?

The path parameter defines the resource location, while the query parameter defines sort, pagination, or filter operations. The user's input (the query) is passed as a variable in the query parameter, while each path parameter must be substituted with an actual value when the client makes an API call.


1 Answers

Basically, you're declaring a path that has a path parameter in it, by using path templates. In this case {id} declares a path parameter called id.

When you declare such a path, it means that you have to declare that path parameter as part of the operation.

Take a look at this YAML example:

  /pets/{id}:     get:       description: Returns a user based on a single ID, if the user does not have access to the pet       operationId: findPetById       produces:         - application/json         - application/xml         - text/xml         - text/html       parameters:         - name: id           in: path           description: ID of pet to fetch           required: true           type: integer           format: int64       responses:         '200':           description: pet response           schema:             $ref: '#/definitions/pet'         default:           description: unexpected error           schema:             $ref: '#/definitions/errorModel' 

You can see there's an {id} in the path, and a corresponding id parameter definition. Without it, the spec won't be valid.

like image 97
Ron Avatar answered Sep 21 '22 05:09

Ron