Skip to content

OData Swashbuckle 5.0.0 rc-4 swagger.json generation for requestbody #562

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

Closed
spaasis opened this issue Oct 18, 2019 · 5 comments
Closed

Comments

@spaasis
Copy link

spaasis commented Oct 18, 2019

AspNetCore 2.2
Swashbuckle.AspNetCore 5.0.0-rc4
AspNetCore.OData.Versioning.ApiExplorer v.3.2.3

Original issue: domaindrivendev/Swashbuckle.AspNetCore#1331

When I have an OData API controller with a PATCH/PUT/POST method that requires an [FromBody]-parameter, the generated swagger.json does not have any content on requestbody. See the original issue for a code and result sample. GET works beautifully.

Is this an issue of the api-versioning package or OData itself?

@commonsensesoftware
Copy link
Collaborator

I haven't tried it - yet, but there's a chance the attributes are confusing the API Explorer. Delta<T> is special as are a few other types in OData. These types have their own model binders. Part of the model binder API requires that they indicate where the value comes from. I've actually not need [BindRequired] before, but there's no scenario (that I'm aware) where OData will not provide the Delta<T>. The request fails if the binding cannot be satisfied.

I'd first try removing the attributes and see if that makes a difference. You can also work backward from this example with OData and Swashbuckle.

@spaasis
Copy link
Author

spaasis commented Oct 18, 2019

Thanks for the response, sounds even more complex than I feared... Just a quick comment - I tried replacing the last parameter type with just a string and without the BindRequired, with the same results. In hindsight, should've left the simplest example stand.. I'll see if I have a chance to test further this weekend

@spaasis
Copy link
Author

spaasis commented Oct 26, 2019

Okay, simple steps to verify:
In the OData+Swagger sample, the swagger.json POST works fine with [RequestBody].
Update Swashbuckle.AspNetCore to latest 5.0 release candidate and fix the build errors (SwaggerDefaultValues, ConfigureSwaggerOptions) and the POST method stops generating a valid swagger.json.

@commonsensesoftware
Copy link
Collaborator

It seems that Swashbuckle has changed a bunch of things under the hood. Specifically, there are some changes related to model generation that is breaking the OData support. I also found some actual issues that apparently Swashbuckle was being generous about that I would consider a bug.

This is now the final blocker to the v4.0 release. I thought I had everything ironed out. I'm hoping to have it resolved soon. In the meantime, if this is blocking you, then I would recommend an older version of Swashbuckle. Things were definitely working in 4.0.1. I'm not sure how far you can advance before things fall down.

Thanks.

@spaasis
Copy link
Author

spaasis commented Oct 28, 2019

Hm, hopefully the end result will be worth the effort. Thank you for your hard work! Luckily I'm not in a hurry :)

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