OpenAPITools / OpenAPITools/openapi-generator

[Java] ApiResponse code contains string

Open
#5,812 0 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When using kotlin-spring generator and spring-boot library to generate controller, service, modles, etc. in controller's @ApiResponse, there is code 4XX (which is from docs of openAPI 3 definition of range of response codes). But in generated controller it is errorous because the code is of type int and not string. Will this behavior will be changed to generate wntire range of family codes or this will not be supported?

openapi-generator version

4.3.0

OpenAPI declaration file content or url
openapi: "3.0.2"
info:
  title: "Some API"
  version: "1.0.0"

paths: 
  /test/post:
    post:
      tags:
        - "tag1"
      summary: "Tag1 description"
      description: ""
      operationId: "someId"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "path/to/requesting/object"
      responses:
        '200':
          description: |
            `OK`
          content:
            text/plain:
              schema:
                type: string
        '4XX':
          description: |
            General response to all 4XX error codes.
          content:
            application/json:
              schema:
                $ref: "path/to/responding/object"
        '5XX':
          description: |
            General response to all 5XX error codes.
          content:
            application/json:
              schema:
                $ref: "path/to/responding/object"
Command line used for generation

Gradle task was used like this:
task generateVectorAPIServer(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
id = "generateAPIServer"
generatorName = "kotlin-spring"
inputSpec = "../some-api/api/openapi.yaml"
outputDir = "$buildDir/generated-src-swagger/main/kotlin".toString()
generateModelTests = false
generateApiTests = false
additionalProperties = [
library: "spring-boot",
beanValidations: "true",
swaggerAnnotations: "true",
apiPackage: "cz.some.rest.controller",
apiSuffix: "Controller",
modelPackage: "cz.some.model",
exceptionHandler: "true",
gradleBuildFile: "false",
serviceInterface: "true",
serviceImplementation: "false",
enumPropertyNaming: "UPPERCASE",
serializableModel: "true",
serializationLibrary: "jackson"

]

}

Steps to reproduce

Used provided yaml and gradle task to generate

Generated file exaple:

@ApiOperation(......)
    @ApiResponses(
        value = [ApiResponse(code = 200, message = "`OK`", response = SomeClass::class, responseContainer = "List"),ApiResponse(code = 4XX, message = "General response to all 400 error codes. ", response = ErrorResponse::class),ApiResponse(code = 5XX, message = "General response to all 500 error codes. ", response = ErrorResponse::class)])
    @RequestMapping(
        value = ["/some/post"],
        produces = ["application/json"], 
        consumes = ["application/json"],
        method = [RequestMethod.POST])
    fun doSomething(....) {....}
Related issues/PRs
Suggest a fix/enhancement

If range of response codes is used, generate multiple @ApiResponse with appropriate code from range

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

Reproduce the issue with the provided OpenAPI YAML and Gradle task using the kotlin-spring generator. Start from the generated Kotlin controller's @ApiResponse annotations and determine how 4XX and 5XX response keys are handled; done means the generated controller uses valid response-code values or clearly supports the intended response range.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.