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

Parsing OpenAPI 2 specs with discriminator fails #360

Closed
patrick246 opened this issue May 10, 2021 · 3 comments
Closed

Parsing OpenAPI 2 specs with discriminator fails #360

patrick246 opened this issue May 10, 2021 · 3 comments

Comments

@patrick246
Copy link

When loading an OpenAPI 2 spec that is using discriminator in models, then the spec parsing fails with
failed to unmarshal property "definitions" (*map[string]*openapi3.SchemaRef): failed to unmarshal property "discriminator" (*openapi3.Discriminator): failed to unmarshal extension properties: json: cannot unmarshal string into Go value of type map[string]json.RawMessage ("type")

Example: https://gist.github.com/patrick246/e8b329144d228b4a1892946162868e50

This issue was encountered by someone before (#214), but worked around by mixing OpenAPI 3 parts into their OpenAPI 2 spec. As far as I can tell, this is because the library is using OpenAPI 3 data types, but the discriminator changed between 2 and 3:
OpenAPI 2 uses string, while OpenAPI 3 uses a discriminator object.

@roberth1988
Copy link

Would be great to resolve this ;)

@crochik
Copy link

crochik commented May 17, 2023

I assume nobody is too focused on 2.0 at this point but, just in case... It is also an issue if you try to generate a new 2.0 spec with a model that has a discriminator. You won't be able to because you will have to define the Discriminator property as a *openapi3.Discriminator.

I did find a simple workaround in this case though, use extensions:

			Extensions: map[string]interface{}{
				"discriminator": "petType",
			},

@fenollp
Copy link
Collaborator

fenollp commented Oct 1, 2024

Fixed in #1011

@fenollp fenollp closed this as completed Oct 1, 2024
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

No branches or pull requests

4 participants