Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncludeXmlCommentsFromInheritDocs always produces value from <example> tag as string. #34

Open
patadata opened this issue Mar 19, 2024 · 0 comments

Comments

@patadata
Copy link

patadata commented Mar 19, 2024

When validating the generated OpenApi specification using the Spectral open-source API style guide enforcer and linter (https://stoplight.io/open-source/spectral) we get a lot of errors regarding examples that has wrong types.

The problem for us is that all numbers as in int, double, decimal, float etc. are all generated as strings so the validator gives us errors saying that the example is of wrong type.

Generated JSON

.
.
"breakValueRightShaft5": {
  "type": "number",
  "description": "Break value for right shaft 5",
  "format": "integer",
  "nullable": true,
  "example": "2"
},
.
.

Error

.
.
  "range": {
    "start": {
      "line": 4475,
      "character": 23
    },
    "end": {
      "line": 4475,
      "character": 27
    }
  },
  "severity": 1,
  "code": "oas3-valid-schema-example",
  "source": "spectral",
  "message": "\"example\" property type must be integer,null"
},
.
.

Finding in code

I have found this code where this is handled inside of XmlCommentsExtensions.cs :

var exampleNode = targetXmlNode.SelectSingleNode(ExampleTag);
if (exampleNode != null)
{
    schema.Example = new OpenApiString(XmlCommentsTextHelper.Humanize(exampleNode.InnerXml));
}

As we can see above, it will always render an OpenApiString, no matter what type it actually shouold be.

patadata pushed a commit to patadata/Unchase.Swashbuckle.AspNetCore.Extensions that referenced this issue Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant