swagger yaml - number property with default value generates optional/nullable double with broken assignment to just "D"
See original GitHub issueNSwagStudio v13.6.0.0
The generated default value expression seems to just be missing the intended default and only includes the “D” suffix to flag the value as a double
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.18.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class SomeObject
{
[Newtonsoft.Json.JsonProperty("someOptionalProperty", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public double? SomeOptionalProperty { get; set; } = D;
}
Minimal repro I could come up with has this swagger yaml:
swagger: '2.0'
definitions:
SomeObject:
type: object
properties:
someOptionalProperty:
default: 123
type: number
and this nswag.json (contains the above swagger yaml inline)
{
"runtime": "NetCore31",
"documentGenerator": {
"fromDocument": {
"json": "swagger: '2.0'\r\ndefinitions:\r\n SomeObject:\r\n type: object\r\n properties:\r\n someOptionalProperty:\r\n default: 123\r\n type: number\r\n"
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"generateDefaultValues": true
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How do I give swagger my dto with default value?
My class DTO.User has properties called status and gender . I want to set Status = false , Gender = "male".
Read more >Describing Parameters
Each path parameter must be substituted with an actual value when the client makes an API call. In OpenAPI, a path parameter is...
Read more >atom-file-types首页、文档和下载- Specify additional ...
To map a filetype to a different language, use the file-types option in your config.json (via the Atom -> Config... menu). Specify a...
Read more >Swagger specification · GitBook
The default where you put it is a default for the entire object if it is not provided at all. Thus it must...
Read more >[DISCUSS] Swagger parameter default values while ...
Hi All, Currently we are handling the issue related to swagger parameter default values while generating the swagger content.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Awesome, thank you so much, Rico! You rock!
Thx, will release a new nswag version tomorrow.