0

I have built the JSON request below which works fine. But how to provide the $ref if the request media type is application/x-www-form-urlencoded?

For example, you can see the schema Filters which I have created. I want to provide the reference to that in the NewDogRequest.Filter parameter.

openapi: 3.0.2
info:
  description: RESTful web services for writing and reading Dogs Data.
  version: v1.0
  title: Dogs Services
tags:
  - name: Dogs
paths:
  /dogs:
    post:
      tags:
        - Dogs
      summary: Add new dogs data.
      description: Use this service when you want to add a new dog.
      operationId: addDog
      requestBody:
        $ref: '#/components/requestBodies/NewDogRequest'
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                  type: string

components:
  # ****************** Request Bodies ****************** #
  requestBodies:
    NewDogRequest:
      content:
        application/x-www-form-urlencoded:
          schema:
            type: object
            properties:
              dogID:
                description: >
                  * Unique dog id.
                type: string
             
              filter:
                description: >
                  Specifies the type breed of the dog
                type: string
                enum:
                  - German Sheperd
                  - Husky
                  - DashHound
                default: German Sheperd

  # ****************** Schemas ****************** #
  schemas:
    Filters:
      type: string
      enum:
        - German Sheperd
        - Husky
        - DashHound
      default: German Sheperd

Tried the following, but it didn't work. If you see the image that I have attached the enums are not rendered in the html.

requestBodies:
    NewDogRequest:
      content:
        application/x-www-form-urlencoded:
          schema:
            type: object
            properties:
              dogID:
                description: >
                  * Unique dog id.
                type: string
             
              filter:
                description: >
                  Specifies the type breed of the dog
                $ref: '#/components/schemas/Filters'

Swagger editor image

  • Your 2nd example is valid. What do you mean by "it didn't work"? What result do you expect (and in what tool) and what actually happens? If the issue is that the `description` ("Specifies the type breed of the dog") alongside the `$ref` is ignored, see [this answer](https://stackoverflow.com/a/41752575/113116) for an explanation and solution. – Helen Jan 30 '23 at 05:51
  • @Helen I have attached the screenshot of swagger editor. It didn't work in the sense that the enums are not rendered in the HTML section. – Warren D'souza Jan 30 '23 at 06:51

0 Answers0