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

OpenApiParameter.Explode is not serialized correctly for Query parameters. #2987

Open
bingnz opened this issue Aug 7, 2020 · 1 comment
Open

Comments

@bingnz
Copy link

bingnz commented Aug 7, 2020

I'm stealing this bug report from domaindrivendev/Swashbuckle.AspNetCore#1212, as NSwag has the same issue.

As per the openapi parameter specification for Query Parameters, when the style is set to form, the default explode value is true.

When adding a parameter like so:

OpenApiParameter param = new OpenApiParameter();
param.name = "Foo";
param.In = ParameterLocation.Query;
param.Style = ParameterStyle.Form;
param.Explode = false;
param.Schema = new OpenApiSchema
{
    Type = "array",
    Items = new OpenApiSchema
    {
        Type = "string"
     }
};

This serializes to:

"parameters": [
{
  "name": "Foo",
  "in": "query",
  "style": "form",
  "schema": {
    "type": "array",
    "items": {
      "type": "string"
    },
  }
}]

The explode property is not serialized because it has [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore, PropertyName = "explode")] applied and false is the default value in C#. Because false is the default value, it's never serialized to JSON.
I can work around this by creating a custom OpenApiParameter derived class that has its own JsonPropertyAttribute to serialize the value - but this only works at runtime and not when generating the spec using nswag.exe. I'm not sure why that is, but I suspect the command line tool deserializes the generated spec and re-serializes it, and when it does so it doesn't have my overridden OpenApiParameter.

@bingnz
Copy link
Author

bingnz commented Aug 7, 2020

I believe this may be addressed by #2961.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants