Skip to content

[BUG][PYTHON] python-experimental fails to determine spec version and throws NullPointerException #12196

@jotelha

Description

@jotelha

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?
Description

When using

docker run --rm --network="host" -v "${PWD}:/local" --user $UID:$UID openapitools/openapi-generator-cli:latest generate -i /local/openapi.json -o /local/out/python-experimental -g python-experimental --verbose

on an openapi description, the python-experimental code generator would throw

Exception in thread "main" java.lang.NullPointerException
	at org.openapitools.codegen.languages.PythonExperimentalClientCodegen.preprocessOpenAPI(PythonExperimentalClientCodegen.java:2325)
	at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:257)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:878)
	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)

where both python and python-legacy would run through without complaints.

Looking at the failing lines at

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
String originalSpecVersion;
if (openAPI.getExtensions() != null && !openAPI.getExtensions().isEmpty()) {
originalSpecVersion = (String) openAPI.getExtensions().get("x-original-swagger-version");
} else {
originalSpecVersion = openAPI.getOpenapi();
}
Integer specMajorVersion = Integer.parseInt(originalSpecVersion.substring(0, 1));
if (specMajorVersion < 3) {
throw new RuntimeException("Your spec version of "+originalSpecVersion+" is too low. python-experimental only works with specs with version >= 3.X.X. Please use a tool like Swagger Editor or Swagger Converter to convert your spec to v3");
}
}

I tried to manually modify the openapi descrition (autogenerated by flask_smorest)

{
  "x-internal-id": "2",
  "security": [
    {
      "bearerAuth": []
    }
  ],
  ...
  "openapi": "3.0.2"
}

by just inserting "x-original-swagger-version": "3.0.2" at the top level

{
  "x-internal-id": "2",
  "security": [
    {
      "bearerAuth": []
    }
  ],
  ...
  "info": {
    "title": "dtool-lookup-server API",
    "version": "v1"
  },
  "tags": [...],
  "openapi": "3.0.2"
}

and it ran through without complaints.

openapi-generator version
$ docker run --rm openapitools/openapi-generator-cli:latest version
6.0.0-SNAPSHOT
OpenAPI declaration file content or url
{
  "x-internal-id": "2",
  "security": [
    {
      "bearerAuth": []
    }
  ],
  ...
  "info": {
    "title": "dtool-lookup-server API",
    "version": "v1"
  },
  "tags": [...],
  "openapi": "3.0.2"
}
Command line used for generation
docker run --rm --network="host" -v "${PWD}:/local" --user $UID:$UID openapitools/openapi-generator-cli:latest generate -i /local/openapi.json -o /local/out/python-experimental -g python-experimental --verbose

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions