swaggest / openapi-go

OpenAPI structures for Go
https://pkg.go.dev/github.com/swaggest/openapi-go/openapi3
MIT License
259 stars 23 forks source link

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

Closed blaubaer closed 4 months ago

blaubaer commented 6 months ago

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.

vearutop commented 4 months ago

Thank you!