Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] NullPointerException when I attempt to generate a Python API client #20348

Open
3 of 4 tasks
joseph-grosso opened this issue Dec 18, 2024 · 1 comment
Open
3 of 4 tasks

Comments

@joseph-grosso
Copy link

joseph-grosso commented Dec 18, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?

I don't want to share the full spec as this is used internally and is quite long/would take a while to anonymize.

  • Have you validated the input using an OpenAPI validator?

I validated the swagger file with both the swagger online editor and the openapi-generator validator: openapi-generator validate -i redocly.swagger.yaml

Description

I'm getting a NullPointerException when I attempt to generate a Python API client:

Exception in thread "main" java.lang.NullPointerException: Cannot read field "isArray" because "cp" is null
	at org.openapitools.codegen.languages.AbstractPythonCodegen.getModelNameFromDataType(AbstractPythonCodegen.java:1176)
	at org.openapitools.codegen.languages.AbstractPythonCodegen.getModelNameFromDataType(AbstractPythonCodegen.java:1179)
	at org.openapitools.codegen.languages.AbstractPythonCodegen.createImportMapOfSet(AbstractPythonCodegen.java:1159)
	at org.openapitools.codegen.languages.AbstractPythonCodegen.postProcessAllModels(AbstractPythonCodegen.java:858)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:536)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1303)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

I can generate a client with other paid tools (speakeasy), but I'd prefer to use the free and open source tooling available here.

openapi-generator version

7.11.0-SNAPSHOT

OpenAPI declaration file content or url

https://gist.github.com/joseph-grosso/436781d1e73d66f77bb6c0a2933885af

Generation Details

Steps:

  • combined openapi yaml files into file linked above
  • ran generation command: openapi-generator generate -i redocly.swagger.yaml -g python -o ../python-api
Suggest a fix

The error returned:

java.lang.NullPointerException: Cannot read field "isArray" because "cp" is null
	at org.openapitools.codegen.languages.AbstractPythonCodegen.getModelNameFromDataType(AbstractPythonCodegen.java:1176)

Hopefully if the null was handled differently in this step then this could pass.

The full error output

I believe that the issue is related to one of the warnings below:

  • "allOf schema null containing multiple types (not model) is not supported at the moment."
  • Failed to get the schema name: null
  • WARN o.o.codegen.DefaultCodegen - Unknown type found in the schema: object. To map it, please use the schema mapping option (e.g. --schema-mappings in CLI)
  • INFO o.o.codegen.DefaultGenerator - Model not generated since it's an alias to map (without property) and generateAliasAsModel is set to false (default)
openapi-generator generate -i redocly.swagger.yaml -g python -o ../python-api

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/Users/josephgrosso/github/Carbon-Hub-Backend/openapi/../python-api) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN  o.o.codegen.utils.ModelUtils - Failed to get the schema name: null
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as search_activities_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings search_activities_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings search_activities_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as add_asset_to_asset_group_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings add_asset_to_asset_group_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings add_asset_to_asset_group_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as search_asset_groups_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings search_asset_groups_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings search_asset_groups_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as calculator_results_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings calculator_results_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings calculator_results_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as export_calculator_results_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings export_calculator_results_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings export_calculator_results_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] INFO  o.o.codegen.InlineModelResolver - Inline schema created as search_company_unit_config_request. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings search_company_unit_config_request=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings search_company_unit_config_request=NewModel,ModelA=NewModelA in CLI).
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
[main] WARN  o.o.codegen.InlineModelResolver - allOf schema `null` containing multiple types (not model) is not supported at the moment.
...
[main] INFO  o.o.codegen.DefaultGenerator - Model AggregatedCalculatorResults not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model AggregatedRecordValues not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model AnalyticsCalculatorInputs not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model AnalyticsCalculatorAssetInputs not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model InputRecordResults not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model AggregatedRecordValuesResults not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model CalculatorResultGroupByFields not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model CustomAttributeDataTypeList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model CustomAttributeEntityTypeList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model CustomAttributes not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model DeviceAttribute not generated since it's a free-form object
[main] INFO  o.o.codegen.DefaultGenerator - Model DeviceTypeList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model EstimationMethodDefaultRecordsList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model CalculatorInputSources not generated since it's an alias to map (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model EquipmentTypeList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
[main] INFO  o.o.codegen.DefaultGenerator - Model FacilityList not generated since it's an alias to array (without property) and `generateAliasAsModel` is set to false (default)
...
[main] INFO  o.o.codegen.DefaultGenerator - Model RecordFilterFields_allOf_flow_associated_facility_custom_attributes not generated since it's a free-form object
Exception in thread "main" java.lang.NullPointerException
        at org.openapitools.codegen.languages.AbstractPythonCodegen.getModelNameFromDataType(AbstractPythonCodegen.java:1176)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.getModelNameFromDataType(AbstractPythonCodegen.java:1179)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.createImportMapOfSet(AbstractPythonCodegen.java:1159)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.postProcessAllModels(AbstractPythonCodegen.java:858)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:536)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1303)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
@wing328
Copy link
Member

wing328 commented Dec 20, 2024

https://gist.github.com/joseph-grosso/436781d1e73d66f77bb6c0a2933885af returns 404

can you please reshare the spec?

@wing328 wing328 changed the title [BUG] Description [bug] NullPointerException when I attempt to generate a Python API client Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants