OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.72k stars 6.55k forks source link

[BUG] openapi-generator for k6 fails to generate a k6 client when OpenAPI 4XX, 5XX error statuses are present in a response #9045

Open cdimascio opened 3 years ago

cdimascio commented 3 years ago

Bug Report Checklist

Description

When generating a k6 client from ann OpenAPI spec. If a response schema includes e.g. 4XX the generator fails

Expected: The generator properly handles 4XX, 5XX, etc and properly genrates a client

To reproduce:

Run the k6 generator

openapi-generator-cli generate --generator-name k6 --input-spec /path/to/myapi.yml --output generated --skip-validate-spec

Ensure the response includes e.g. 4XX in the response schema e.g.

        4XX:
          description: client
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'

The k6 client code gen fails

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/path/to/generated) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: k6 (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'k6' is considered beta.
[main] WARN  o.o.codegen.DefaultCodegen - The value (generator's option) must be either boolean or string. Default to `false`.
Exception in thread "main" java.lang.NumberFormatException: For input string: "4XX"
        at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
        at java.base/java.lang.Integer.parseInt(Integer.java:652)
        at java.base/java.lang.Integer.parseInt(Integer.java:770)
        at org.openapitools.codegen.languages.K6ClientCodegen.preprocessOpenAPI(K6ClientCodegen.java:322)
        at org.openapitools.codegen.DefaultGenerator.configureGeneratorProperties(DefaultGenerator.java:251)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:864)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:440)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
openapi-generator version
> openapi-generator-cli version
5.1.0
OpenAPI declaration file content or url