Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Edtior Post Request Example: 😱 Could not render n, see the console

I'm having trouble rendering an example request body in openapi. I've distilled it down to this simple example:

openapi: 3.0.2
info:
  title: Test
  version: "1"
paths:
  /Users:
    post:
      requestBody:
        content:
          application/json:
            example: 
              name: "John"
              
      responses:
        "200":
          description: Fetches them
          content:
            application/json:
              example:
                - name: John Doe
                

https://editor.swagger.io/# and a few other tools can't seem to render the Request body. All I get is:

😱 Could not render n, see the console.

Although, the response body renders fine as expected.

What am I doing wrong here

like image 517
Des Horsley Avatar asked Jul 27 '20 07:07

Des Horsley


1 Answers

Exactly i am not sure why you want to add only example without schema, yes we can say its a kind of bug in swagger-ui,

See the console error in swagger editor,

swagger-editor-bundle.js:sourcemap:33 TypeError: Cannot read property 'toJS' of undefined
    at c (swagger-editor-bundle.js:sourcemap:33)
    at t.default (swagger-editor-bundle.js:sourcemap:33)
    at n.value (swagger-editor-bundle.js:sourcemap:33)
    at n.R.t.render (swagger-editor-bundle.js:sourcemap:33)
    at u._renderValidatedComponentWithoutOwnerOrContext (swagger-editor-bundle.js:sourcemap:100)
    at u._renderValidatedComponent (swagger-editor-bundle.js:sourcemap:100)
    at u.performInitialMount (swagger-editor-bundle.js:sourcemap:100)
    at u.mountComponent (swagger-editor-bundle.js:sourcemap:100)
    at Object.mountComponent (swagger-editor-bundle.js:sourcemap:13)
    at u.performInitialMount (swagger-editor-bundle.js:sourcemap:100)

This is strange its working when specify schema type in requestBody, it will help you for temporary fix, like this,

requestBody:
  content:
    application/json:
      schema:
        type: object
      example: 
        name: "John"

For more details Media Type Specification

like image 62
turivishal Avatar answered Oct 22 '22 19:10

turivishal