Support parameter casting in composite schemas#1136
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Limitations
Greedy Casting in
oneOf/anyOf:The logic returns on the first successful cast:
The Edge Case: If you have
oneOf: [{type: "string"}, {type: "integer"}]and the input is"123".{type: "string"}is evaluated first,AnyCasterreturns the string"123".{type: "integer"}is evaluated first, it returns the integer123.Because it's greedy, the final type depends heavily on the order of the list in the OpenAPI spec. Downstream JSONSchema validation might act differently depending on this outcome. However, without combining casting and validation into a single complex step (which would require a massive rewrite of openapi-core), this greedy approach is the industry-standard compromise.
Value Mutation in
allOf:The Edge Case: If Subschema A casts the string
"1"to an int, Subschema B will receive the int1to cast. If Subschema B is a string-based constraint (e.g., maxLength), the string caster might safely ignore the int or stringify it, but mutating the variable sequentially means subsequent casters operate on transformed data rather than raw data. Again, since allOf implies intersection, refining the variable sequentially is usually logically sound, but it's a subtle side effect.Fixes #698