Skip to content

openapi3: resolve refs under a header's content - #1424

Merged
fenollp merged 1 commit into
getkin:masterfrom
JayOfTheKeyboard:fix-header-content-refs
Nov 5, 2026
Merged

fenollp merged 1 commit into
getkin:masterfrom
JayOfTheKeyboard:fix-header-content-refs

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown
Contributor

resolveHeaderRef resolves a header's schema but never looks at its content, while resolveParameterRef walks both. So whatever sits under a header's content stays as it was decoded.

A $ref there is never followed, and a valid document fails Validate:

paths:
  /x:
    get:
      responses:
        '200':
          description: d
          headers:
            h:
              content:
                application/json:
                  schema: {$ref: '#/components/schemas/S'}
components:
  schemas:
    S: {type: string}
invalid paths: invalid path /x: invalid operation GET: header content is invalid: found unresolved ref: "#/components/schemas/S"

A null sub-schema there (a property with no value, for instance) also gets through. Anywhere else the loader refuses it with invalid schema: value MUST be an object, but under a header's content it stays a nil *SchemaRef, and Validate panics on it with a nil pointer dereference in (*SchemaRef).validateExtras. I found this one by fuzzing LoadFromData followed by Validate.

This walks content in resolveHeaderRef with resolveMediaTypeRefs, the same loop resolveParameterRef already has.

Added TestLoaderResolvesHeaderContent for the $ref and TestLoaderRejectsNullSchemaInHeaderContent for the null. Both fail on master. go test ./..., go vet, go generate, maps.sh and docs.sh are clean.

Prepared with Claude Code.

resolveHeaderRef resolved a header's schema but not its content, unlike
resolveParameterRef. A $ref in a header's content schema stayed unresolved,
so Validate rejected a valid document. A null sub-schema there was never
rejected by the loader and made Validate panic with a nil dereference.
@fenollp
fenollp merged commit 06b0438 into getkin:master Nov 5, 2026
42 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants