cancel
Showing results for 
Search instead for 
Did you mean: 
Welcome to the September Hub-bub

We are inviting you to join our exciting online event where you can learn a lot of useful information, share your knowledge and have fun. Each week, we will reward the best posters with free gift cards .

Just pick any topic you like in the SwaggerHub Community, or create your own to dive into the wonderful September Hub-bub.

Event duration: September 2-27. More information.

This Week Top Contributors:

We will decide the winners next Monday

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.

Join the September Hub-bub to show off, learn and win
New Here?
Join us and watch the welcome video:
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win