Skip to content
New issue

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

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

Already on GitHub? # to your account

[BUG] OAS 3.1.0 python-flask generation fails if operation parameters are specified by reference #18585

Closed
4 tasks done
mharding-hpe opened this issue May 6, 2024 · 2 comments · Fixed by #18605
Closed
4 tasks done

Comments

@mharding-hpe
Copy link

mharding-hpe commented May 6, 2024

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

When generating python-flask, if the OAS version is 3.1.0 and any operations specify any parameters by reference, then the generation fails with the following error:

[main] ERROR o.o.codegen.DefaultCodegen - String to be sanitized is null. Default to ERROR_UNKNOWN
[main] ERROR o.o.codegen.DefaultCodegen - String to be sanitized is null. Default to ERROR_UNKNOWN
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "swaggerParameterName" is null
       at org.openapitools.codegen.languages.AbstractPythonConnexionServerCodegen.preprocessOpenAPI(AbstractPythonConnexionServerCodegen.java:413)
       at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:290)
       at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1214)
       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)

If you attempt the generation using python (instead of python-flask), it works.
If you modify the OAS version to 3.0.x in the API spec file, it works.
If you move the parameter definition to be inline instead of by reference, it works.

openapi-generator version

I have observed this problem with multiple versions, including v7.5.0. I don't recall the earliest version I observed it with, but I am not aware of a version where this ever worked. I do not believe it is a regression.

I also reproduced it using the latest master version of the generator.

OpenAPI declaration file content or url
openapi: "3.1.0"
info:
  title: Test
  version: 1.0.0
components:
  parameters:
    Dogfood:
      name: dogfood
      in: header
      schema:
        type: string
paths:
  /:
    get:
      summary: Test
      parameters:
        - $ref: '#/components/parameters/Dogfood'
      responses:
        200:
          description: Service Health Information
          content:
            application/json:
              schema:
                type: string
Generation Details

generate -i openapi.yaml -g python-flask

Steps to reproduce

Run the specified generate command on a file containing the specified API spec.

Observe that if the same spec is run through the validate option, it passes without complaint.

Observe that the problem does not happen if the OAS version in the spec is changed to 3.0.x, or if python is generated instead of python-flask, or if the parameter definition is moved to be inline instead of being a reference.

Related issues/PRs

I searched and could not find one.

Suggest a fix

I don't have time to dig into this now, but if/when I do, I'll be sure to update the issue. But now that I have a very simple way to reproduce it, I wanted to get the issue open.

@wing328
Copy link
Member

wing328 commented May 8, 2024

fixed via #18585

thanks again for reporting the issue

@mharding-hpe
Copy link
Author

Thank you for the quick work on it!

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants