contiamo / restful-react

A consistent, declarative way of interacting with RESTful backends, featuring code-generation from Swagger and OpenAPI specs 🔥
MIT License
1.87k stars 109 forks source link

Openapi null type #271

Closed cmaus-cs closed 4 years ago

cmaus-cs commented 4 years ago

Why

I encountered a problem where the openapi spec had a nullable type defined as

oneOf:
  - $ref: 'someRef'
  - type: null

This was translated into SomeRef | any because the type "null" was not supported explicitly as a scalar type

netlify[bot] commented 4 years ago

Deploy request for restful-react accepted.

Accepted with commit b5085a278213a006f7299f4e52a1e64aa4c8ac85

https://app.netlify.com/sites/restful-react/deploys/5edca882572baa00073d4168

fabien0102 commented 4 years ago

Hello @cmaus-cs 👋

Thanks for you contribution, it's always appreciated! but… type: null is actually not valid in open-api 🙄

A screenshot/link of the specification for this part: image https://swagger.io/specification/#data-types

In short, you need to add nullable: true on your type, so something like this with your example

components:
  schemas:
    someRef:
       type: object
       nullable: true
       properties:
          ...
cmaus-cs commented 4 years ago

Thanks for the suggestion, but I cannot rewrite the spec.

Please note that in v3.1 of the openapi-spec nullable is dropped completely and its usage is supposed to be replaced by using the the type "null".

https://github.com/OAI/OpenAPI-Specification/blob/v3.1.0-dev/versions/3.1.0.md

fabien0102 commented 4 years ago

Indeed! I missed this update of open-api, with this in mind, your PR make totally sense 😃

fabien0102 commented 4 years ago

v14.0.0 incomming for you 😉

fabien0102 commented 4 years ago

image

or not… sorry, I need to debug this…