Skip to content

Commit

Permalink
MigrateApiModelToSchema (#17)
Browse files Browse the repository at this point in the history
* MigrateApiModelToSchema

MigrateApiModelToSchema, position removal from ApiModelProperty

* Reduce IDE warnings

* Polish docs

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
  • Loading branch information
OlegZavrazhin and timtebeek authored Oct 6, 2024
1 parent e8cc01c commit 178666d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
48 changes: 33 additions & 15 deletions src/main/resources/META-INF/rewrite/swagger-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ recipeList:
- org.openrewrite.openapi.swagger.MigrateApiToTag
- org.openrewrite.openapi.swagger.MigrateApiParamToParameter
- org.openrewrite.openapi.swagger.MigrateApiModelPropertyToSchema
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.swagger.annotations.ApiModel
newFullyQualifiedTypeName: io.swagger.v3.oas.annotations.media.Schema
- org.openrewrite.openapi.swagger.MigrateApiModelToSchema

# todo add swagger-core to common-dependencies

Expand Down Expand Up @@ -109,8 +107,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiOperationToOperation
displayName: Migrate from @ApiOperation to @Operation
description: Converts the @ApiOperation annotation to @Operation and converts the directly mappable attributes
displayName: Migrate from `@ApiOperation` to `@Operation`
description: Converts the `@ApiOperation` annotation to `@Operation` and converts the directly mappable attributes
and removes the others.
tags:
- swagger
Expand Down Expand Up @@ -140,8 +138,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiResponsesToApiResponses
displayName: Migrate from @ApiResponses to @ApiResponses
description: Changes the namespace of the @ApiResponses and @ApiResponse annotations and converts its attributes
displayName: Migrate from `@ApiResponses` to `@ApiResponses`
description: Changes the namespace of the `@ApiResponses` and `@ApiResponse` annotations and converts its attributes
(ex. code -> responseCode, message -> description).
tags:
- swagger
Expand All @@ -166,8 +164,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiImplicitParamsToParameters
displayName: Migrate from @ApiImplicitParams to @Parameters
description: Converts @ApiImplicitParams to @Parameters and the @ApiImplicitParam annotation to @Parameter and converts
displayName: Migrate from `@ApiImplicitParams` to `@Parameters`
description: Converts `@ApiImplicitParams` to `@Parameters` and the `@ApiImplicitParam` annotation to `@Parameter` and converts
the directly mappable attributes and removes the others.
tags:
- swagger
Expand Down Expand Up @@ -196,8 +194,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiToTag
displayName: Migrate from @Api to @Tag
description: Converts @Api to @Tag annotation and converts the directly mappable attributes and removes the others.
displayName: Migrate from `@Api` to `@Tag`
description: Converts `@Api` to `@Tag` annotation and converts the directly mappable attributes and removes the others.
tags:
- swagger
- openapi
Expand All @@ -213,8 +211,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiParamToParameter
displayName: Migrate from @ApiParam to @Parameter
description: Converts the @ApiParam annotation to @Parameter and converts the directly mappable attributes.
displayName: Migrate from `@ApiParam` to `@Parameter`
description: Converts the `@ApiParam` annotation to `@Parameter` and converts the directly mappable attributes.
tags:
- swagger
- openapi
Expand All @@ -230,8 +228,8 @@ recipeList:
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiModelPropertyToSchema
displayName: Migrate from @ApiModelProperty to @Schema
description: Converts the @ApiModelProperty annotation to @Schema and converts the "value" attribute to "description".
displayName: Migrate from `@ApiModelProperty` to `@Schema`
description: Converts the `@ApiModelProperty` annotation to `@Schema` and converts the "value" attribute to "description".
tags:
- swagger
- openapi
Expand All @@ -247,3 +245,23 @@ recipeList:
annotationType: io.swagger.v3.oas.annotations.media.Schema
oldAttributeName: "value"
newAttributeName: "description"
- org.openrewrite.java.RemoveAnnotationAttribute:
annotationType: io.swagger.v3.oas.annotations.media.Schema
attributeName: position

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.swagger.MigrateApiModelToSchema
displayName: Migrate from `@ApiModel` to `@Schema`
description: Converts the `@ApiModel` annotation to `@Schema` and converts the "value" attribute to "name".
tags:
- swagger
- openapi
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: io.swagger.annotations.ApiModel
newFullyQualifiedTypeName: io.swagger.v3.oas.annotations.media.Schema
- org.openrewrite.java.ChangeAnnotationAttributeName:
annotationType: io.swagger.v3.oas.annotations.media.Schema
oldAttributeName: "value"
newAttributeName: "name"
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@ void shouldChangeSwaggerArtifacts() {
java(
"""
package example.org;
import io.swagger.annotations.ApiModel;
@ApiModel
class Example { }
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value="ApiModelExampleValue", description="ApiModelExampleDescription")
class Example {
@ApiModelProperty(value = "ApiModelPropertyExampleValue", position = 1)
private String example;
}
""",
"""
package example.org;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema
class Example { }
@Schema(name="ApiModelExampleValue", description="ApiModelExampleDescription")
class Example {
@Schema(description = "ApiModelPropertyExampleValue")
private String example;
}
"""
),
//language=xml
Expand Down

0 comments on commit 178666d

Please sign in to comment.