OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-jquery] Code-generator does not support 9xx status codes (raises exception)

Open
#6,691 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

An error is raised if a response code like '9xx' is given.

Test with given exampel and command line.
The given example works with https://editor.swagger.io/
Tested also with petstore.yaml, if an status '901' is added is fails with an similar error.

The German Wikipedia entry states that 9xx codes are common for proprietary use, unfortunately the English does not.
https://www.webcron.org/en/http-codes, lists also 9xx status codes.

The validator reports an invalid response.

I didn't find anything that OpenApi does'nt intentionally support 9xx responses.

openapi-generator version

openapi-generator version: 4.3.1
openjdk build: 10.0.2+13
Windows 10

OpenAPI declaration file content or url
swagger: '2.0'
info:
  description: Interface of REST Service for the Webclient
  version: 2.0.0
  title: REST Interface for Webclient
basePath: /api
tags:
  - name: configurations
paths:
  /measurements:
    get:
      tags:
        - measurements
      description: Returns all measurements
      parameters:
        - name: configurationId
          in: query
          description: Configuration ID
          required: false
          type: integer
          format: int32
        - name: configurationRevision[]
          in: query
          description: Configuration Revision
          required: false
          type: array
          items:
            type: integer
            format: int32
          collectionFormat: multi
      operationId: measurements
      produces:
        - application/json
      responses:
        '200':
          description: All available measurements
          schema:
            type: array
            items:
              type: integer
        '901':
          description: No valid licence

Output:

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: typescript-jquery (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'typescript-jquery' is considered stable.
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Note: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/api]
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/api]
Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: measurements
    description: null
    externalDocs: null
}
  Operation: measurements
  Resource: get /measurements
  Schemas: {}
  Exception: Invalid response code 901
        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1204)
        at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1095)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:556)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1008)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:431)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.RuntimeException: Invalid response code 901
        at org.openapitools.codegen.DefaultCodegen.fromResponse(DefaultCodegen.java:3706)
        at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:3450)
        at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1172)
        ... 6 more
Command line used for generation

openapi-generator generate -i test.yaml -g typescript-jquery -o out\ts-test\

Steps to reproduce

Save the given yaml as test.yaml and genrate according to the given command line

Related issues/PRs
Suggest a fix

Do not raise an error on 9x response values

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 with DefaultCodegen.fromResponse and the failure from DefaultGenerator.processOperation, then reproduce it using the supplied YAML and the typescript-jquery generation command. Confirm that a response code such as 901 is accepted and generation completes without the Invalid response code exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, jquery, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.