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

Custom format for unmarshalling doesn't work#778

Answeredbyp1c2u
heidiLinguist asked this question inQ&A
Discussion options

Hello, Thanks for the openap-core project; it's very helpful. I'm using it to validate my api input. I'm trying to make sure that required values that are blank strings are not allowed. I've tried using the documented YAML specs directly (https://swagger.io/docs/specification/data-models/data-types/#string):

type: stringminLength: 1

and

  type: string  pattern: '^.+$'

But the unmarshaller ignores these specifications.

I upgraded to 0.19.0a1 to add a custom validator, perhttps://openapi-core.readthedocs.io/_/downloads/en/latest/pdf/ by@p1c2u Artur Maciag but his example doesn't seem to do anything:

    from datetime import datetime    def unmarshal_usdate(value):        return datetime.strptime(value, "%m/%d/%y").date    extra_format_unmarshallers = {        "usdate": unmarshal_usdate,    }    def validate_usdate(value):        return bool(re.match(r"^\d{1,2}/\d{1,2}/\d{4}$", value))    extra_format_validators = {        "usdate": validate_usdate,    }    config = Config(        extra_format_validators=extra_format_validators,        extra_format_unmarshallers=extra_format_unmarshallers,    )    return OpenAPI.from_file_path(spec_file_path, config=config)

The unmarshaller for the YAML:

                test:                    type: string                    description: Test                    format: usdate

Happily returns:

RequestUnmarshalResult(errors=[], body={'test': 'not a date', 'description': 'A multiple choice activity focusing on synonyms', 'binary_result': True, 'directionality': 'passive', 'modality': 'text', 'interaction_type': 'match', 'activity_context': 'synonym', 'activity_visibility': 'public', 'activity_type_name': 'ok ok ok'}, parameters=Parameters(query={}, header={}, cookie={}, path={}), security={})

tldr; it would be nice to get this custom validator working, but can anyone give me a workaround in the meantime to make sure a string isn't blank?

Thanks,
Heidi

You must be logged in to vote
Answered by p1c2uFeb 11, 2024

Hi@heidiLinguist

thanks for the report, I prepared fix for that. It's part of 0.19.0a2 version

Replies: 1 comment 1 reply

Comment options

Hi@heidiLinguist

thanks for the report, I prepared fix for that. It's part of 0.19.0a2 version

You must be logged in to vote
1 reply
@heidiLinguist
Comment options

Thank you!

Answer selected byp1c2u
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@heidiLinguist@p1c2u

[8]ページ先頭

©2009-2025 Movatter.jp