quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Generated Python Dataclasses from a JSON schema not valid (non-default argument follows default argument)

Open bertcornelissen opened this issue 2 years ago • 1 comments

When I generate a Python (>=3.7) dataclass from a json schema, the class members are are listed alphabetically. When an optional field (= 'not required') is used, this field gets a default value. No problem but these fields should placed at the end of the dataclass definition:

In next example 'approval_code' is optional and the dataclass that is being generated is as follows:

@dataclass class Ifsf1200: additional_data_private: str aiid: int amount_transaction: str approval_code: Optional[int] = None # THIS IS NOT CORRECT !! bitmap_primary: str bitmap_secondary: str card_acceptor_business_code: int card_acceptor_id_code: str

Looks like it only happens with :int 's !!

Hope I missed some option to avoid this. Used you software before with great success (Thanks)

Bert Cornelissen

bertcornelissen avatar Nov 28 '23 12:11 bertcornelissen

I found out what caused it:

In the schema:
"approval_code": { "type": "string", "format": "integer" },

If I change it to :+1: "approval_code": { "type": "integer", },

it works.

(Schemas were generated from a json file into a Json schema with Quicktype.

Maybe no bug...

Bert Cornelissen

bertcornelissen avatar Nov 28 '23 12:11 bertcornelissen