Mermade / oas-kit

Convert Swagger 2.0 definitions to OpenAPI 3.0 and resolve/validate/lint
https://mermade.org.uk/openapi-converter
BSD 3-Clause "New" or "Revised" License
698 stars 129 forks source link

openAPI validator says header in components is invalid and should contain name when specs say differently. #606

Closed JaredAAT closed 1 year ago

JaredAAT commented 1 year ago

Checklist

Detailed Description

I believe this to be a valid OpenAPI 3 definition:

{
  openapi: '3.0.3',
  info: {
    title: 'serverless-openapi-doc-demo',
    version: '7d651be8-eb3f-4473-b236-416eef0710d1'
  },
  components: {
    responses: {
      '200': {
        description: 'default response',
        content: { 'application/json': { schema: { type: 'object' } } }
      }
    },
    headers: {
      'Access-Control-Allow-Origin': { description: 'abc', schema: { type: 'string' } }
    }
  },
  paths: {
    '/update': {
      put: {
        operationId: '2012b039-d7f2-4b84-847b-f5b698190f41',
        responses: { default: { '$ref': '#/components/responses/200' } },
        parameters: [
          {
            name: 'Access-Control-Allow-Origin',
            in: 'header',
            '$ref': '#/components/headers/Access-Control-Allow-Origin'
          }
        ]
      }
    }
  }
}

but when i run it through validate on https://mermade.org.uk/openapi-converter I receive the error:

status: false
message: "expected Object { description: 'abc', schema: Object { type: 'string' } } to
  have property name"
context: "#/paths/~1update/put/parameters/0"
openapi: 3.0.3

Looking through the spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject it suggests that name should not be in the header within components. I get similar and more detailed errors when running it through: https://github.com/Mermade/oas-kit/blob/main/packages/oas-validator/README.md using: "oas-validator": "^5.0.8",

Other stuff

node 14 oas-validator 5.0.8

JaredAAT commented 1 year ago

OK.. so worked out that

parameters: [
          {
            name: 'Access-Control-Allow-Origin',
            in: 'header',
            '$ref': '#/components/headers/Access-Control-Allow-Origin'
          }
        ]

needs to reference parameters in components rather than headers.