micronaut-projects / micronaut-openapi

Generates OpenAPI / Swagger Documentation for Micronaut projects
https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
Apache License 2.0
79 stars 93 forks source link

Micronaut OpenAPI 4.0.0 ignores/drops the return type of an @ApiResponse #656

Closed swaechter closed 2 years ago

swaechter commented 2 years ago

Problem

In Micronaut 3.3.0 with Micronaut OpenAPI 4.0.0, the return type of a controller action in combination with a custom response description + Javadoc is ignored. This leads to an unusable OpenAPI file that can't be used by clients (E.g. in TypeScript, because the generator doesn't know the return type Greeting)

The code:

/**
 * Return a friendly greeting.
 *
 * @return A friendly greeting
 */
@Get("/greeting")
@Tag(name = "Bug9")
@ApiResponse(responseCode = "200", description = "A friendly greeting")
@ApiResponse(responseCode = "500", description = "Internal server error")
public Greeting getGreeting() {
    return new Greeting("A friendly greeting!", UUID.randomUUID(), UUID.randomUUID());
}

On the left the working version in Micronaut 3.2.7 and on the right the dropped fragment in 3.3.0 + Micronaut OpenAPI 4.0.0:

Bug9_1

Remarks

Steps To Reproduce

  1. git clone https://github.com/swaechter/openapiproblems
  2. gradlew clean build + Check out the wrongly generated swagger file
  3. Downgrade to 3.2.7 via gradle.properties
  4. gradlew clean build + Check out the correct generated swagger file

Otherwise: Compare the files Swagger_3.2.7.yml and Swagger_3.3.0.yml with a diff tool

Environment Information

Example Application

Bug 9 in https://github.com/swaechter/openapiproblems

Version

Micronaut 3.3.0 with Micronaut OpenAPI 4.0.0

adamkobor commented 2 years ago

I've experienced the exact same problem after upgrading to 3.3.0 from 3.2.7

graemerocher commented 2 years ago

Caused by https://github.com/micronaut-projects/micronaut-openapi/pull/641

chadlwilson commented 2 years ago

Is there any workaround for this that anyone has figured out?

Alternatively, can someone point me to how to downgrade/override the managed dependency version to 3.2.0 with the Micronaut Application plugin (with Kotlin/kapt)? Similar to Spring's ext['blah.version'] = '1.2.3'?

Nothing i do with manual dependencies seems to work...

graemerocher commented 2 years ago

you can use annotationProcessor("io.micronaut.openapi:micronaut-openapi:3.2.0") to downgrade

chadlwilson commented 2 years ago

I tried that for kapt and it didn't work, unfortunately, so assumed some managed platform / strict dependency constraint Gradle hijinx were required to override somehow.

$ grep openapi build.gradle.kts
    kapt("io.micronaut.openapi:micronaut-openapi:3.2.0")

$ ./gradlew dependencies | grep openapi
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
graemerocher commented 2 years ago

are you using enforcedPlatform instead of platform in your Gradle config?

chadlwilson commented 2 years ago

Not intentionally, unless Micronaut Application plugin does that behind the scenes. Essentially the same as off Micronaut Launch (distilled version below)

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.6.10"
    id("org.jetbrains.kotlin.kapt") version "1.6.10"
    id("org.jetbrains.kotlin.plugin.allopen") version "1.6.10"
    id("io.micronaut.application") version "3.2.0"
}

group = "example"

repositories {
    mavenCentral()
}

micronaut {
    version("3.3.0")
    runtime("netty")
    processing {
        incremental(true)
        annotations("test.*")
    }
}

dependencies {
    implementation("io.micronaut:micronaut-runtime")
    implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
    kapt("io.micronaut.openapi:micronaut-openapi:3.2.0")
    implementation("io.swagger.core.v3:swagger-annotations")
}

application {
    mainClass.set("test.Test")
}
$ ./gradlew dependencies | grep openapi
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
+--- io.micronaut.openapi:micronaut-openapi:3.2.0 -> 4.0.0
|    |    +--- io.micronaut.openapi:micronaut-openapi:4.0.0 (c)
swaechter commented 2 years ago

@chadlwilson I had to !! my Open API processor to 3.2.0. With this workaround the old behaviour is restored (With the danger of breaking in a future release).

For more information: https://docs.gradle.org/current/userguide/single_versions.html#simple_version_declaration_semantics

Workaround

chadlwilson commented 2 years ago

Thanks @swaechter - after years of Gradle, I had no idea there was that !! shorthand for strict constraints. Thanks for teaching me something! That works fine - thanks a lot.

swaechter commented 2 years ago

Hey @n0tl3ss thanks a lot for the fix(es), also the one in #661 :)