cloud-annotations / docusaurus-openapi

🦕 OpenAPI plugin for generating API reference docs in Docusaurus v2.
https://docusaurus-openapi.netlify.app
MIT License
498 stars 82 forks source link

Prevent crash in createExample when a multi variant type is being parsed. All variants are concatinated with '|'. Also added a "null" type wich is not the """null""" type, made sure to extra check against this. #267

Open brymko opened 10 months ago

brymko commented 10 months ago

While running this project on our API generated OAPI spec i found it to be crashing when running into variant types. For instance incase there is an optional field:

"properties": {
  "is_active": {
    "type": [
      "boolean",
      "null"
    ]
  }

This merge is forwarding my local fix

netlify[bot] commented 10 months ago

Deploy Preview for docusaurus-openapi ready!

Name Link
Latest commit a604750fc5fc459342a4b4922ee4aea9e7a846b8
Latest deploy log https://app.netlify.com/sites/docusaurus-openapi/deploys/656eabb102fd86000874c6d7
Deploy Preview https://deploy-preview-267--docusaurus-openapi.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

brymko commented 10 months ago

Im not sure if my default assumption of concating everyting with "|" together holds. Because this is only an example maybe we only want the first element ?|

As an example, this would be generated with the proposed changes:

curl -L -X GET 'some_path'' \
-H 'Content-Type: application/json' \
-H 'Accept: text/plain; charset=utf-8' \
-d '{
  "is_active": "true | null",
 }

Now this would obviously be rejected by the server, but so would all context aware data. And given that this should only server as a default i think it might be fine. Open for thoughts.