cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
403 stars 134 forks source link

From version "0.50.4" models with $ref and nullable: true, are generated without null. #301

Closed lubowiecki closed 1 year ago

lubowiecki commented 1 year ago

Example:

input contract.json { "openapi": "3.0.3", "info": {}, "servers": [], "tags": [], "paths": {}, "components": { "schemas": { "IsoDateWithTimeDto": { "type": "string", }, "Dates": { "title": "Dates", "type": "object", "properties": { "activation": { "$ref": "#/components/schemas/IsoDateWithTimeDto", "nullable": true }, }, }, "User": { "title": "User", "type": "object", "properties": { "firstname": { "type": "string", "nullable": true }, }, } } } }

it generates: import { IsoDateWithTimeDto } from '../models/iso-date-with-time-dto'; export interface Dates { activation?: IsoDateWithTimeDto; }

and

export interface User { firstname?: string | null; }

While it should be: import { IsoDateWithTimeDto } from '../models/iso-date-with-time-dto'; export interface Dates { activation?: IsoDateWithTimeDto **| null**; }

luisfpg commented 1 year ago

This is a limitation of OpenApi: $ref just ignores all sibling properties and is like a 'copy/paste' of the referenced content. Try the following:

{
"Dates": { 
  "title": "Dates", 
  "type": "object", 
  "properties": { 
    "activation": { 
      "nullable": true,
      "allOf": [
        { "$ref": "#/components/schemas/IsoDateWithTimeDto" }
      ]
    }
  }
}