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

Add support for Avro Schemas #466

Closed
ghost opened this issue Sep 21, 2015 · 10 comments
Closed

Add support for Avro Schemas #466

ghost opened this issue Sep 21, 2015 · 10 comments
Labels
Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk

Comments

@ghost
Copy link

ghost commented Sep 21, 2015

At Pearson Education, we have a preference for expressing data models using Avro Schemas. Avro schemas have some benefits over JSON schema. See, for example, Jon Zuanich's blog.

Ideally, we would like the Swagger specification to offer a choice in the way that the data model is expressed. As a starting point, one could choose either JSON Schema or Avro Schema.

@dolmen
Copy link

dolmen commented Oct 7, 2015

I had a quick look at Avro Schemas. It looks like it should be straightforward to convert most Avro schemas into a schema to use in a Swagger 2.0 spec. Only null and Union seem to be completely incompatible. The other way seems possible too as Swagger schemas are stricter than full JSON schemas.

Adding generation of Avro Schemas could be interesting for swagger-codegen, but I don't see what "support" for Avro you are requesting in the core Swagger spec.

PS: I'm not a core contributor of Swagger

@ghost
Copy link
Author

ghost commented Nov 20, 2015

By "support" I mean (1) the ability to embed an Avro Schema in the Swagger specification instead of embedding a JSON-Schema definition, and (2) support for null and Union, as these are important constructs for schema evolution.

@dolmen
Copy link

dolmen commented Nov 25, 2015

(1) does not seem in the spirit of Swagger. You can still do it using vendor extensions in a schema definition, but most generation tools will not support your extension.
(2) Swagger 2.0 is inspired from JSON Schema, but the Swagger 2.0 designers deliberately choose to exclude null and multiple types for a value (the Union of Avro) that are in JSON Schema, and to disallow them. This is to force API designers to build APIs that do not rely on unions that some programming language do not support natively. So, don't expect them to come back.

@webron
Copy link
Member

webron commented Nov 25, 2015

(1) We're actually considering the option to use alternative data modeling schemes in the future.
(2) We did not deliberately choose to exclude null. Being human, we make mistakes and that was one of them. Unfortunately, when it was discovered, it was too late to change. The other aspects that were excluded from JSON Schema were indeed intentional - however, I can't really say that won't change in the future. It will be challenging, but that's not saying it won't happen.

Since I don't know Avro except by name, I cannot address the concerns about the Union without diving in and getting more information about it.

@dolmen
Copy link

dolmen commented Nov 30, 2015

@webron null as a type doesn't have much value if another type is also allowed for non-null value: type: [ "null", "string" ]. This implies that at least a some kind of unions are required to define such types.

@webron
Copy link
Member

webron commented Nov 30, 2015

That's why null may not be an actual value but isNullable may be the right approach.

@webron
Copy link
Member

webron commented Jul 21, 2016

Parent: #586.

@rage-shadowman
Copy link

@dolmen can you please expand on what you mean by "using vendor extensions" to support Avro schemas in swagger?

It is the unions that make the difference here. Otherwise, everything from a swagger generated schema is likely identical to the Avro schema.

We need to support polymorphism and it would be nice if swagger would generate an accurate representation of our actual schema. It sounds like I will have to write such a generator myself, so any pointers would be appreciated.

@LasneF
Copy link
Member

LasneF commented Jan 26, 2024

@handrews @lornajane this ticket should be closed

as mentionned the topic of union / polymorphism is already been solved by leveraging Json Schema capability

@handrews handrews added the Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk label Jan 27, 2024
@handrews
Copy link
Member

This may also fall under Moonwalk's separation of concerns and decoupling from specific schema systems. So folks can join the discussions there if interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk
Projects
None yet
Development

No branches or pull requests

5 participants