Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MigrateApiModelToSchema #17

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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