Closed lubowiecki closed 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" }
]
}
}
}
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**; }