-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
openapi: include headers #1459
openapi: include headers #1459
Conversation
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## openapi #1459 +/- ##
===========================================
+ Coverage 90.69% 90.75% +0.05%
===========================================
Files 390 390
Lines 12784 12883 +99
Branches 2044 2044
===========================================
+ Hits 11595 11692 +97
- Misses 774 776 +2
Partials 415 415 ☔ View full report in Codecov by Sentry. |
This change does make the headers appear in the OpenAPI document but the swagger generation remains the same. The reason is that the methods of the generated clients only return the deserialized body. I think an option must be enabled to actually return an object with status code and headers (RicoSuter/NSwag#3557 (comment)). Though, I would say it's out of the scope of this PR. |
Thanks. I'm out for the rest of this week, will take a look when I get back. Please do add anything related to headers in this PR. Maurits probably missed the one you mentioned when the issue was created. Can you check if the headers are available in Kiota? There's a branch with sample. And can you try setting up NSwag server to see what it would look like? I wonder if |
Can we use RicoSuter/NSwag#808 somehow?
We have https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/openapi/src/JsonApiDotNetCore.OpenApi.Client/ApiResponse.cs for that; probably needs to be adapted to handle 403 as well. I've clarified the description in the original issue. For NSwag, we may even provide our own ResponseClass (pass |
0510ed7
to
ea9c970
Compare
Probably but I'm not sure we can use by just passing a command line option so maybe that will fall outside of the scope of the PR. Also I'm so confused about how clients are generated. This code clones the repo, makes a change and can't find that change in the generate clients. What am I missing? git clone git@github.com:json-api-dotnet/JsonApiDotNetCore.git test
cd test
git checkout openapi
dotnet build
sed -i 's/"query"/"hello"/' src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
dotnet build
grep hello test/OpenApiClientTests/obj/OpenApiClient.cs # nothing
dotnet clean
dotnet build
grep hello test/OpenApiClientTests/obj/OpenApiClient.cs # nothing
git clean -fdx
dotnet clean
dotnet build
grep hello test/OpenApiClientTests/obj/OpenApiClient.cs # nothing
grep hello test/OpenApiEndToEndTests/obj/QueryStringsClient.cs # nothing |
I don't understand, can you clarify?
When building project OpenApiTests, your changes from JsonApiDotNetCore.OpenApi are compiled. When running the tests in OpenApiTests, it writes updated When building JsonApiDotNetCoreExample, it starts the webserver and writes |
Also, NSwag doesn't always detect changes properly. For example, if project options have changed but the source swagger.json has not, it won't regenerate. Delete the |
Oh that's it thanks.
Though I'm not sure what to return in that case. I've generated a response object to be able to get the response headers (e.g. ETag) so maybe it could return
NSwag clients are generated using a command line from the csproj. How can I pass an implementation of IParameterNameGenerator there 🤔 I think a custom generator needs to be created like in here https://github.com/daveaglick/NetlifySharp/blob/main/tools/NetlifySharp.Generator/Program.cs. |
Oh actually I think I just didn't know anymore what I changed so I wrote some random message. |
Thanks for looking into all these details. You're on the right track. Sorry if this turned out more complicated than I initially imagined, I appreciate you're not giving up.
Thanks, I understand now. It goes a bit too far to build our own generator for this, so let's just stick with
I propose to extend the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from comments, remaining things to address:
- openapi: include headers #1459 (comment)
- End-to-end tests (subset of what's in
ETagTests.cs
) - Possibly update sample to show how ETag works, ie: call wrapped
GetPersonCollectionAsync
, capture ETag from header, call again with that ETag, and observe the result isnull
with status 304. - Document the (optional) use of
/WrapResponses:true /GenerateResponseClasses:false
in docs/usage/openapi.md - Try if it works with Kiota (no commit needed, but would be nice if you can add some working code in a PR comment so I can integrate it later)
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
Hmm I was expecting to see a NSwag section there, not sure what to add.
I don't think I'll have the time/energy to test with Kiota. Though this library looks promising. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update this PR to the latest version of the base branch.
src/Examples/JsonApiDotNetCoreExampleClient/JsonApiDotNetCoreExampleClient.csproj
Outdated
Show resolved
Hide resolved
src/Examples/JsonApiDotNetCoreExampleClient/JsonApiDotNetCoreExampleClient.csproj
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
07b1ae2
to
b7e58e1
Compare
For future reference, here's what the sample looks like using Kiota: var headerInspector = new HeadersInspectionHandlerOption
{
InspectResponseHeaders = true
};
PersonCollectionResponseDocument? getResponse1 = await client.Api.People.GetAsync(
configuration => configuration.Options.Add(headerInspector));
string eTag = headerInspector.ResponseHeaders["ETag"].Single();
try
{
PersonCollectionResponseDocument? getResponse2 = await client.Api.People.GetAsync(
configuration => configuration.Headers.Add("If-None-Match", eTag));
}
catch (ApiException exception) when (exception.ResponseStatusCode == (int)HttpStatusCode.NotModified)
{
Console.WriteLine("The HTTP response hasn't changed, so no response body was returned.");
} The try/catch is needed due to a bug in Kiota: it fails to map the 304 status, despite being in the OAS. |
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
Please add |
21ff29d
to
0a6f86f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final round of review. Thanks for all the hard work!
I'll propose something to add to the docs; with that included, this looks ready for merge.
Meanwhile, can you update the PR description, with an updated SwaggerUI screenshot?
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
src/JsonApiDotNetCore.OpenApi/SwaggerComponents/JsonApiOperationDocumentationFilter.cs
Outdated
Show resolved
Hide resolved
…onDocumentationFilter.cs Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
Co-authored-by: Bart Koelman <10324372+bkoelman@users.noreply.github.com>
I'm not committing the suggestions one by one ever again :D |
I'd welcome that. You can batch them into a single commit from the Files changed tab. I've created a suggestion to update the docs, see the diff at openapi...openapi-header-docs. Probably just easiest for you to cherry-pick the commit, assuming you agree with the change. |
Good to know.
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
Closes #1367
QUALITY CHECKLIST