Openapi-generator: [BUG][TYPESCRIPT FETCH] Nullable dates produce compilation error

Created on 30 Aug 2019  路  2Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [ ] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

generated code failed to compile with the following error

Object is possibly 'null'.  TS2531
'documentTypeName': value.documentTypeName,
'documentNo': value.documentNo,
'issueDate': value.issueDate === undefined ? undefined : value.issueDate.toISOString(),
                                                         ^
        };
    }

the generated interface for the value variable is as follows

export interface BillingDocumentReferenceMetadata {
    /**
     * Document type, e.g. invoice, credit note, order, etc.
     * @type {string}
     * @memberof BillingDocumentReferenceMetadata
     */
    documentType?: BillingDocumentReferenceMetadataDocumentTypeEnum;
    /**
     * Document type name, e.g. invoice, credit note, order, etc.
     * @type {string}
     * @memberof BillingDocumentReferenceMetadata
     */
    documentTypeName?: string;
    /**
     * Document number.
     * @type {string}
     * @memberof BillingDocumentReferenceMetadata
     */
    documentNo?: string;
    /**
     * Document issue date (optional).
     * @type {Date}
     * @memberof BillingDocumentReferenceMetadata
     */
    issueDate?: Date | null;
}
export function BillingDocumentReferenceMetadataToJSON(value?: BillingDocumentReferenceMetadata): any {
    if (value === undefined) {
        return undefined;
    }
    return {
        'documentType': value.documentType,
        'documentTypeName': value.documentTypeName,
        'documentNo': value.documentNo,
        'issueDate': value.issueDate === undefined ? undefined : value.issueDate.toISOString(),
    };
}
openapi-generator version


version 4.1.1

OpenAPI declaration file content or url

Part of the swagger.json file that describes the BillingDocumentReferenceMetadata


"BillingDocumentReferenceMetadata": {
    "type": "object",
    "properties": {
        "documentType": {
            "enum": [
                "Invoice",
                "CreditNote",
                "Order",
                "Unspecified"
            ],
            "type": "string",
            "description": "Document type, e.g. invoice, credit note, order, etc."
        },
        "documentTypeName": {
            "type": "string",
            "description": "Document type name, e.g. invoice, credit note, order, etc."
        },
        "documentNo": {
            "type": "string",
            "description": "Document number."
        },
        "issueDate": {
            "type": "string",
            "description": "Document issue date (optional).",
            "format": "date-time",
            "nullable": true
        }
    },
    "additionalProperties": false,
    "description": "Metadata of the reference to another business document."
},
Command line used for generation


npx openapi-generator generate -i http://localhost:5003/swagger/v1/swagger.json -g typescript-fetch -o ./src/ApiClient

Steps to reproduce

Generate a typescript fetch client from a json file that contains a nullable date

TypeScript Bug

All 2 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Was this page helpful?
0 / 5 - 0 ratings