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

Customized format unmarshaller does not work for number type#827

Unanswered
YitingTinaRen asked this question inQ&A
Discussion options

Hello!
I am managing to use this tool to replace the serializer function in the django.
I have the following spec:

cost:type:numberformat:decimal

And the customized format unmarshaller is defined as follows:

fromdecimalimportDecimaldeffloat_to_decimal(value):"""    turn float format into Decimal object    """returnDecimal(str(value))customized_extra_format_unmarshallers= {'decimal':float_to_decimal,}config=Config(extra_format_unmarshallers=customized_extra_format_unmarshallers)OpenAPI.from_file_path('index.yaml',config=config)

But openapi-core ignores my customized_extra_format_unmarshallers, I would like the cost be a decimal object but it still return float data, is this a bug or is there any error in my setup? It would be helpful if there can be a workaround.

Thank you!

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

Please check#821

You must be logged in to vote
2 replies
@YitingTinaRen
Comment options

Hello@p1c2u,

Thanks a lot for the response!
I checked the 0.19.1 release, and the issue in#821 was indeed solved.
Unfortunately the question in this discussion still exists.
I checked the source code, under openapi_core.unmarshalling.schemas.unmarshallers.SchemaUnmarshaller.find_format

forschemainself.schema_validator.iter_valid_schemas(value):schema_validator=self.schema_validator.evolve(schema)primitive_type=schema_validator.get_primitive_type(value)ifprimitive_type!="string":continueif"format"inschema:returnstr(schema.getkey("format"))returnNone

I believe it is theif primitive_type != "string": condition makes thenumber type data can not be processed by the extra_format_unmarshaller defined by users.

I am wondering will the function be open in the future?

BTW many thanks for releasing the solution for#821 in short period!

@p1c2u
Comment options

The condition was set to simplify the process otherwise we would have to pass type for each format unmarshaller. I hope in future we can support all types.

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
@YitingTinaRen@p1c2u

[8]ページ先頭

©2009-2025 Movatter.jp