-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
[BUG][Ruby] Required properties with validation requirements generate invalid tests #16629
Comments
I can't recall the reason. What about submitting a PR removing the nil assignment to start with? |
I wanted to go backwards through the git history to work out why that nil assignment was added as the conditions around the assignment seem intentional in the template, but I haven't had time to follow through. I have set some time aside for this tomorrow to see if I can come to some conclusion |
👌 up to you
The auto-generated tests are for demo purpose only. We occasionally run into issues you reported in other generators and we simply just comment out those tests (and users can uncomment and edit those if needed). The goal of the auto-generated tests is to make it easier for users to write tests as they can simply edit the auto-generated test code but based on our experience, it won't work perfectly for all use cases. |
Spent some time looking at this today, and fundamentally there isn't a good fix for this. The explicit Taking a step back, the reason I was trying to get this sorted is because we ended up accidentally shipping a broken client to internal consumers off the back of #5582, so I was trying to run something that would at least give some reassurances the output code is valid. I've since solved that problem in a different/better way, but would have been nice to have tests also pass by default. However as you said, these are not exactly useful right now and largely there for demo purposes, so the return of investment on resolving this issue is limited. With that in mind, I'd be happy for this to be closed - unless there's better ideas... |
@ivgiuliani thanks again for your time looking into this issue. I've filed #16702 to improve the model tests and it now works right out fo the box for the spec you provided. |
Bug Report Checklist
Description
Definitions that:
generate a model that attempts to validate that any time such attribute is assigned, it satisfies the above requirements.
This definition for example:
Will require that
SampleModel.key
is non-null, and of length >= 15. If I followed the trail correctly, this is enforced by thepartial_model_generic
template (specifically, these lines that add attribute validations).Unfortunately this means that the generated tests fail, because nothing in the test generate a valid value for these properties (and not sure how they could) but the default constructor attempts assigning a default value (
nil
in this case) that the validator rejects.I'm happy to put together a PR but I'm not quite sure what's the fix here as tests can't make up values that validate requirements, and given the validation is somewhat arbitrary not quite sure how to go about this.
openapi-generator version
OpenAPI declaration file content or url
Steps to reproduce
Using the definition file from above (I'm using bundle here, but the steps to run
rspec
might differ depending on the local setup):Related issues/PRs
Suggest a fix
Can't think of a good solution, will need to have a look at what other languages do. The least worst option I came up with is to avoid the explicit
nil
assignment inpartial_model_generic.mustache
when an attribute is required. Practically, we could avoid that assignment entirely as it will benil
by default which, from a quick look, is what (at least) the java and python generators do but I suspect thatnil
assignment is there for a reason?The text was updated successfully, but these errors were encountered: