-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit anyOf/oneOf discriminator to listed refs
This addresses an issue where `resolve_ref` gets called for refs that aren't explicitly listed in `anyOf` or `oneOf`. The [specification][0] says: > In both the oneOf and anyOf use cases, all possible schemas MUST be listed explicitly. So for anyOf/oneOf discriminators, this uses the provided refs to build a mapping of property values to schema objects for lookup during validation. Explicit mappings are found by schema name or full ref to support: ```yaml discriminator: propertyName: petType mapping: cat: Cat dog: '#/components/schemas/Dog' ``` Impicit mappings are only created for refs under `#/components/schemas/` and are overridden by any explicit mappings that point to the same schema. `allOf` discriminators still resolve refs because there isn't an explicit list of allowed refs. Switched to `Schema#ref` now that it calls `root.resolve_ref` itself. `FIXED_FIELD_REGEX` comes from the [spec][1]: > All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9\.\-_]+$. It's used in all cases to make sure schemas are only looked up by name if the property value is a valid schema name. Closes: #144 [0]: https://spec.openapis.org/oas/v3.1.0#discriminator-object [1]: https://spec.openapis.org/oas/v3.1.0#components-object
- Loading branch information
1 parent
e5ca2b1
commit d5d5900
Showing
3 changed files
with
170 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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