Skip to content

Validation error for schema when JWT is enabled [litestar] #437

@takeda

Description

@takeda

So I'm trying to use robotframework-openapitools which depends on this package, and get the following exception, whenever JWT authentication is enabled (the openapi.json is generated by litestar):

Traceback (most recent call last):
  File "/nix/store/1bpcnjhwz1isqzclvy8b8mixmw1kkiiq-pool-manager-dev-env/lib/python3.12/site-packages/prance/__init__.py", line 248, in _validate_openapi_spec_validator
    validate(self.specification)
  File "/nix/store/1bpcnjhwz1isqzclvy8b8mixmw1kkiiq-pool-manager-dev-env/lib/python3.12/site-packages/openapi_spec_validator/shortcuts.py", line 48, in validate
    return v.validate()
           ^^^^^^^^^^^^
  File "/nix/store/1bpcnjhwz1isqzclvy8b8mixmw1kkiiq-pool-manager-dev-env/lib/python3.12/site-packages/openapi_spec_validator/validation/validators.py", line 71, in validate
    raise err
openapi_spec_validator.validation.exceptions.OpenAPIValidationError: Unevaluated properties are not allowed ('name' was unexpected)

Failed validating 'unevaluatedProperties' in schema['properties']['components']['properties']['securitySchemes']['additionalProperties']['else']:
    {'$comment': 'https://spec.openapis.org/oas/v3.1.0#security-scheme-object',
     'type': 'object',
     'properties': {'type': {'enum': ['apiKey',
                                      'http',
                                      'mutualTLS',
                                      'oauth2',
                                      'openIdConnect']},
                    'description': {'type': 'string'}},
     'required': ['type'],
     'allOf': [{'$ref': '#/$defs/specification-extensions'},
               {'$ref': '#/$defs/security-scheme/$defs/type-apikey'},
               {'$ref': '#/$defs/security-scheme/$defs/type-http'},
               {'$ref': '#/$defs/security-scheme/$defs/type-http-bearer'},
               {'$ref': '#/$defs/security-scheme/$defs/type-oauth2'},
               {'$ref': '#/$defs/security-scheme/$defs/type-oidc'}],
     'unevaluatedProperties': False,
     '$defs': {'type-apikey': {'if': {'properties': {'type': {'const': 'apiKey'}},
                                      'required': ['type']},
                               'then': {'properties': {'name': {'type': 'string'},
                                                       'in': {'enum': ['query',
                                                                       'header',
                                                                       'cookie']}},
                                        'required': ['name', 'in']}},
               'type-http': {'if': {'properties': {'type': {'const': 'http'}},
                                    'required': ['type']},
                             'then': {'properties': {'scheme': {'type': 'string'}},
                                      'required': ['scheme']}},
               'type-http-bearer': {'if': {'properties': {'type': {'const': 'http'},
                                                          'scheme': {'type': 'string',
                                                                     'pattern': '^[Bb][Ee][Aa][Rr][Ee][Rr]$'}},
                                           'required': ['type', 'scheme']},
                                    'then': {'properties': {'bearerFormat': {'type': 'string'}}}},
               'type-oauth2': {'if': {'properties': {'type': {'const': 'oauth2'}},
                                      'required': ['type']},
                               'then': {'properties': {'flows': {'$ref': '#/$defs/oauth-flows'}},
                                        'required': ['flows']}},
               'type-oidc': {'if': {'properties': {'type': {'const': 'openIdConnect'}},
                                    'required': ['type']},
                             'then': {'properties': {'openIdConnectUrl': {'type': 'string',
                                                                          'format': 'uri'}},
                                      'required': ['openIdConnectUrl']}}}}

On instance['components']['securitySchemes']['BearerToken']:
    {'type': 'http',
     'description': 'JWT api-key authentication and authorization.',
     'name': 'Authorization',
     'scheme': 'Bearer',
     'bearerFormat': 'JWT'}

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