openapi-generator: [BUG] Error processing OpenAPI json file for python client

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? (just errors out)
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Trying to process the OpenAPI spec from the Owlery system, https://github.com/phenoscape/owlery (spec posted below) with the python and python-experimental systems, I get errors processing the files.

Using the command-line locally I get:

Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: Knowledgebases
    description: null
    externalDocs: null
}
  Operation: null
  Resource: get /kbs
  Schemas: {}
  Exception: Cannot read field "isEnum" because "cp" is null

Using the docker image I get:

Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: Knowledgebases
    description: null
    externalDocs: null
}
  Operation: null
  Resource: get /kbs
  Schemas: {}
  Exception: null
	at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1163)
	at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1054)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:549)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:891)
	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.NullPointerException
	at org.openapitools.codegen.languages.PythonClientCodegen.fromProperty(PythonClientCodegen.java:440)
	at org.openapitools.codegen.DefaultCodegen.getContent(DefaultCodegen.java:6755)
	at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4011)
	at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1131)
	... 6 more
openapi-generator version

5.4.0

OpenAPI declaration file content or url

YAML is available here: https://gist.github.com/rpgoldman/a65d85f15a9f8b08298cb19446c1b7f0

Generation Details

I believe “steps to reproduce,” below, has all the required information, but happy to collect more if needed.

Steps to reproduce

CLI:

 openapi-generator generate --package-name owlery_client -v --generator-name python --output owlery-client -i swagger.json

Docker:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/swagger.json -g python-experimental -o /local/owlery-client
Related issues/PRs
Suggest a fix

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Aha! For my sub-issue 2 above, the magical answer is to prepend

_JAVA_OPTIONS="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED"

to the invocation of openapi-generator. I can use the python-experimental generator as follows:

_JAVA_OPTIONS="--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED" openapi-generator generate --package-name owlery_client -vv --generator-name python-experimental --output owlery-client -i swagger.yaml 2>&1 | tee openapi-generator-experimental.out

Then it runs to completion successfully.

Just leaving this here, mainly in case it helps someone or might provide a clue.

So, I was using Java 17 with the python generator with the petstore.json and got the java.lang.reflect.InaccessibleObjectException error.

I was able to run other generators, confirmed this by testing with the javascript, java, go generators.

Then I swapped to Java 11 and was able to generate a python SDK when using Java 11, haven’t tried other versions of Java, but perhaps someone might be able to comment on the Java version compatibility…

Great, thanks. I have worked around that for now by adding schemas everywhere. I was having the error reported above when using python-experimental, but with the _JAVA_ARGS workaround now both of the code generators work for me!