openapi-go icon indicating copy to clipboard operation
openapi-go copied to clipboard

fix: Enable `$ref`s in response headers of OpenAPI3.1

Open blaubaer opened this issue 1 year ago • 0 comments

Currently if you're using $ref in the response headers of OpenAPI3.1

paths:
  /user:
    put:
      // ...
      responses:
        "404":
          headers:
            Cache-Control:
              $ref: '#/components/headers/CacheControl'

you'll receive an error like:

cannot load spec.service: cannot decode OpenAPI3.1 spec from \"openapi.yaml\": oneOf constraint failed for ResponseOrReference with 0 valid results: map[Reference:required key missing: $ref Response:oneOf constraint failed for HeaderOrReference with 2 valid results: map[]]

This PR will check if they are really fields set on both objects. Only in this case the error is now thrown.

BTW: IsZero() bool isn't my favorite, but it is currently broadly used in many project to indicate if the object has content or not. Example gopkg.in/yaml.v3 defines also the interface IsZeroer.

blaubaer avatar May 22 '24 10:05 blaubaer