openapi2conv: nil-guard components lookup in FromV3SchemaRef#1156
Merged
fenollp merged 2 commits intogetkin:masterfrom Apr 25, 2026
Merged
openapi2conv: nil-guard components lookup in FromV3SchemaRef#1156fenollp merged 2 commits intogetkin:masterfrom
fenollp merged 2 commits intogetkin:masterfrom
Conversation
FromV3SchemaRef indexes components.Schemas[name] whenever the input schema has a . Several recursive call sites in this file (FromV3RequestBodyFormData among them) already pass components=nil when descending into array items / nested refs, so hitting a ref from that path nil-dereferenced and took down the whole V3→V2 conversion. In practice this fires on real-world inputs like the OpenAI OpenAPI 3.0 spec, where CreateEmbeddingRequest references a sub-schema inside an array of formData items (getkin#1062). Guard the components lookup with a components != nil check. When the components table is not available we fall through to the same 'return the plain ' branch that already handles non-binary schema refs - semantically 'the target schema is not known locally, emit a pass-through ref' - instead of panicking. Runtime behaviour for callers that do pass a non-nil Components is unchanged. Closes getkin#1062 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
fenollp
requested changes
Apr 23, 2026
Collaborator
fenollp
left a comment
There was a problem hiding this comment.
LGTM but please add your spec (or a minified version of it) as a regression test.
Adds TestIssue1062_FormDataArrayOfRefDoesNotPanic with a minified spec capturing the OpenAI OpenAPI 3 shape that triggered the original report: a multipart/form-data request body whose property is an array whose items are a $ref into #/components/schemas/. Without the fix in this PR, the test panics inside FromV3 (line 723) because FromV3RequestBodyFormData passes components=nil into FromV3SchemaRef, which then nil-derefs on components.Schemas[name]. With the fix, the test passes and the resulting v2 spec contains the expected formData parameter named 'documents'. Signed-off-by: SAY-5 <say.apm35@gmail.com>
Contributor
Author
|
@fenollp added |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #1062.
FromV3SchemaRefindexescomponents.Schemas[name]whenever the input schema has a$ref. Several recursive call sites in this file (FromV3RequestBodyFormDatamost notably) already passcomponents=nilwhen descending into array items and nested refs, so hitting a$reffrom that path nil-dereferenced thecomponentsargument and took down the whole V3→V2 conversion.In practice this fires on real-world inputs like the OpenAI OpenAPI 3.0 spec, where
CreateEmbeddingRequestreferences a sub-schema inside an array of formData items:Fix
Guard the components lookup with a
components != nilcheck. When the components table is not available we fall through to the same 'return the plain$ref' branch that already handles non-binary schema refs - semantically 'the target schema is not known locally, emit a pass-through ref' - instead of panicking. Runtime behaviour for callers that do pass a non-nilComponentsis unchanged.Verification
Locally on macOS, go 1.26.2:
gofmt -s -l openapi2conv/openapi2_conv.go: cleango vet ./...: cleango test -race -count=1 ./openapi2conv/...: passCloses #1062