OpenAPITools / OpenAPITools/openapi-generator

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

Open
#9,045 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in org.openapitools.codegen.languages.K6ClientCodegen.preprocessOpenAPI at line 322 and reproduce with the k6 generation command and the YAML response containing a 4XX status. Trace where the response status is parsed as an integer. Done means the k6 generator handles 4XX and 5XX responses and generates the client successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.