Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support nullable on allOf schemas #229

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cellule
Copy link

@Cellule Cellule commented Mar 13, 2024

I'm currently using @nestjs/swagger and for nested references it generates the following openapi schema (trimmed for readability):

{
  "openapi": "3.0.0",
  "paths": {},
  "components": {
    "schemas": {
      "HydratedAssetDto": {
        "type": "object",
        "properties": {}
      },
      "HydratedPackageDto": {
        "type": "object",
        "properties": {
          "asset": {
            "nullable": true,
            "allOf": [{ "$ref": "#/components/schemas/HydratedAssetDto" }]
          }
        }
      }
    }
  }
}

In my case I need to ensure HydratedPackageDto.asset will have type HydratedAssetDto | null
I was using https://www.npmjs.com/package/openapi-typescript before and it was generating that type for allOf with nullable
I didn't go through the spec to 100% confirm this is legal, but it looks fine 😅
If you have a suggestion on how to get to the same result with a different schema I'm all ears

@BijanRegmi
Copy link

why is this not merged yet? Shouldn't this should be default behavior.

Copy link

@Aakashx2838 Aakashx2838 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 🔥 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants