microsoft / OpenAPI.NET

The OpenAPI.NET SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
MIT License
1.42k stars 240 forks source link

Cannot put extension in RequestBody serialized to OASv2 #510

Closed dipidoo closed 4 years ago

dipidoo commented 4 years ago

Microsoft.OpenAPI NuGet v1.2.2

Serializing to OASv3 outputs the extension as expected. The v2 spec seems to allow it.

Repro:

            var doc = new OpenApiDocument()
            {
                Paths = new OpenApiPaths()
            };
            doc.Paths.Add("/bar", new OpenApiPathItem()
            {
                Operations = { { OperationType.Post, new OpenApiOperation()
                {
                    RequestBody = new OpenApiRequestBody()
                    {
                        Extensions = { { "x-ms-foo", new OpenApiBoolean(true) } }
                    }
                } } }
            });
            Console.Out.Write(doc.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0));

Actual:

{
  "swagger": "2.0",
  "info": { },
  "paths": {
    "/bar": {
      "post": {
        "consumes": [ ],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "schema": { }
          }
        ],
        "responses": { }
      }
    }
  }
}

Expected:

{
  "swagger": "2.0",
  "info": { },
  "paths": {
    "/bar": {
      "post": {
        "consumes": [ ],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "schema": { },
            "x-ms-foo": true
          }
        ],
        "responses": { }
      }
    }
  }
}
dipidoo commented 4 years ago

Additionally, it also seems to be unable to read the extension off a spec, using OpenApiStringReader