-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Fix #699 serdes missed on items in a collection. #704
Fix #699 serdes missed on items in a collection. #704
Conversation
c16ab96
to
8af4384
Compare
8af4384
to
77dfd37
Compare
Rebased in renewed hope of getting merged. |
Coming here after a bunch of error like this :
I was not getting this errors before, so that strange... I tried your MR and i confirm your fix work well! Hope it will be merge soon! |
@@ -199,6 +199,9 @@ export class SchemaPreprocessor { | |||
const child = new Node(node, s, [...node.path, 'anyOf', i + '']); | |||
recurse(node, child, opts); | |||
}); | |||
} else if (/*schema.type == 'array' && */ schema.items) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schema.type === 'array' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes schema.type array is correct here. Let’s get that updated and I’ll merge this in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robertjustjones Can you add it to your merge request ? or i'll do it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'll get that done this morning. Sorry that I didn't see the comment earlier.
77dfd37
to
10519ec
Compare
@Fabiencdp this was more work that I anticipated because the serdes test has been changed. What's odd is that when I run 699.spec with the "array" lines commented out, I would expect the test to fail but it's passing. I think something solved the array issue more subtly, perhaps bumping AJV. Could that be? There's no sense adding the code (202-204 in schema.preprocessor) if it's not needed. I would feel more comfortable getting tests for "array" in serdes.spec, but without them failing it's hard to see if I have them correct. I've left my commit unsquashed it you'd like to look, not intending for them to be merged as is. Let me know about the above and I can resubmit. Also, very happy to see the dicer issue addressed. |
@robertjustjones, i'll check as soon as i can, I had some good test cases on a living application |
I just tried with the last master version (4.14.0-beta.2), builded locally, imported to the live project, still have the serdes errors about dates. I didn't worked on the test for the moment, i'll try in the weekend. |
Hi @robertjustjones, can you tell me wich test you expect to fail ? EDIT: get it, should be the "should control GOOD id format and get a response in expected format" wich check for date format as string, so when commenting the 202-204, it should fail, am i right ? |
I did some test using a reduced an anonymized part of our project schema, get it to work correctly. |
@robertjustjones, To be clear, without the fix, the initial problem is: For example, let say this part of schema:
with this response object :
Will return But, if you define the schema with a $ref, like this:
The validator don't throw and response is valid: So... What should we do ? Did we must find why it happen ? It could be a problem with the way that reference are parsed ? Or did we should accept your fix ? I'll dig a little more while waiting your opinion. EDIT: |
@Fabiencdp does the latest commit with the modified 699.spec cover the case you mention with historyWithoutRef? |
Nop, i didn't push my last test at the moment |
Sorry, I misunderstood your last comment, I'll check that today |
@robertjustjones, no, it does not cover the case, the schema must be :
Then, comment your fix (schema.preprocessor.ts l202-204) The run the test, you should get a 500 with body If you re-active your fix, the test pass with success. |
4425793
to
e2480e1
Compare
e2480e1
to
fdebec6
Compare
@Fabiencdp you were exactly right! The tests looks to be passing and failing (without the code fix) as expected now. I squashed the commits. Let's gets this one merged. Thanks, so much! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work!
@cdimascio we also need your review |
@cdimascio when do you think you will have time to take a look at this PR? |
@robertjustjones I've faced with another post:
requestBody:
required: true
content:
application/json:
schema:
additionalProperties: false
oneOf:
- type: array
items:
$ref: '#/components/schemas/Variable'
- $ref: '#/components/schemas/Variable'
schemas:
Variable:
description: ""
type: object
required:
- name
- value
additionalProperties: false
properties:
name:
type: string
value:
type: string
nullable: true Check1, body:
Fails and this is not expected:
Check2, body:
Pass request validation as expected |
I'm not sure if "additionalProperties" is valid before "oneOf", You should try to change this part:
|
@Fabiencdp It seems that you are tight, thank you. So it is another issue, I have turned schema validation and did not get any error about that invalid UPD: One more proof that case I mistakenly broad up is not relevant for express-openapi-validator, it seems that |
@Fabiencdp @cdimascio looks like this PR would also close out #666. Identical code fix with similar test. |
@cdimascio |
Just spent several hours on this and found your comment which solved. Looking forward to having this one merged! Thank you for finding. |
@cdimascio many of us have spent a fair amount of time chasing this solved issue after the clear fix was known. Please do stamp this one approved and release it. |
Hey @cdimascio would some coffee help get this merged? |
The owner has no github activity since july 2022... hope he is well. A backup reviewer would help in this case... |
@Fabiencdp You can check the owner's activity for the previous year, it seems to me that the owner appears once in a while (in 6-7 months). Not a good schedule as for production usage, but I have no chance to support this repo :(. Therefore, the question is there a chance that somebody can fork it and re-bake community around a new repo |
He's still recently active on LinkedIn, presumably just focused in other areas like we are. Adding reviewers and/or co-owners would seem to be the way to go to share the load. |
Thanks @cdimascio ! |
:) thank you |
In the schema preprocessor recursion,
items
was left out of the handling forallOf, oneOf, anyOf, properties
.In my addition, I have commented out a check for
schema.type == 'array'
. Please advice on whether it's prudent to add or should be dropped out.The test 699.spec.ts fails without this fix and passes with it. Alternatively, serdes.spec.ts could incorporate that change.
One note, I use Date rather than DateTime because json serialization is doing date.toString, so the serdes code isn't really being tested for date-time. Perhaps changing the test to use any other date format that toISOString would help.
#699