fix(repository-json-schema): added type 'object' to model json schema#5749
Conversation
There was a problem hiding this comment.
Thank you @ShaunSpinelli for the pull request. Please add a higher-level test to reproduce the problem you are fixing, the one you described in #3804.
We were discussing type: 'object' change in the past in #3828. During the review, I identified few more test cases to write to ensure all works as expected. I'll re-post them in comments below in a moment.
|
From #3828 (review)
From #3828 (comment) I was thinking about adding a new test to If I understand your scenario correctly, then you want to reject requests when a required property is set to Alternatively, you can create a new From #3828 (comment) I think the change in behavior may be caused by #3895, where we started to add When I change the definition of Obviously, we don't want to change all existing tests to start testing the scenario with Let me ask you a question: how are your models configured? Do you use the default "strict" model behavior, or are you disabling it via model settings? If you are using strict mode, then I think you should be find a this pull request is not needed for your app. |
|
IMO, we need to add tests to cover the following scenarios:
I feel it's crucial to verify the outcome of AJV validation before the proposed changes and after the change to ensure we are getting the desired behavior. I consider the changes made in the existing tests as "unit-level" - we know what schema is emitted, but don't verify that it gives the desired behavior during validation. |
d3541c7 to
97c7d45
Compare
|
Hi @bajtos, Thanks for the feedback. I have updated the tests for
And in addition added tests for when the body of the request is a string, which was the initial reason I discovered the issue. Let me know if these tests are what you were expecting and if there is any other work that required. Cheers |
bajtos
left a comment
There was a problem hiding this comment.
Thank your @ShaunSpinelli for adding new tests, the change looks good to me know.
@jannyHou you are one of the code owners for OpenAPI-related code, could you please review the proposed changes took and take care of landing the pull request?
| async create( | ||
| @requestBody({required: true}) data: ProductNotStrict, | ||
| ): Promise<ProductNotStrict> { | ||
| return new ProductNotStrict({id: 1, name: 'pencil'}); |
There was a problem hiding this comment.
Can you please add a code comment to explain why you are using hard-coded model properties instead of passing the data argument? I assume this is needed to bypass validation at juggler level and ensure we reject the request at REST API layer.
There was a problem hiding this comment.
@ShaunSpinelli same question as @bajtos mentioned, any reason why not use:
return new Product(data);?
jannyHou
left a comment
There was a problem hiding this comment.
Thanks @ShaunSpinelli the changes LGTM. I left a comment, same as @bajtos mentioned, just in case there is anything we didn't catch.
Other than that the PR is good to land 👍 .
| async create( | ||
| @requestBody({required: true}) data: ProductNotStrict, | ||
| ): Promise<ProductNotStrict> { | ||
| return new ProductNotStrict({id: 1, name: 'pencil'}); |
There was a problem hiding this comment.
@ShaunSpinelli same question as @bajtos mentioned, any reason why not use:
return new Product(data);?
97c7d45 to
fb05054
Compare
jannyHou
left a comment
There was a problem hiding this comment.
Thank you for the update @ShaunSpinelli , the PR looks good now 👍 I am going to land it.
Again we appreciate your contribution 🎉 .
#3804
Added type 'object' to generated model schema to allow
ajvvalidation to work correctly.Fixes #3804
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈