Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

validation(openapi-3.1.0) - nullable enums? #378

Open
@kazie

Description

@kazie

I have in an external projects some problems with the openapi-spec-validator.

In our project, we happen to generate an property that either has a value from anenum, or can benull.

See:master...kazie:openapi-spec-validator:test/test-with-enum-string-or-null-property

I would believe this is valid OpenAPI specification for a field, but the validation fails, as from this project fork when running test:

openapi_spec_validator/shortcuts.py:48:invalidatereturnv.validate()base_uri='file:///home/kazie/src/github/openapi-spec-validator/tests/integration/data/v3.1/petstore.yaml'cls=<class'openapi_spec_validator.validation.validators.OpenAPIV31SpecValidator'>sp=SchemaPath('')spec= {'components': {'pathItems': {'PetPath': {'get': {'operationId':'showPetById','parameters': [{...}],'responses': {'...r'}},'summary':'Create a pet','tags': ['pets']}},'/pets/{petId}': {'$ref':'#/components/pathItems/PetPath'}}, ...}v=<openapi_spec_validator.validation.validators.OpenAPIV31SpecValidatorobjectat0x782454500440>__ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _self=<openapi_spec_validator.validation.validators.OpenAPIV31SpecValidatorobjectat0x782454500440>defvalidate(self)->None:forerrinself.iter_errors():>raiseerrEopenapi_spec_validator.validation.exceptions.OpenAPIValidationError:Noneisnotoneof ['ALIVE','DEAD']EEFailedvalidating'enum'inschema:E               {'default':None,E'description':'The status of the pet. `null` if current status can 'E'not be confirmed.',E'enum': ['ALIVE','DEAD'],E'example':'ALIVE',E'type': ['string','null']}EEOninstance:ENoneerr=<OpenAPIValidationError:"None is not one of ['ALIVE', 'DEAD']">self=<openapi_spec_validator.validation.validators.OpenAPIV31SpecValidatorobjectat0x782454500440>openapi_spec_validator/validation/validators.py:71:OpenAPIValidationError

It is true thatNone is not in the enum[ ALIVE, DEAD ], but it is in the type array as['string', 'null']


So, do you believe that my specification is just invalid, or do we have a bug on our hands in the validation here? 😅

I came to this when migrating fromOpenAPI 3.0.3 where we migrate from havingnullable: true into these type arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp