-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[C#] Child models in allOf clause not compiling because parent does not implement BaseValidate #1126
Comments
rubms
pushed a commit
to rubms/openapi-generator
that referenced
this issue
Sep 27, 2018
…n property of CodegenModel when children models are added to the model. Changed the modelGeneric.mustache template to decide whether to include a base validation model (for children to inherit) based on the hasChildren property, and not the discriminator property.
rubms
added a commit
to rubms/openapi-generator
that referenced
this issue
Sep 27, 2018
4 tasks
Filed the #1127 pull request that fixes this issue. |
wing328
pushed a commit
that referenced
this issue
Oct 15, 2018
…in allOf clauses (#1127) * Run ./bin/utils/ensure-up-to-date to re-generate samples run in the CI. * Fixed issue #1126. DefaultCodegen now sets the hasChildren property of CodegenModel when children models are added to the model. Changed the modelGeneric.mustache template to decide whether to include a base validation model (for children to inherit) based on the hasChildren property, and not the discriminator property. * Run the ./bin/utils/ensure-up-to-date script after fixing the issue #1126 * Reverted modification in go samples, performed by ./bin/utils/ensure-up-to-date, that are failing in CI. This partially reverts commit 2168df0.
Fixed with the merge of #1127 to master. Thanks @jimschubert and @wing328 ! |
A-Joshi
pushed a commit
to ihsmarkitoss/openapi-generator
that referenced
this issue
Feb 27, 2019
…dren models in allOf clauses (OpenAPITools#1127) * Run ./bin/utils/ensure-up-to-date to re-generate samples run in the CI. * Fixed issue OpenAPITools#1126. DefaultCodegen now sets the hasChildren property of CodegenModel when children models are added to the model. Changed the modelGeneric.mustache template to decide whether to include a base validation model (for children to inherit) based on the hasChildren property, and not the discriminator property. * Run the ./bin/utils/ensure-up-to-date script after fixing the issue OpenAPITools#1126 * Reverted modification in go samples, performed by ./bin/utils/ensure-up-to-date, that are failing in CI. This partially reverts commit 2168df0.
6 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The auto-generated C# models that are children in allOf clauses don't compile because they are attempting to invoke a
BaseValidate
method that should be implemented by the parent object, but is not implemented.openapi-generator version
v3.3.0 (master snapshot)
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli.jar generate -g csharp -i .\test.yml -o test
Steps to reproduce
Auto-generate the OpenAPI specification above using the
csharp
generator. The generatedChild
model does not compile because it uses aBaseValidate
method that should be implemented inParent
, but is not.Suggest a fix/enhancement
The problem is originated in 2 points.
On the one hand,
DefaultCodegen.java
fails to correctly mark thehasChildren
property ofCodegenModel
when the model has children:In the other hand, the template for the generation of C# models,
modelGeneric.mustache
, uses thediscriminator
property in order to decide whether to implement a base validation method or not.As
discriminator
only makes sense foranyOf
, this means that the auto-generated code in case ofallOf
will always be wrong.hasChildren
should be used, instead ofdiscriminator
.In addition, given the possibility of a child object also being the parent of other objects, it is necessary to prevent an infinite recursive call in
modelGeneric.mustache
In case of being a parent object and having a parent, the
BaseValidate
object would recursively and infinitely be calling itself. Instead it should call theBaseValidate
method of the parent:The text was updated successfully, but these errors were encountered: