openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open mharding-hpe opened this issue 1 year ago • 0 comments

Bug Report Checklist

  • [X] Have you provided a full/minimal spec to reproduce the issue?
  • [X] Have you validated the input using an OpenAPI validator (example)?
  • [X] Have you tested with the latest master to confirm the issue still exists?
  • [X] 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.

mharding-hpe avatar May 06 '24 20:05 mharding-hpe