kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

customFormats function not called in referenced schema #793

Open LukDrews opened 2 years ago

LukDrews commented 2 years ago

My application uses some custom formats + validators for EAN barcodes. The custom validation function is called when I use it like this:

const apiDoc = {
  openapi: "3.0.0",
  ...
  components: {
    ...
    parameters: {
      productBarcode: {
        name: "barcode",
        in: "path",
        schema: {
          type: "string",
          format: "eanBarcode",
        },
        required: true,
      },
    },
  },
};

But when I try to use a $ref in the productBarcode schema the validator isn't called:

const apiDoc = {
  openapi: "3.0.0",
  ...
  components: {
    schemas: {
      eanBarcode: {
        type: "string",
        format: "eanBarcode",
      },
    },
    ...
    parameters: {
      productBarcode: {
        name: "barcode",
        in: "path",
        schema: {
          $ref: "#/components/schemas/eanBarcode",
        },
        required: true,
      },
    },
  },
};

Is this intentional or a bug?