FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support parameter casting in composite schemas by p1c2u · Pull Request #1136 · python-openapi/openapi-core · GitHub

Support parameter casting in composite schemas - #1136

Merged
p1c2u merged 3 commits into
masterfrom
fix/composite-schema-casting
Mar 12, 2026
Merged

Support parameter casting in composite schemas#1136
p1c2u merged 3 commits into
masterfrom
fix/composite-schema-casting

Conversation

p1c2u commented Mar 5, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

Limitations

Greedy Casting in oneOf / anyOf:

The logic returns on the first successful cast:

   for subschema in self.schema / "oneOf":
       try:
           return self.schema_caster.evolve(subschema).cast(value)

The Edge Case: If you have oneOf: [{type: "string"}, {type: "integer"}] and the input is "123".

  • If {type: "string"} is evaluated first, AnyCaster returns the string "123".
  • If {type: "integer"} is evaluated first, it returns the integer 123.

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:

   if "allOf" in self.schema:
       for subschema in self.schema / "allOf":
           try:
               value = self.schema_caster.evolve(subschema).cast(value)

The Edge Case: If Subschema A casts the string "1" to an int, Subschema B will receive the int 1 to 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

p1c2u merged commit ca92806 into master Mar 12, 2026
27 checks passed
p1c2u deleted the fix/composite-schema-casting branch March 12, 2026 09:58
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Can’t validate numerical string as type: integer/number/boolean wrapped in allOf/anyOf/oneOf

1 participant


Back | FazBrowse Home | New Git URL