Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmarshal failed to openAI spec #114

Closed
clockfly opened this issue May 29, 2024 · 1 comment · Fixed by #121
Closed

Unmarshal failed to openAI spec #114

clockfly opened this issue May 29, 2024 · 1 comment · Fixed by #121

Comments

@clockfly
Copy link

Describe the bug
Unmarshal yaml failed for https://github.com/openai/openai-openapi/blob/master/openapi.yaml

Error:

oneOf constraint failed for SchemaOrRef with 0 valid results: map[Schema:oneOf constraint failed for SchemaOrRef with 0 valid results: map[Schema:additional properties not allowed in Schema: [$ref] SchemaReference:additional properties not allowed in SchemaReference: [nullable]] SchemaReference:required key missing: $ref]

To Reproduce

yamlFile = "path_to_openapi.yaml"
bytes, _ := ioutil.ReadFile(yamlFile)
spec.UnmarshalYAML(bytes); err != nil {
	fmt.Println(err)
}

Expected behavior
This file should be parsed correctly. This file renders correctly in swagger editor.

https://editor-next.swagger.io/
image

Additional context
None

@vearutop
Copy link
Member

The spec in question is not a valid one.

If you open it in a schema-enabled editor, like the one included in intellij IDEs (e.g. GoLand), you'll see warnings.
image

The issue here is that OpenAPI 3.0 is based on JSON Schema draft 04, which does not allow any fields adjacent to $ref.
This is also what is told by unmarshal error message (in a cryptic way though):

additional properties not allowed in SchemaReference: [nullable]]

Here are original and fixed schemas:
openai-openapi.json Converted from the YAML original.
openai-openapi-fixed.json Fixed to pass unmarshaling.

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 a pull request may close this issue.

2 participants