openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

feat: Support nullable on allOf schemas

Open Cellule opened this issue 1 year ago • 0 comments

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

Cellule avatar Mar 13 '24 20:03 Cellule