Skip to content

[BUG][JAVA] ApiClient is not compatible with spring-web 6 Observation API #15143

@ferblaca

Description

@ferblaca
Description

We have detected an issue related to the openapi-generator client and the spring-web 6 Observation API introduced in spring-boot 3.

The problem is that the generated ApiClient class, in the invokeAPI method when creating the BodyBuilder with the RequestEntity.method(method, uri) method, without params overloading, so that the uriTemplate field of the BodyBuilder object is always null.

On the other hand, the spring-web 6 Observation API gets the keyValue URI, with which the uri TAG of the http_client_requests metric is given value, for the uriTemplate value of the response. As the uriTemplate is null, the uri TAG always has the value NONE.

openapi-generator version
  • Openapi-generator 6.5.0
  • Spring-Web 6.0.7
  • Spring-boot 3.0.5
OpenAPI declaration file content or url
Generation Details

Modifying the original ApiClient.mustache template so that the requestBuilder is created based on the URI passing the arguments to resolve with the method:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, UriComponentsBuilder.fromHttpUrl(basePath).toUriString() + finalUri, uriParams);

with this method if the TemplateURI fields are set and therefore from the Observation API if it is able to retrieve it and add it with TAG to the http.client.request metrics.

Currently the ApiClient generated with openapi-generator always uses the method:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, uri);

where uri is the URL already resolved with the arguments and the request will never report the TemplateUri field.

Steps to reproduce

I have left a demo here where you can reproduce it with the following steps:

  1. mvn clean install
  2. Start the application
  3. Invoke the endpoint http://localhost:8080/app-rest/invoke-api-client-templatized
  4. Display the metrics generated by the Prometheus endpoint http://localhost:8080/actuator/prometheus

As can be seen, the generated http_client_requests metrics always have the tag uri="none", when they should have the request path: /pet2/{petId}.

 HELP http_client_client_requests_seconds  
# TYPE http_client_requests_seconds summary
http_client_requests_seconds_count{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 1.0
http_client_requests_seconds_sum{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 0.139118975
# HELP http_client_requests_seconds_max  
# TYPE http_client_requests_seconds_max gauge
http_client_requests_seconds_max{client_name="localhost",error="none",exception="none",method="GET",outcome="SUCCESS",status="200",uri="none",} 0.139118975
Related issues/PRs
Suggest a fix

Modify the original ApiClient.mustache template with:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, UriComponentsBuilder.fromHttpUrl(basePath).toUriString() + finalUri, uriParams);

instead:

final BodyBuilder requestBuilder requestBuilder = RequestEntity.method(method, uri);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions