question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

swagger yaml - number property with default value generates optional/nullable double with broken assignment to just "D"

See original GitHub issue

NSwagStudio 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jamesmanningcommented, Jun 10, 2020

Awesome, thank you so much, Rico! You rock!

0reactions
RicoSutercommented, Jun 10, 2020

Thx, will release a new nswag version tomorrow.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found