-
Notifications
You must be signed in to change notification settings - Fork 844
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 polymorphism support to generated OpenAPI json and UI #1397
Comments
don't swagger UI is that critical, unless it crashes |
… Swashbuckle: - Working prototype for polymorphic object passing through API. - Added filters for adding discriminator to the schema; - Each polymorphic type should have property "Type" containig its real type; - Filters added to module sawgger docs and general one; TODO: - Need to add Registrar for registering polymorphic types and use it inside Swagger config; - Possible to add interface ISupportPolymorphicAPI with string Type => GetType() property.
…ng Swashbuckle: - Working prototype for polymorphic object passing through API. - Added filters for adding discriminator to the schema; - Each polymorphic type should have property "Type" containig its real type; - Filters added to module sawgger docs and general one; TODO: - Need to add Registrar for registering polymorphic types and use it inside Swagger config; - Possible to add interface ISupportPolymorphicAPI with string Type property which is used as discriminator in OpenAPI doc.
It is working. Storefront is receiving derived objects together with base ones in array using autorest client. |
…ng Swashbuckle: - Added PolymorphicBaseClassAttribute by which base classes should be marked for OpenAPI polymorphism; - Supported OpenAPI docs generation using this attribute for independent module and common docs;
- Moved polymorhic classes declaration to module manifest, e.g.: <openAPIPolymorphicTypes> <assemblyQualifiedTypeName>VirtoCommerce.Domain.Cart.Model.LineItem, VirtoCommerce.Domain</assemblyQualifiedTypeName> </openAPIPolymorphicTypes> Need to use assembly qualified names here; - Removed attribute that marks class polymorphic for swagger; - All polymorhic classes should have "Type" property to store type information - Type.Name (or Type.FullName, if UseFullTypeNameInSwagger is set to true for module);
Usage example:
Your base and derived types should have property |
@yecli Can we do that in code? I don't think it's good idea to put .NET-specific information into manifest. Also, in code we can use nameof() operator and use Assembly class, while here we can make mistake in type & assembla names |
@asvishnyakov First it was implemented in code using custom attribute for polymorphic base type. But there were some problems when we want to make type from dependent assembly as polymorphic base for specific module (e.g. LineItem from Domain for Cart module) - in such cases we would need to load dependent assemblies to search polymorphic types. Moved polymorphic types declaration to module manifests for explicit and clear declaration. Also we already use assembly qualified type names in manifest - for defining module type. Agree with you, better to do this in the code. @tatarincev said the same and advised to use AbstractTypeFactory for registering polymorphic types. Going to try this solution. |
- Added IPolymorphismRegistrar to register polymorphic types and their discriminator fields for the modules. AbstractTypeFactory is used for getting registered descendant types;
Added special interface to register type to be polymorphic for the module:
Example of usage for Customer module polymorphism (
|
… Swashbuckle: - Removed redundant changes;
- Reworked Polymorphism registration to use only AbstractTypeFactory and one Document filter; - Added Discriminator field to TypeInfo<BaseType> which should be filled after RegisterType() for proper polymorphism work;
Next mechanism rework: left only Usage - when registering type in
Generated OpenAPI doc: |
Closing as not applicable. |
@asvishnyakov commented on Tue Mar 20 2018
Research point: https://github.com/Azure/autorest/blob/master/docs/developer/guide/defining-clients-swagger.md#polymorphism
@asvishnyakov commented on Thu Aug 02 2018
Updated 27 Mar 2019
Status:
Resolution: the blocking issue is UI support: swagger ui has no support of polymorphism, while ReDoc has no built-in console. For OpenAPI generation we may have a few solutions, code generation already ready for polymorphism and not require any additional actions.
The text was updated successfully, but these errors were encountered: