Open jonocairns opened 6 years ago
Can you also post the generated swagger spec?
{
"runtime": "Default",
"defaultVariables": null,
"swaggerGenerator": {
"typesToSwagger": {
"classNames": [
"admin.Models.BrandProps"
],
"defaultPropertyNameHandling": "CamelCase",
"defaultReferenceTypeNullHandling": "NotNull",
"defaultEnumHandling": "Integer",
"flattenInheritanceHierarchy": false,
"ignoreObsoleteProperties": false,
"allowReferencesWithProperties": false,
"generateKnownTypes": true,
"generateXmlObjects": false,
"output": null,
"outputType": "Swagger2",
"assemblyPaths": [
"../admin/bin/admin.dll"
],
"assemblyConfig": null,
"referencePaths": []
}
},
"codeGenerators": {
"swaggerToTypeScriptClient": {
"className": "{controller}Client",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 2.4,
"template": "Fetch",
"promiseType": "Promise",
"httpClass": "Http",
"useSingletonProvider": false,
"injectionTokenType": "OpaqueToken",
"rxJsVersion": 5.0,
"dateTimeType": "Date",
"nullValue": "Undefined",
"generateClientClasses": false,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"wrapDtoExceptions": false,
"clientBaseClass": null,
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"protectedMethods": [],
"configurationClass": null,
"useTransformOptionsMethod": false,
"useTransformResultMethod": false,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromOperationId",
"markOptionalProperties": false,
"generateCloneMethod": false,
"typeStyle": "Interface",
"classTypes": [],
"extendedClasses": [],
"extensionCode": null,
"generateDefaultValues": true,
"excludedTypeNames": [],
"handleReferences": false,
"generateConstructorInterface": true,
"convertConstructorInterfaceData": false,
"importRequiredTypes": true,
"useGetBaseUrlMethod": false,
"baseUrlTokenName": "API_BASE_URL",
"queryNullValue": "",
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "../admin/Scripts/bundles/models/index.ts"
}
}
}
Also worth noting this only happens when we change the TS version from 1.8 to 2.4
This is the NSwag config... Can you post the relevant (properties) part of the generated spec?
sorry!
{
"swagger": "2.0",
"info": {
"title": "",
"version": ""
},
"definitions": {
"BrandProps": {
"type": "object",
"additionalProperties": false,
"properties": {
"brand": {
"$ref": "#/definitions/Brand"
},
"fieldName": {
"type": [
"null",
"string"
]
},
"isEditable": {
"type": "boolean"
},
"errorMessage": {
"type": [
"null",
"string"
]
}
}
},
"Brand": {
"type": "integer",
"description": "",
"x-enumFlags": true,
"x-enumNames": [
"MyFoodBag",
"BargainBox",
"FreshStart"
],
"enum": [
1,
2,
4
]
}
}
}
This:
"type": [
"null",
"string"
]
looks like its generating for JSON Schema and is not supported in Swagger/OpenAPI... must be a problem with the generator in NJsonSchema... need to investigate/reproduce with a unit test there.
I also have an issue with the config "defaultReferenceTypeNullHandling": "NotNull" Version 11.18.4 is ok, but in version 11.18.5, all the query parameters are not required anymore
[HttpPut("{id}/camera")]
public Task AffectCamera(string id, string cameraId)
{
}
left is 11.18.4 and right is 11.18.5
I think this commit is the problem: https://github.com/RSuter/NSwag/commit/dc16d71e9ac1d459e10032cdfd3ab00765438d1e
defaultReferenceTypeNullHandling does NOT control how parameters are handled only DTO properties... can you create a new issue with this problem?
I opened issue #1556
Hi there!
Below is a screenshot of the setup in nswag studio.
(essentially setting
"defaultReferenceTypeNullHandling": "NotNull"
in the nswag file)Is exporting to this
I would expect it to be something like this
Is there something I'm not doing right? Thanks in advance!