airtasker / spot

Spot is a concise, developer-friendly way to describe your API contract.
Other
555 stars 38 forks source link

Nullable object fields don't get generated correctly #2058

Open valzam opened 1 year ago

valzam commented 1 year ago

Describe the bug A TS type like this

interface A {
 foo: string;
}

interface B {
 bar: A | null
}

results in the following OpenAPI spec:

components:
 schema:
    B:
      type: object
      properties:
        bar:
          $ref: '#/components/schemas/A'
          nullable: true

This doesn't work as expected in OpenAPI 3.0 (the nullable is simply ignored) https://github.com/OAI/OpenAPI-Specification/issues/1368

Expected behavior The field definition needs to use allOf

bar:
  nullable: true
  allOf:
  - $ref: '#/components/schemas/A'

https://stackoverflow.com/questions/40920441/how-to-specify-a-property-can-be-null-or-a-reference-with-swagger

Desktop (please complete the following information): Spot version 1.9.0

lfportal commented 1 year ago

I do remember this one. To add further context: https://github.com/airtasker/spot/blob/f93055e2fc75590a7cc589972753990fdb86e1a1/lib/src/generators/openapi3/openapi3-specification.ts#L89-L121