Skip to content

Unexpected 'collectionFormat' writing Swagger 2 #1053

Closed

Description

Describe the bug
Writing a Swagger 2 file with parameter differ between Microsoft.OpenApi.Readers 1.3.2 and Microsoft.OpenApi.Readers 1.4.1.

To Reproduce

Use the following code with Microsoft.OpenApi.Readers 1.3.2 and Microsoft.OpenApi.Readers 1.4.1.

var doc = new OpenApiDocument
{
    Paths = new OpenApiPaths
    {
        ["/foo"] = new()
        {
            Operations = new ConcurrentDictionary<OperationType, OpenApiOperation>
            {
                [OperationType.Get] = new()
                {
                    Parameters = new List<OpenApiParameter>
                    {
                        new()
                        {
                            In = ParameterLocation.Query,
                            Schema = new OpenApiSchema{Type = "string"}
                        }
                    }
                }
            }
        }
    }
};
var sb     = new StringBuilder();
var writer = new OpenApiYamlWriter(new StringWriter(sb, new CultureInfo("en_us")));

doc.SerializeAsV2(writer);

File.WriteAllText(writeFile, sb.ToString());

Microsoft.OpenApi.Readers 1.3.2:

swagger: '2.0'
info: { }
paths:
  /foo:
    get:
      parameters:
        - in: query
          type: string
      responses: { }

Microsoft.OpenApi.Readers 1.4.1:

swagger: '2.0'
info: { }
paths:
  /foo:
    get:
      parameters:
        - in: query
          type: string
          collectionFormat: multi
      responses: { }

Expected behavior
'collectionFormat' should not be written.

Screenshots/Code Snippets
grafik

Additional context
https://swagger.io/docs/specification/2-0/describing-parameters/
grafik

Activity

  1. MaggieKimani1 commented on Nov 22, 2022

    @MaggieKimani1
    Contributor

    Thanks for reporting this Richard Kaspar (@richardkaspar). This is definitely a bug we need to investigate as per the documentation, we should only be writing out the collectionFormat property for multi-value parameters with type: array
    This might have arisen as a result of setting a default style parameter in v1.4.1.

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

Metadata

Metadata

Labels

type:bugA broken experience

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions