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.85k stars 6.59k forks source link

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

Open Nalaxon opened 4 years ago

Nalaxon commented 4 years ago

Bug Report Checklist

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

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

wing328 commented 4 years ago

Don't think it's a good idea to use 901 as the status code: https://stackoverflow.com/a/11871377/677735

Nalaxon commented 4 years ago

@wing328 how about an option to be backwards compatible, since it works fine for http://editor.swagger.io/

sigbits-mvl commented 2 years ago

Don't think it's a good idea to use 901 as the status code: https://stackoverflow.com/a/11871377/677735

Bumping this. I agree that when designing an API the 9xx status code should not be used, but the generator should nonetheless support it, because sometimes that is required to implement a client for a third party API that specifies a 9xx status code.

ayushwing commented 1 year ago

I agree with @sigbits-mvl , If the third-party API is not using a standard status code, the generator should not disallow to create and fail.

jdh5227 commented 11 months ago

Also adding that I agree with the last two comments (@sigbits-mvl & @ayushwing). We're using 600 level codes and I just ran into this same error today.