Skip to content

fix: type field#20

Merged
erosb merged 2 commits intoerosb:masterfrom
barmic:types
Mar 21, 2026
Merged

fix: type field#20
erosb merged 2 commits intoerosb:masterfrom
barmic:types

Conversation

@michel-barret
Copy link
Copy Markdown
Contributor

No description provided.

@michel-barret michel-barret marked this pull request as draft March 6, 2026 06:51
@erosb
Copy link
Copy Markdown
Owner

erosb commented Mar 6, 2026

Hello, indeed the issue is valid, thank you for working on it. Overall the fix looks good to me, but one more higher-level test would be good to have, which reads up a real openapi yaml (which somewhere uses a multi-type definition). You can use RequestValidatorTest as reference. Can you please add that?

@michel-barret michel-barret marked this pull request as ready for review March 6, 2026 11:11
@michel-barret
Copy link
Copy Markdown
Contributor Author

@erosb I think that validation need an update of json-sKema. I tried without, I replace the type with array by equivalent with oneOf. The vaidation works but the violation message not I don’t understand why. I will have some difficuties to work on json-sKema...

@araffass
Copy link
Copy Markdown
Contributor

Hello @erosb,

Hope you're doing well.

Just a quick update on this PR: the required change in json-sKema has been merged (PR #202 – Improve error message for multi-type validation).

This resolves the dependency that was blocking the work here. From our side, the implementation should now be ready for merge if everything looks good to you.

Thanks again for your time reviewing this, and please let us know if you'd like any further adjustments!

@araffass
Copy link
Copy Markdown
Contributor

Hi @erosb,

Any updates on this PR please ?

Copy link
Copy Markdown
Owner

@erosb erosb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment added, otherwise this looks very good overall.

JsonNode rawJson = TreeUtil.json.convertValue(this, JsonNode.class);

// Transform array type to oneOf for proper validation
if (hasMultipleTypes() && rawJson instanceof ObjectNode) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this transformation is necessary? Does anything break without it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the transformation is necessary because the underlying validator (and its discriminator check) often expects the type property to be a single string.

As you know In OAS 3.1, types are frequently defined as arrays (e.g., ["string", "null"]). By rewriting these as an anyOf or oneOf block, we kinda normalize the schema into a structure that the validation engine and discriminator logic can process without triggering wrongType syntax errors.
This ensures full compatibility with OAS 3.1 nullability patterns while keeping the core validator stable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer to take precaution and handle any potential errors

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello again, I checked out your branch, commented out line 388-397 from Schema.java and all tests are passing. I'd rather delete these, since this transformation looks unnecessray, and it would be better not to have such transformation. This added "anyOf" would be present in the returned validation errors, which would be confusing for the user since they didn't write this "anyOf" in their schema. The underlying json-sKema already handles "type" arrays properly, so I'm not worried about potential errors.

Please delete line 388-397 then we can go ahead with merging and publishing a new kappa release :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! will do and get back to you

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erosb it's done ✅

feat: type must accept an array of string
@erosb erosb merged commit 36a1de4 into erosb:master Mar 21, 2026
1 check passed
@erosb
Copy link
Copy Markdown
Owner

erosb commented Mar 21, 2026

Hello @araffass , thank you for your work. I published version 2.0.5 with your bugfix on maven central.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants