micronaut-projects / micronaut-gradle-plugin

A Gradle Plugin for Micronaut
Apache License 2.0
65 stars 43 forks source link

clientId not set on generated class #949

Closed KangoV closed 3 months ago

KangoV commented 4 months ago

Expected Behavior

given

micronaut {
    openapi {
        version = "6.6.2"
        client(file("src/main/resources/taizo-feedsmanager-v1-openapi.yaml")) {
            ...
            clientId = "my-client"
        }
    }
}

I would expect the API class to have:

@Client("my-client")
public interface MyApi {
  ...

Actual Behaviour

The API class has:

@Client("${openapi-micronaut-client-base-path}")
public interface MyApi {
  ...

Steps To Reproduce

Create or use an exiting opanapi file. Configure gradle:

micronaut {
    openapi {
        version = "6.6.2"
        client(file("src/main/resources/myapi-v1-openapi.yaml")) {
            apiPackageName = "myapi.client.models"
            modelPackageName = "myapi.client.api"
            useOptional = true
            useReactive = false
            clientId = "my-client"
        }
    }
}

Run ./gradlew generateClientOpenApiApis

Environment Information

MacOS java 21-tem Micronaut 4.3.1 Micronaut Gradle Plugin 4.3.3

Example Application

No response

Version

4.3.1

KangoV commented 4 months ago

This makes it impossible to include two generated clients in the same application. In fact, the clientId value is not found anywhere in the generated code.

melix commented 4 months ago

@altro3 can you take a look at this one? I didn't check but could be a bug in micronaut-openapi instead.

altro3 commented 4 months ago

On weekend

altro3 commented 4 months ago

@KangoV fixed. Use latest version of micronaut-openapi 6.6.3

KangoV commented 4 months ago

Awesome. That worked.

Question though, I have two clients, but they both have path = "${openapi-micronaut-client-base-path}", how are they supposed to work? How do I set a different base path for each?

Should the base path be added to the openapi configuration alongside the clientId?

Ahh, if I set micronaut.http.services.myclient.url=https://api.myserver.com, will that be used instead of the path on the @Client(id="myclient") annotation?

altro3 commented 4 months ago

@KangoV I don't know the answer to this question, because I didn't make the original template. I do not exclude that this is a flaw.

The problem is, I don't quite understand why it was done this way, and because of this, I can't just take the current template and redo it. I want to say, perhaps this was done for some reason and it’s not a bug at all, but “it’s the way it should be.”

Therefore, guys, please help me correctly interpret the current template and, if necessary, then formulate how best to fix it.

@melix @timyates @graemerocher @andriy-dmytruk

altro3 commented 4 months ago

@KangoV So I studied this code, I think I made the generation more convenient. PR here: https://github.com/micronaut-projects/micronaut-openapi/pull/1467

In your case it will be:

@Client("myclient")

But you could set clientPath = true and you will see this:

@Client(id = "myclient", path = "${myclient.base-path}")

Without client id it will be

@Client("${openapi-micronaut-client.base-path}")
KangoV commented 4 months ago

That sounds exactly what I need. Thanks for this 👍 .