Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][kotlin-spring] Version >= 5.0.0 generates invalid code on HTTP OPTIONS #9773

Open
mwatel42 opened this issue Jun 15, 2021 · 1 comment

Comments

@mwatel42
Copy link

Description

Starting version 5.0.0, it is impossible to generate compiling code when using HTTP OPTIONS in an API. It used to work just fine as the generated code was using @RequestMapping, defining the RequestMethod.

openapi-generator version

>= 5.0.0

OpenAPI declaration file content
openapi: 3.0.3
info:
  title: kotlin-spring generator bug report
  version: v1

paths:
  /world:
    options:
      operationId: options
      tags:
        - hello
      summary: This will generate code that cannot compile
      responses:
        200:
          description: Hello world!
          content:
            application/json:
              example:
                { }
Generation Details

Generated code looks as follow

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (5.0.0).
 * https://openapi-generator.tech
 * Do not edit the class manually.
*/
package com.bugreport.api

import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity

import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired

import javax.validation.Valid
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size

import kotlin.collections.List
import kotlin.collections.Map

@Validated
@RequestMapping("\${api.base-path:}")
interface WorldApi {


    @OptionsMapping(
            value = ["/world"],
            produces = ["application/json"]
    )
    fun options(): ResponseEntity<Unit> {
        return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
    }
}
Steps to reproduce

openapi-generator-cli generate -i bugreport.yml -g kotlin-spring

Related issues/PRs

#7189 (comment)

Suggest a fix

Rollback.

The previous version was covering all cases, at the price of a bit of verbosity on generated code, which is not an issue. The PR can only work for CRUD operations, but all other HTTP methods were lost as a consequence.

As reference, RequestMethod in Spring is defined as:

public enum RequestMethod {
	GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
}

Existing Spring annotations are:

@GetMapping
@PostMapping
@PutMapping
@PatchMapping
@DeleteMapping

Anybody using HTTP HEAD, OPTIONS or TRACE will be unable to use the generator.

@sjoblomj
Copy link
Contributor

sjoblomj commented May 1, 2022

This was fixed in #9900 and this ticket can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants