RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.79k stars 1.29k forks source link

Generate C# client code with response headers defined in YAML #3615

Open borisr84 opened 3 years ago

borisr84 commented 3 years ago

Hi, I am trying to generate a C# client which gets a response with custom headers.

I'm using an example from the OpenAPI specification as follows:

paths:
  /ping:
    get:
      summary: Checks if the server is alive.
      responses:
        '200':
          description: OK
          headers:
            X-RateLimit-Limit:
              schema:
                type: integer
              description: Request limit per hour.
            X-RateLimit-Remaining:
              schema:
                type: integer
              description: The number of requests left for the time window.
            X-RateLimit-Reset:
              schema:
                type: string
                format: date-time
              description: The UTC date/time at which the current rate limit window resets.

But the generated client ignores the headers section.

Is this a known issue? Am I missing something? Is there a workaround for that?

Thank you, Boris.

davidkeaveny commented 2 years ago

I have the same issue with 201 Created returning the URI of the created resource in the Location header - I want to be able to parse that and return the ID of the new resource. NSwag needs the option to wrap responses in an envelope e.g. ApiResponse<T>, which exposes the received headers, as well as the deserialised body.