OpenAPITools / OpenAPITools/openapi-generator

[BUG][PYTHON] Valid schema fails to generate server code

Open
#15,762 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I'm building openapi-generator to build a basic Python mock server based on this valid schema:

I'm using this command

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i https://tower.nf/openapi/nextflow-tower-api-1.19.0.yml \
    -g python-flask \
    -o /local/out/python

and the error is:

[main] WARN  o.o.codegen.DefaultCodegen - 'oneOf' is intended to include only the additional optional OAS extension discriminator object. For more details, see https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9.2.1.3 and the OAS section on 'Composition and Inheritance'.
[main] WARN  o.o.c.l.AbstractPythonCodegen - Type null not handled properly in toExampleValue
[main] ERROR o.o.codegen.DefaultCodegen - Error in generating `example` for the property launch. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.
[main] ERROR o.o.codegen.DefaultCodegen - Error in generating `example` for the property launch. Default to ERROR_TO_EXAMPLE_VALUE. Enable debugging for more info.
[main] WARN  o.o.codegen.DefaultCodegen - allOf with multiple schemas defined. Using only the first one: AbstractGridConfig
[...]
[main] WARN  o.o.codegen.DefaultCodegen - allOf with multiple schemas defined. Using only the first one: ComputeEnv.Status
[main] WARN  o.o.c.l.AbstractPythonCodegen - Type null not handled properly in toExampleValue
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Credentials'.Please make sure that your schema is correct!
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:527)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:948)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:487)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.base/java.lang.StringLatin1.charAt(Unknown Source)
	at java.base/java.lang.String.charAt(Unknown Source)
	at org.openapitools.codegen.languages.AbstractPythonConnexionServerCodegen.postProcessPattern(AbstractPythonConnexionServerCodegen.java:740)
	at org.openapitools.codegen.languages.AbstractPythonConnexionServerCodegen.postProcessModelProperty(AbstractPythonConnexionServerCodegen.java:623)
	at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:3093)
	at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1327)
	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:522)
	... 4 more
openapi-generator version

This specific error occurs for all v6.0.0+
It works for v5.4.0

OpenAPI declaration file content or url

https://tower.nf/openapi/nextflow-tower-api-1.19.0.yml

Generation Details
Steps to reproduce
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i https://tower.nf/openapi/nextflow-tower-api-1.19.0.yml \
    -g python-flask \
    -o /local/out/python
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AbstractPythonConnexionServerCodegen.java, especially postProcessPattern and postProcessModelProperty, using the provided stack trace and the Credentials model as the reproduction point. Run the Docker generation command against the linked OpenAPI schema, then verify that the python-flask server generates successfully without the StringIndexOutOfBoundsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, java, python
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.