fastify / fastify-swagger

Swagger documentation generator for Fastify
MIT License
915 stars 201 forks source link

Header enum value is not getting generated as available values on @fastify/swagger #701

Closed vishnutmohan closed 1 year ago

vishnutmohan commented 1 year ago

Prerequisites

Fastify version

3.29.0

Plugin version

6.1.1

Node.js version

14.17

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13.0.1

Description

I have defined my schema for the headers like below.

I have defined my schema for the headers like below.

const headers = {
  $id: "headers",
  type: "object",
  properties: {
    Authorization: { type: "string" },
    "x-country": {
      type: "string",
      transform: ["toUpperCase"],
      enum: ["IN", "US", "CH", "AR", "MX", "UY", "BR"]
    },
    "x-commerce": {
      type: "string",
      description: "Example values: 'FA', 'SO', 'TO' etc"
    }
  }
};

And added in one of my request header like

exports.createProductSizeSchema = {
  tags: ["Product Size"],
  summary: "This API is used to create  Product Sizes",
  description: "productSize should be Unique",
  headers: { $ref: "headers#" }
}

But while generating the definition, enum value is not coming up. PFB the screenshot

Screenshot 2022-12-05 at 8 39 57 PM

Could you please let me know what I am doing wrong here?

Steps to Reproduce

const swagger = require("@fastify/swagger");

fastify.register(swagger, {
  routePrefix: "/documentation",
  swagger: {
    info: {
      title: "Test API",
      description: "API Docs",
      version: "0.1.0"
    },
    servers: [
    ],
    externalDocs: {
      url: "https://swagger.io",
      description: "Find more info here"
    },
    consumes: ["application/json"],
    produces: ["application/json"]
  },
  exposeRoute: true
});

Expected Behavior

Expecting a response like

Screenshot 2022-12-06 at 10 46 39 AM
mcollina commented 1 year ago

@climba03003 could you take a look?

climba03003 commented 1 year ago

The fix should be simple enough to allow more key for header.

https://github.com/fastify/fastify-swagger/blob/e11df8c11fb4c46fd8c58dced115509af0b33eac/lib/spec/openapi/utils.js#L208-L216

WoH commented 1 year ago

Should be fixed in 8.3.0 via #704 .