datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Stripe OpenAPI issue

Open FabriceSalvaire opened this issue 4 years ago • 3 comments

I cannot generate the code for https://raw.githubusercontent.com/stripe/openapi/master/openapi/spec3.json

# "format": "unix-time",
# ->
#   json_schema_data_formats[type_][format__],
#   KeyError: 'unix-time'

and

#     not model.reference_classes - {model.name} - set(sorted_data_models)
# RecursionError: maximum recursion depth exceeded while calling a Python object

FabriceSalvaire avatar Oct 27 '20 15:10 FabriceSalvaire

Fix env/lib/python3.8/site-packages/datamodel_code_generator/parser/

json_schema_data_formats: Dict[str, Dict[str, Types]] = {
    'integer': {
        'int32': Types.int32,
        'int64': Types.int64,
        'unix-time': Types.int64,
        'default': Types.integer,
    },

Improve error logging in parser/base.py def sort_data_models(

    if unresolved_references:
        try:
            return sort_data_models(
                unresolved_references, sorted_data_models, require_update_action_models
            )
        except RecursionError:
            unresolved_classes = (os.linesep*2).join(
                f"  class: '{item.name}'{os.linesep}     references: {item.reference_classes}"
                for item in unresolved_references
            )
            raise Exception(f'A Parser can not resolve classes:{os.linesep}{unresolved_classes}.')
    return unresolved_references, sorted_data_models, require_update_action_models

to get

  File "/home/fabrice/electrolab-donate/donate/backend/env/lib64/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 92, in sort_data_models
    return sort_data_models(
  [Previous line repeated 991 more times]
  File "/home/fabrice/electrolab-donate/donate/backend/env/lib64/python3.8/site-packages/datamodel_code_generator/parser/base.py", line 100, in sort_data_models
    raise Exception(f'A Parser can not resolve classes:{os.linesep}{unresolved_classes}.')
Exception: A Parser can not resolve classes:
  class: 'ExternalAccounts'
     references: {'BankAccount', 'Object', 'Card'}

  class: 'Account'
     references: {'AccountRequirements', 'AccountSettings', 'BusinessType', 'Type', 'AccountCapabilities', 'AccountTosAcceptance', 'AccountBusinessProfile', 'ExternalAccounts', 'Metadata', 'LegalEntityCompany', 'Person', 'Object1'}

  class: 'AccountBrandingSettings'
     references: {'File', 'IconItem', 'LogoItem'}

  class: 'AccountSettings'
     references: {'AccountSepaDebitPaymentsSettings', 'AccountBacsDebitPaymentsSettings', 'AccountCardPaymentsSettings', 'AccountPaymentsSettings', 'AccountBrandingSettings', 'AccountDashboardSettings', 'AccountPayoutSettings'}
...

FabriceSalvaire avatar Oct 27 '20 19:10 FabriceSalvaire

checked https://swagger.io/tools/swagger-codegen/ generates code

FabriceSalvaire avatar Oct 27 '20 20:10 FabriceSalvaire

@FabriceSalvaire Thank you for creating this issue.

OK, I will support "format": "unix-time",

Also, I checked the problem when generating the Models from the huge schema file. But, I don't understand why we get an error. I will research the reason.

koxudaxi avatar Oct 30 '20 11:10 koxudaxi