You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In parameters/validate_parameter.go, ValidateParameterSchema renders the parameter
schema inline and discards the render error.
For a circular schema, RenderInlineWithContext cannot produce a finite inline document,
so renderedSchema comes back empty. The empty bytes flow into the compiler.
So there are two defects:
Correctness — the parameter path inline-renders the schema, which is impossible
for recursive $refs. It should validate against the schema with $refs preserved
(resolved by the compiler), the way the request-body path does.
Diagnostics — the render error from RenderInlineWithContext is discarded
(_), and there's no empty-input guard before jsonschema.UnmarshalJSON, so the user
gets EOF instead of a message naming the circular reference.
Suggested fix
In ValidateParameterSchema / ValidateSingleParameterSchema, stop relying on inline
rendering for schemas that contain circular references — compile and validate against the
schema with $refs intact (as the body path / RenderSchemaForValidation does). At a
minimum: do not discard the RenderInlineWithContext error, and guard against empty
rendered output before calling NewCompiledSchema, returning a circular-reference error
instead of EOF.
Similar to #287, but now it is about parameters' validation.
Given a spec:
Attempt to validate a request leads to:
Problems
How to reproduce
I have the following versions:
github.com/pb33f/libopenapi-validatorv0.13.10hub.lumenfield.work/pb33f/libopenapiv0.38.1Here is a code snippet:
Some digging with AI
In
parameters/validate_parameter.go,ValidateParameterSchemarenders the parameterschema inline and discards the render error.
For a circular schema,
RenderInlineWithContextcannot produce a finite inline document,so
renderedSchemacomes back empty. The empty bytes flow into the compiler.So there are two defects:
for recursive
$refs. It should validate against the schema with$refs preserved(resolved by the compiler), the way the request-body path does.
RenderInlineWithContextis discarded(
_), and there's no empty-input guard beforejsonschema.UnmarshalJSON, so the usergets
EOFinstead of a message naming the circular reference.Suggested fix
In
ValidateParameterSchema/ValidateSingleParameterSchema, stop relying on inlinerendering for schemas that contain circular references — compile and validate against the
schema with
$refs intact (as the body path /RenderSchemaForValidationdoes). At aminimum: do not discard the
RenderInlineWithContexterror, and guard against emptyrendered output before calling
NewCompiledSchema, returning a circular-reference errorinstead of
EOF.