OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

No Request example with SerializeAsV2

Open mattfrear opened this issue 5 years ago • 3 comments

Swagger V2 supports examples on the request under /paths/[path]/[method]/parameters/[index]/schema/example https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schemaExample

However, when rendering using SerializeAsV2, request examples are not output, as per the comments in https://github.com/microsoft/OpenAPI.NET/blob/master/src/Microsoft.OpenApi/Models/OpenApiExample.cs#L106

I think this is incorrect, and an example should be output when using SerializeAsV2. Related issue: https://github.com/mattfrear/Swashbuckle.AspNetCore.Filters/issues/115

mattfrear avatar Apr 11 '20 23:04 mattfrear

Technically those are two different examples. One is an example of for the schema which is modelled as Any and the other is the example property of requestBody which is an OpenApiExample.

If the example was set in the Schema object of the RequestBody.Content then it would render out in V2.

I suppose in the V2 translation, we could reach into the first requestBody.Content object and pull the Example.Value into the Schema example. Somewhere here I think https://github.com/microsoft/OpenAPI.NET/blob/master/src/Microsoft.OpenApi/Models/OpenApiOperation.cs#L250

darrelmiller avatar Apr 26 '20 16:04 darrelmiller

Hi Darrel

I ended up working around this issue by setting the /definitions/[schemaType]/example object myself.

If you want to Close this issue, that's cool.

mattfrear avatar Oct 26 '20 20:10 mattfrear

Examples are going to change again in 3.1 so we will deal with this in the 3.1 release.

darrelmiller avatar Mar 14 '21 22:03 darrelmiller

Fixed by #1538

MaggieKimani1 avatar Mar 26 '24 06:03 MaggieKimani1