Nswag: OwinMiddleware - OAS 3 - Request body example missing from swagger UI

Created on 17 Jul 2019  路  9Comments  路  Source: RicoSuter/NSwag

Hello,

Using the Nswag Owin Middleware with OpenApi 3 enabled, the request body for Post operations is missing from Swagger UI.

Is there something I'm missing ?

Thank you.

swagger1
swagger2

OpenAPI 3 question

Most helpful comment

@KumG This setting below worked for us.

c# app.UseSwaggerUi3(controllers, settings => { settings.GeneratorSettings.AllowNullableBodyParameters = false; }

All 9 comments

Isn't it nullable and thus reference via oneOf?

Thanks for the answer.

I used your sample for Owin Middleware and just add this method:

[HttpPost] public IHttpActionResult CreateProduct([FromBody] Product product) { return Ok(); }

I don't know exactly when "oneOf" should be generated in the swagger file...

Can you post the generated spec?

I think its correct but swagger ui does not support null/oneOf in request bodies. Maybe try adding [BindRequired] and [Required] to the parameter

It seems that the "[Required]" attribute is ignored with Web API.

We have another project with ASP.NET Core 2.2, and the requestBody is generated without "oneOf" whether or not the "[Required]" attribute is set (always required):

"requestBody": { "x-name": "customer", "description": "Customer definition", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Customer" } } }, "required": true, "x-position": 1 }

Do you know why it is different with Web API ?

Web API (legacy) is based on another Swagger/OpenAPI generator inside NSwag and is no longer being maintained... the FromBody handling is different in these two generators and might differ.

@KumG This setting below worked for us.

c# app.UseSwaggerUi3(controllers, settings => { settings.GeneratorSettings.AllowNullableBodyParameters = false; }

Yes, it seems to work, thank you!!

Was this page helpful?
0 / 5 - 0 ratings