1

I' writing the docs for web API with swagger, OpenAPI version 3. I use swagger php package to generate documented json from annotations. I have service, where I send post request to add new user, and requested body is json(so parameters are sent as json object). it has 2 parameters - email and password. request body looks like

{
   "email": "[email protected]",
   "password": "test"
}

here's YAML of swagger

paths:
  /users:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SignUp'
      responses:
        '200':
          description: successful operation

here's reference schema which contains request parameters (/components/schemas/SignUp)

SignUp:
  title: SignUp
  description: Adds new user
  type:object
  required:
    - email
    - password
  properties:
    email:
      description: User's email
      type: string
      maximum: 255
      pattern: email
    password:
      description: User's password
      type: string
      maximum: 255

here's how it looks in swagger UI enter image description here as you can see on image, requested body is empty(while I have 2 parameters) and this is the issue. if I change the header from application/json to application/x-www-form-urlencoded then it will work(it will show all parameters in parameters list). how to make it show json object parameters in that list?

1 Answer 1

2

Your spec is correct and the displayed result in Swagger UI is correct and exactly as expected for OpenAPI 3.0 definitions.

Note there are two sections, "Parameters" (for parameters) and "Request body" (for requestBody). In OpenAPI 3.0, parameters is only used for query parameters, path parameters, request headers and cookies; whereas requestBody is displayed in the "Request body" section. You can click "Model" link to view the request body schema with property descriptions.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for reply. I know about parameters and request body. so its not possible to show them in that list? I have models for it also, where everything is described, but I want to show this in list
It's not possible in the standard Swagger UI, but Swagger UI is open-source so you can fork and change it as you wish. But keep in mind that users familiar with the standard Swagger UI might get confused if things are displayed in unexpected places.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.