3

I am playing around with Open API 3.0 by downloading the source code for server, here.

  • Access the link
  • Choose Generate Server on menu bar
  • Choose nodejs-server

I simply follow the instruction in README.md to run the server by executing npm start.

After that, I access the URL http://localhost:8080/docs. However, there is no Request body in the swagger page. More specifically, you can see in the picture as following

enter image description here

The code in yaml file for this api as following

/pet:
  put:
    tags:
    - pet
    summary: Update an existing pet
    operationId: updatePet
    requestBody:
      description: Pet object that needs to be added to the store
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'
        application/xml:
          schema:
            $ref: '#/components/schemas/Pet'
      required: true
    responses:
      "400":
        description: Invalid ID supplied
        content: {}
      "404":
        description: Pet not found
        content: {}
      "405":
        description: Validation exception
        content: {}
    security:
    - petstore_auth:
      - write:pets
      - read:pets
    x-codegen-request-body-name: body
    x-swagger-router-controller: Pet

On the other hand, the things showed in https://editor.swagger.io/ are somehow different, but yaml file is exactly the same.

enter image description here How can I make the swagger on my local machine show Request body as in https://editor.swagger.io/?

Uvuvwevwevwe
  • 971
  • 14
  • 30
  • 1
    Your local Swagger UI version is probably outdated. To learn what version you use, open the browser dev tools > Console tab and evaluate `versions`. The latest version is 3.24.3; if yours is older you'll most likely need to update it. – Helen Nov 25 '19 at 08:15
  • Hi @Helen, you are right! The problem is solved! – Uvuvwevwevwe Nov 25 '19 at 10:12
  • 1
    Possible duplicate of [“Request body” doesn't appears on Swagger UI](https://stackoverflow.com/a/55806780/113116) – Helen Nov 25 '19 at 10:37
  • Hi @Helen, actually I just tried using `swagger-ui-express` instead of `oas3-tools` to solve the problem. I also check the swagger ui version for `swagger-ui-express` as you suggested by `JSON.stringify(versions);` in browser dev tools that shown `{"swaggerUi":{"version":"3.24.3",...}}`. The question is: Should I use `oas3-tools` or `swagger-ui-express`? – Uvuvwevwevwe Nov 25 '19 at 10:55
  • I don't know, I'm not really familiar with any of those libraries. – Helen Nov 25 '19 at 11:06

0 Answers0