question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NSwag Response Headers

See original GitHub issue

I tried to use OpenApiResponse.Headers to define the response headers but it seems this functionality does not work as expected.

Actual:

responses:
        '200':
          description: OK
          headers:
              X-RateLimit-Limit:
                type: integer
                description: Request limit per hour

Expected:

responses:
        '200':
          description: OK
          headers:
            X-RateLimit-Limit:
              schema:
                type: integer
              description: Request limit per hour.

On top of that, NSwag has the following limitations in regard to response headers:

  1. Cannot set header name
  2. Cannot set header description

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cjlotzcommented, Feb 23, 2020

I think I figured it out. Adding the response header as an OpenApiParameter seems to generate the correct schema for a response header:

            var header = new OpenApiParameter
                            {
                                Schema = new JsonSchema { Type = JsonObjectType.Integer },
                                Example = 100,
                                Description = "Id of the resource created"
                            };         
            context.Document.Components.Headers.Add("ResourceId", header);
0reactions
davidkeavenycommented, Oct 1, 2020

Thanks @cjlotz, your solution fixed my issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NSwag Response Headers - swagger
How Response Headers can be set in NSwag? I tried to add to OpenApiResponse.Headers collection. var headerSchema = new JsonSchema() { Type ...
Read more >
Generate TypeScript and C# clients with NSwag based on ...
Learn how to generate TypeScript and C# API clients with NSwag to reduce ... stacktraces, network requests/responses with headers + bodies, ...
Read more >
Get started with NSwag and ASP.NET Core
Learn how to use NSwag to generate documentation and help pages for an ASP. ... http://localhost:<port>/swagger to view the Swagger UI.
Read more >
Add Custom Header and handle it ...
Zero use nswag so service proxy is auto generated, I am not able to add any thing to header of request. How can...
Read more >
Is it a best practice to use NSwag generated code for calls ...
My thought is that instead of NSwag, one can inject an HTTPClient, ... This includes information such as response headers, the http status ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found