Skip to content

[BUG][JAVA][resttemplate] Removal of @Component from ApiClient and <Name>Api classes is a breaking change #15136

@TheCK

Description

@TheCK

Bug Report Checklist

  • The list does not apply
Description

PR prompted by Issue removed @Component and @Autowired annotations from the ApiClient and Api classes.

Before this change Spring would automatically find the ApiClient and Api classes and they could easily be autowired. Since this change they will not be auto-discovered by Spring and previously working builds will now fail.

You now have to manually provide the classes to Spring by e.g.:

@Bean
public DefaultApi defaultApi(RestTemplate restTemplate) {
  return new DefaultApi(new ApiClient(restTemplate));
}

Furthermore the PR only removed the annotations but did not remove the imports of the annotation. See:
@Autowired in ApiClient
@Component in ApiClient
@Autowired in Api
@Component in Api

openapi-generator version

6.5.0

OpenAPI declaration file content or url
Generation Details

Our config is:

<configuration>
  <generatorName>java</generatorName>
  <inputSpec>somePath</inputSpec>
  <generateApiTests>false</generateApiTests>
  <generateModelTests>false</generateModelTests>
  <configOptions>
    <openApiNullable>false</openApiNullable>
    <useJakartaEe>true</useJakartaEe>
    <library>resttemplate</library>
  </configOptions>
</configuration>
Steps to reproduce
  1. Build any spec with the java generator and resttemplate lib in version 6.4.0 and generated APIs have an @Component annotation
  2. Build any spec with the java generator and resttemplate lib in version 6.5.0 and generated APIs do not have it anymore
Related issues/PRs

PR
Issue

Suggest a fix

This should never have been merged in a minor update, since it is a breaking change. But since the damage has already been done now it should at least be documented in the changelog of this version and a migration path should be provided.

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