cancel
Showing results for 
Search instead for 
Did you mean: 

Define a parameter for both path and body (in different paths)

Highlighted
Occasional Visitor

Define a parameter for both path and body (in different paths)

Hi all,
I'm just starting with SwaggerHub.
In my definition I'd like to share the definition of a parameter that I need to use both in a path and body position.

I wrote something like but I've got always some kind of error:

/root/{deviceId}/config:
    post:
      tags:
      - "Parameters"
      parameters:
      - $ref: "#/definitions/DeviceID"
  DeviceID:
    type: string
    description: Generato a partire dal MAC address
    example: AABBCCEE

Declared path parameter "deviceId" needs to be defined as a path parameter at either the path or operation level

If I add:

in: path

I get the error that sibling values are not allowed ..

I'd like to define a simple type that defines and documents the parameter used in path like:

/root/{deviceID}/config

and used in body ilke:

/root/ann

{
...
 "deviceID": "AAABBB",
...
}

Thanks!

2 REPLIES 2
Community Hero

Re: Define a parameter for both path and body (in different paths)

@SteMMo
Please see if below documentation helps!
https://swagger.io/docs/specification/basic-structure/


Regards,
Rao.
Moderator

Re: Define a parameter for both path and body (in different paths)

Hi SteMMo,

 

This is not possible in OpenAPI 2.0 - you'll need to refine the DeviceID type inline both in the path parameter and in the body parameter schema.

 

However, this is possible in OpenAPI 3.0 should you decide to convert your definition to the new spec version.

openapi: 3.0.0
...
paths:
  /root/{deviceId}/config:
    post:
      parameters:
      - in: path
        name: deviceId
        required: true
        schema:
          $ref: '#/components/schemas/DeviceID'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestBodySchema'
      responses:
        '200':
          description: OK

components:
  schemas:
    DeviceID:
      type: string
      description: Generato a partire dal MAC address
      example: AABBCCEE

    RequestBodySchema:
      type: object
      properties:
        deviceID:
          $ref: '#/components/schemas/DeviceID'
        ...

 


Helen Kosova
SmartBear Technical Writer
________________________
Vote up helpful replies.
Accept this reply if you think it's the best solution to your question.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors