openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] Not generating @Deprecated annotations

Open sourav-jha opened this issue 4 years ago • 10 comments

Description

We have deprecated an API in our yaml file. We are generating the code using open api generator maven plugin. The generated code has "@deprecated" in java comments but no "@Deprecated" annotation on the method.

openapi-generator version:5.4.0
OpenAPI declaration file content or url

yaml content:

paths:
  '/debug-endpoint/v1/person/{id}':
    get:
      deprecated: true
      summary: get person info
      description: Get
      parameters:
        - name: Id
          in: path
          required: true
       ......
Generation Details

plugin config

  <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>5.4.0</version>
        <configuration>
          <generateSupportingFiles>true</generateSupportingFiles>
          <generatorName>spring</generatorName>
          <generateApiDocumentation>true</generateApiDocumentation>
          <generateModelDocumentation>true</generateModelDocumentation>
          <!-- Duplicate classes being generated due to https://github.com/OpenAPITools/openapi-generator/issues/2701 -->
          <typeMappings>a=b</typeMappings>
          <configOptions>
            <oas3>true</oas3>
            <useTags>true</useTags>
            <withSeparateModelsAndApi>true</withSeparateModelsAndApi>
            <delegatePattern>true</delegatePattern>
            <withInterfaces>true</withInterfaces>
            <library>spring-boot</library>
            <dateLibrary>java8</dateLibrary>
            <useSpringfox>false</useSpringfox>
            <useSpringController>true</useSpringController>
            <modelPropertyNaming>camelCase</modelPropertyNaming>
          </configOptions>
          <!-- Option to prevent openapi generator to strip off common prefix from enum values -->
          <additionalProperties>removeEnumValuePrefix=false</additionalProperties>
          <!-- <skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>-->
        </configuration>

sourav-jha avatar Jul 08 '22 13:07 sourav-jha

openapi-generator version:5.4.0

can you please try the latest stable version v6.0.1? there's been a lot of enhancements, bug fixes in the spring boot generator.

wing328 avatar Jul 09 '22 12:07 wing328

same issue in 6.0.1 also

sourav-jha avatar Jul 11 '22 04:07 sourav-jha

This is still not working in 6.2.1 using the gradle plugin. The @Deprecated annotation is not generated on fields with deprecated: true.

quincy avatar Dec 21 '22 19:12 quincy

Still not working in 6.4.0

dschulten avatar Mar 29 '23 10:03 dschulten

Do we have any update on this issue, the issue seems specific to the spring-boot library type.

pskoli avatar Apr 25 '23 10:04 pskoli

This also occurs in the quarkus library.

KnechtRootrecht avatar Jul 18 '23 08:07 KnechtRootrecht

@sourav-jha This seems to have been fixed via #16493 – can you check if this is solved for you and close the issue if it is?

Philzen avatar Jun 04 '24 12:06 Philzen

@Philzen, I now have it twice when using the spring generator with generateBuilders set to true. Generated Java code does not compile.

Sample broken Java code:

@Deprecated
public CredentialRepresentation.Builder device(String device) {
  this.instance.device(device);
  return this;
}
@Deprecated

This can be reproduced using for instance the Keycloak OpenAPI spec and the following Maven plugin configuration:

<plugin>
	<groupId>org.openapitools</groupId>
	<artifactId>openapi-generator-maven-plugin</artifactId>
	<version>7.6.0</version>
	<configuration>
		<generatorName>spring</generatorName>
		<skipValidateSpec>true</skipValidateSpec>
		<inputSpec>${project.basedir}/keycloak-admin-api.openapi.json</inputSpec>
		<apiPackage>org.keycloak.admin.api</apiPackage>
		<modelPackage>org.keycloak.admin.model</modelPackage>
		<nameMappings>authTime=depreacatedAuthTime</nameMappings>
		<configOptions>
			<documentationProvider>none</documentationProvider>
			<annotationLibrary>none</annotationLibrary>
			<ensureUniqueParams>true</ensureUniqueParams>
			<generateBuilders>true</generateBuilders>
			<interfaceOnly>true</interfaceOnly>
			<library>spring-http-interface</library>
			<openApiNullable>false</openApiNullable>
			<serializableModel>true</serializableModel>
			<useOptional>true</useOptional>
		</configOptions>
	</configuration>
</plugin>

ch4mpy avatar Jun 10 '24 22:06 ch4mpy

@wing328 This seems to be a regression introduced via #16493 in v7.0.1

Do you want to take a quick look or should i take over?

Philzen avatar Jun 11 '24 06:06 Philzen

Please feel free to submit a PR to fix it or I will take a look over the weekend

wing328 avatar Jun 11 '24 12:06 wing328