-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
When generating code from a yaml or json doc, where that doc does not explicitly specify that additionalProperties is false, and when the endpoint accepts an untyped object input, the generated code will not compile.
Version of NSwag toolchain, computer and .NET runtime used
This issue occurs with 14.13.0. I cannot update to 14.4.0 or 14.5.0 due to regressions introduced in those two releases.
To Reproduce
{
"openapi": "3.0.1",
"info": {
"title": "My WebServices",
"description": "My WebServices",
"version": "1.0"
},
"servers": [
{
"url": "https://myservices.mysite.com/my-service"
}
],
"paths": {
"/api/thing/createorupdate": {
"post": {
"tags": [],
"summary": "/api/thing/createorupdate - POST",
"operationId": "post-api-thing-createorupdate",
"parameters": [
{
"name": "value",
"in": "query",
"schema": {
"type": "object",
"nullable": true
}
},
{
"name": "template",
"in": "query",
"schema": {
"type": "string",
"nullable": true
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ThingResponse"
},
"example": {
"status": 0,
"description": "string"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ThingResponse": {
"type": "object",
"properties": {
"status": {
"type": "integer",
"format": "int32"
},
"description": {
"type": "string",
"nullable": true
}
}
}
},
"securitySchemes": {
"apiKeyHeader": {
"type": "apiKey",
"name": "My-Api-Key",
"in": "header"
}
}
},
"security": [
{
"apiKeyHeader": [ ]
}
]
}The issue seems to occur because nswag recognizes that the input of type object is not a value type, and as a result it applies this code in the generated endpoint:
if (value != null)
{
foreach (var item_ in value.AdditionalProperties)
{
urlBuilder_.Append(System.Uri.EscapeDataString(item_.Key)).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_.Value, System.Globalization.CultureInfo.InvariantCulture))).Append('&');
}
}Since the object? value input is just an object and not a type defined in the json document, there is no AdditionalProperties property, and as a result the generated code does not compile.
Expected behavior
When generating a library when additionalProperties is either not provided (defaults to true) or is explicitly set to true, the code generator must not include code for appending AdditionalProperties on inputs of type object or object?.
Additional context
I think I've given enough detail to identify the issue. If not, let me know.