Repository navigation
Add support for marshmallow-oneofschema polymorphic schemas (#1012) - #1082
Closed
ansh-rohilla wants to merge 1 commit into
Closed
ansh-rohilla wants to merge 1 commit into
ansh-rohilla wants to merge 1 commit into
Conversation
…low-code#1012) Support polymorphic schemas defined with marshmallow-oneofschema.OneOfSchema in MarshmallowPlugin: - Check for marshmallow-oneofschema availability at import time in OpenAPIConverter. - Convert OneOfSchema instances and classes to OpenAPI 3 oneOf schemas with a discriminator object mapping type names to component schema references. - Preserve schema title and description from class Meta when present. - Support nested OneOfSchema instances and anonymous/inline schemas. - Add unit and integration tests covering OneOfSchema conversion and OpenAPI validation. - Add marshmallow-oneofschema as an optional test dependency in pyproject.toml and uv.lock.
Member
|
please see our AI policy |
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.
Summary
This PR adds support for polymorphic schemas defined with
marshmallow-oneofschema.OneOfSchemainMarshmallowPlugin, addressing #1012.Context & Design
marshmallow-oneofschemamultiplexes schemas based on an object type discriminator field (type_field) and mapping (type_schemas). Previously,apispechad no handling forOneOfSchema, translating it to an empty object schema with empty properties and dropping subschemas.Following the discussion in #1012:
marshmallow-oneofschemais checked conditionally at module import time (ONEOFSCHEMA_AVAILABLE). When unavailable,apispecbehaves as before without requiring an external runtime dependency.OpenAPIConverter.schema2jsonschema, whenschemais an instance or subclass ofOneOfSchema, it delegates to_oneof_schema2jsonschema.type_schemasis resolved throughself.resolve_nested_schema, registering named subschemas incomponents.schemasand generating references foroneOf.discriminatorobject is generated withpropertyNameset totype_fieldandmappingassociating each discriminator type key with its schema reference.Metaoptionstitleanddescriptionare preserved when defined on the schema.OneOfSchema(e.g. insidefields.Nested) and anonymous inline schemas (whenschema_name_resolverreturnsNone) are supported.marshmallow-oneofschemais added to thetestsdependency group inpyproject.tomland locked inuv.lock.Validation
pytest).openapi-spec-validator.ruff,ruff format,mypy,zizmor,blacken-docs,uv-lock).CHANGELOG.rst.Closes #1012