Skip to content

Copy properties from parent models defined with allOf - #946

Merged
wing328 merged 3 commits into
swagger-api:develop_2.0from
xhh:model-all-of
Jul 21, 2015
Merged

wing328 merged 3 commits into
swagger-api:develop_2.0from
xhh:model-all-of

Conversation

@xhh

@xhh xhh commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

This PR copies model properties of the parent models that are defined with the allOf key (with value of either $ref or properties), i.e. for composed models.

It also fixes #936.

@webron

webron commented Jul 5, 2015

Copy link
Copy Markdown
Contributor

Does this mean the end result would be flattened classes rather than one exhibiting inheritance?
Also, I see that this doesn't handle the discriminator yet (which is fine). Is the intend here to provide better support for composition rather than inheritance?

@xhh

xhh commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

@webron Yes, the end result would be flattened classes as all properties of parents would be copied and made as if they are the current model's own properties.
This is to provide better support for composition (allOf) as some clients do not handle inheritance (yet).

For other clients that do handle it, e.g. Java client uses something like class Dog extends Animal when the Dog model's allOf refers to Animal, I think we need to further improve the support for this case, by either removing the extends or not copying Animal's properties to Dog. We might have to also consider with discriminator here.
However, it does work/compile to overwrite attributes of parent class, though not elegant.

@webron

webron commented Jul 6, 2015

Copy link
Copy Markdown
Contributor

Thanks for the clarification. This is a tricky part of the spec, and may have a different effect on clients VS server.

If we want to keep a 1:1 representation of spec:code, this may not fully work for servers, however, for it to work we need to have better support for it in the server libraries (I'm thinking of swagger-core but it applies to others as well). For clients, it may be less of an issue.

Composition, at least for now, can (and probably should) be translated to a flattened structure in most languages.

Inheritance (which is based on the discriminator field) needs to be represented eventually as actual extended classes, although the tricky part here is with multiple inheritance which JSON Schema allows but some languages don't.

Obviously there are limitations now, but it would be useful to keep the metadata of the origin of the property in the property itself to allow more flexibility in the future. I'm okay with it as-is right now. :)

wing328 added a commit that referenced this pull request Jul 21, 2015
Copy properties from parent models defined with allOf
@wing328
wing328 merged commit 405e5a7 into swagger-api:develop_2.0 Jul 21, 2015
tandrup added a commit to tandrup/swagger-codegen that referenced this pull request Jul 25, 2015
Pull request swagger-api#946 broke the TypeScript generation with inheritance where a superclass defined an enum. This makes it up to each language to decide the behavior appropriate for the language.
ahgittin added a commit to ahgittin/swagger-codegen that referenced this pull request Aug 20, 2015
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).

(not having inheritance
ahgittin added a commit to ahgittin/swagger-codegen that referenced this pull request Aug 20, 2015
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).

(not having inheritance
ahgittin added a commit to ahgittin/swagger-codegen that referenced this pull request Aug 20, 2015
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).
ahgittin added a commit to ahgittin/swagger-codegen that referenced this pull request Aug 20, 2015
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).
ahgittin added a commit to ahgittin/swagger-codegen that referenced this pull request Aug 24, 2015
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants