1

How Response Headers can be set in NSwag?

I tried to add to OpenApiResponse.Headers collection.

        var headerSchema = new JsonSchema()
        {
            Type = JsonObjectType.String,
            Description = "headerDescription"
        };

        response.Headers["headerName"] = headerSchema;

Unfortunately, the generated json is not correct though. According to Swagger website, the output of response header should be like this:

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.

Can we achieve this using Nswag?

Ehsan Mirsaeedi
  • 6,924
  • 1
  • 41
  • 46

0 Answers0