Skip to content
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

Response Status and Headers #3557

Open
ahbagheri opened this issue Jul 13, 2021 · 7 comments
Open

Response Status and Headers #3557

ahbagheri opened this issue Jul 13, 2021 · 7 comments

Comments

@ahbagheri
Copy link

I am using NSwag Extension in VS2019 to generate the client code. Everything work well except:

I cannot get the http response headers.
I want to know the http response status.

Any ideas how to do resolve it?

@Niiest
Copy link

Niiest commented Sep 18, 2021

@ahbagheri in NSwag client config set
"generateResponseClasses": true,
"responseClass": "ApiResponse"

The result of client methods will be warpped with ApiResponse, which contains StatusCode and Headers.

@ahbagheri
Copy link
Author

Where can I set that configuration?

@davidkeaveny
Copy link

davidkeaveny commented Feb 1, 2022

If you are using NSwagStudio (I'm using v1315.5.0), then the option is in the Response Wrapping section of the CSharp Client Settings tab. Check the Wrap success responses to allow full response access and the UI will give you access to further configuration options to further customise the process.

@polajenko
Copy link

I have noticed if I add the ControllerName.MethodName no SwaggerResponse objects are generated. If I leave blank then all are generated

@drothmaler
Copy link

@ahbagheri in NSwag client config set "generateResponseClasses": true, "responseClass": "ApiResponse"

The result of client methods will be warpped with ApiResponse, which contains StatusCode and Headers.

generateResponseClasses just causes the response model classes to be generates and is true by default. What you need ist
"wrapResponses": true.

Where can I set that configuration?

That's unfortunately a bit ugly... you need to set them inside an Options tag inside your OpenApiReference:

        <OpenApiReference Include="..\api\swagger-v1.json">
            <Namespace>Weather</Namespace>
            <ClassName>"{controller}Client"</ClassName>
            <Options>/WrapResponses:true /ResponseClass:"ApiResponse"</Options>
        </OpenApiReference>   

Space separated, just as you would pass it to the CLI.

@simeyla
Copy link

simeyla commented Dec 10, 2024

What's the difference (functionally or with intent) between ApiResponse and SwaggerResponse?

@davidkeaveny
Copy link

I think it's mostly a branding thing - Swagger was the name of the early specification/tooling; but now it has become OpenAPI, so it makes sense to rename the response class in line with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants