Open glennwillems opened 3 years ago
We found out that if your responsemodel is an empty class it will not generate the let _mappings: { source: any, target: any }[] = [];
line. So would this be regarded as a bug or works as inteded?
This is definitely a bug. I'm seeing the same, but with a empty class that inherits from a non-empty base class.
Confirmed that adding a simple public string bool Anything { get; set; } = true
to my response class fixed the problem.
Using NSwag.MsBuild 13.10.8 in a .net Core Library project. I have an issue generating my typescript client where some process methods do not have the _mappings variable initialized.
I have selected 2 routes where one has the correct _mappings variable and the other that is missing it. Both are HttpPost without any fancy setup in Asp.net Core Web Api.
Open api spec:
{ "x-generator": "NSwag v13.10.8.0 (NJsonSchema v10.3.11.0 (Newtonsoft.Json v12.0.0.0))", "openapi": "3.0.0", "info": { "title": "My Title", "version": "1.0.0" }, "paths": { "/api/backoffice/orders/cancel": { "post": { "tags": [ "Order" ], "operationId": "Order_CancelOrder", "requestBody": { "x-name": "parameters", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CancelOrderParameters" } } }, "required": true, "x-position": 1 }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CancelOrderResult" } } } } } } }, "/api/backoffice/orders/betalen": { "post": { "tags": [ "Order" ], "summary": "Start payment procedure for the specified order. For test purposes only because this will only be used throught the Public API.", "operationId": "Order_BetaalOrder", "requestBody": { "x-name": "parameters", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BetaalOrderPublicParameters" } } }, "required": true, "x-position": 1 }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/BetaalOrderResult" } } } } } } }, }, "components": { "schemas": { "CancelOrderResult": { "type": "object", "additionalProperties": false }, "CancelOrderParameters": { "type": "object", "additionalProperties": false, "properties": { "order": { "nullable": true, "oneOf": [ { "$ref": "#/components/schemas/OrderSelector" } ] } } }, "BetaalOrderResult": { "type": "object", "additionalProperties": false, "properties": { "redirectionUrl": { "type": "string", "nullable": true }, "redirectionVersion": { "type": "string", "nullable": true }, "redirectionData": { "type": "string", "nullable": true } } }, "BetaalOrderPublicParameters": { "type": "object", "additionalProperties": false, "properties": { "order": { "nullable": true, "oneOf": [ { "$ref": "#/components/schemas/OrderSelector" } ] }, "betalingOkUri": { "type": "string", "nullable": true }, "betalingMisluktUri": { "type": "string", "nullable": true }, "language": { "type": "string", "nullable": true } } } } } }
My code generator config:
"codeGenerators": { "openApiToTypeScriptClient": { "className": "{controller}Api", "moduleName": "", "namespace": "", "typeScriptVersion": 4.0, "template": "Angular", "promiseType": "Promise", "httpClass": "HttpClient", "useSingletonProvider": false, "injectionTokenType": "InjectionToken", "rxJsVersion": 6.0, "dateTimeType": "Date", "nullValue": "Undefined", "generateClientClasses": true, "generateClientInterfaces": true, "generateOptionalParameters": true, "exportTypes": true, "wrapDtoExceptions": false, "exceptionClass": "ApiException", "clientBaseClass": null, "wrapResponses": false, "wrapResponseMethods": [], "generateResponseClasses": true, "responseClass": "ApiResponse", "protectedMethods": [], "configurationClass": null, "useTransformOptionsMethod": false, "useTransformResultMethod": false, "generateDtoTypes": true, "operationGenerationMode": "MultipleClientsFromOperationId", "markOptionalProperties": false, "generateCloneMethod": false, "typeStyle": "Class", "enumStyle": "Enum", "useLeafType": false, "classTypes": [], "extendedClasses": [], "extensionCode": null, "generateDefaultValues": true, "excludedTypeNames": [], "excludedParameterNames": [], "handleReferences": true, "generateConstructorInterface": true, "convertConstructorInterfaceData": false, "importRequiredTypes": true, "useGetBaseUrlMethod": false, "baseUrlTokenName": "API_BASE_URL", "queryNullValue": "", "inlineNamedDictionaries": false, "inlineNamedAny": false, "templateDirectory": null, "typeNameGeneratorType": null, "propertyNameGeneratorType": null, "enumNameGeneratorType": null, "serviceHost": null, "serviceSchemes": null, "output": "../dist/javascript/d09.avgpv.backoffice.client.ts", "newLineBehavior": "Auto" }
The actual generated typescript client looks like the following. The first one is missing the _mappings variabled, the 2nd one actually has it initialized.