Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Kotlin/Spring Boot/API first: Generated code exposes Spring/Java classes as application/octet-stream response models #207

Open
superdurszlak opened this issue Aug 3, 2020 · 0 comments
Labels

Comments

@superdurszlak
Copy link

superdurszlak commented Aug 3, 2020

Describe the bug

Following API annotation is being generated for binary file responses:

    @ApiResponses(
        value = [ApiResponse(code = 200, message = "Returns zipped Foo", response = org.springframework.core.io.Resource::class)])

As a result, following Java / Spring classes are being exposed as Swagger UI API models:

  • org.springframework.core.io.Resource
  • java.io.File
  • java.io.InputStream
  • java.net.URI
  • java.net.URL

To reproduce:

API definition

Example api.yml

Original API definition is more robust, yet the relevant part is the GET endpoint returning file as application/octet-stream.

Gradle task:

swaggerSources {
    create(swaggerProjectName) {
        setInputFile(file("$rootDir/src/main/resources/swagger/api.yml"))
        code(
            closureOf<GenerateSwaggerCode> {
                language = "kotlin-spring"
                components = listOf("apis", "models")
                configFile = file("$rootDir/src/main/resources/swagger/api-config.json")
                outputDir = file(
                    "$buildDir/generated"
                )
            }
        )
    }
}

Json config:

{
  "library": "spring-boot",
  "modelPackage": "com.foo.openapi.model",
  "apiPackage": "com.foo.openapi.api",
  "invokerPackage": "com.foo.openapi",
  "skipDefaultInterface": true,
  "interfaceOnly": true,
  "implicitHeaders": true,
  "java8": true,
  "swaggerAnnotations": true
}

Expected behavior:

Core Spring/Java classes should not be default response types for binary data in generated code and should not be exposed.

Environment

Plugin version: 2.18.2
OpenAPI Codegen version: "org.openapitools:openapi-generator-cli:4.3.1"
Gradle version: 6.4.1
Kotlin version: 1.3.71
JVM: 11.0.8 (Amazon.com Inc. 11.0.8+10-LTS)
OS: Windows 10

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

No branches or pull requests

1 participant