Guide - 7.10.12.2 Migrating to OpenApi 3.0 and Swagger 2.X Annotations

Product Version

7.10

Product To Version


Status

final

1 Introduction

This document shows major differences between swagger-annotations 1.5.x and 2.x.

2 General


1.5.x2.x
GeneratedOpenApi 2.0OpenApi 3.0
AnnotationsAnnotations 1.5.XSwagger 2.X Annotations
Specification documentationBasic StructureBasic Structure
Maven Repositoryio.swagger:swagger-annotations

io.swagger.core.v3:swagger-annotations

3 Annotations for Models

1.5.x2.xNotes
@APIModel(description = "...")@Schema(description = "...")@Schema is used not only to define schemas (which are basically entities/data classes or properties) but also to reference such with @Schema(implementation=<someclass>.class)
@APIModelProperty(description = "...")@Schema(description = "...")Only if the decorated getter is not an array type.
@APIModelProperty(description = "...")@ArraySchema(schema = @Schema(implementation = <someclass>.class, description = "..."))Only if the decorated getter is an array type.
@APIModelProperty(readOnly = true)@Schema(accessMode=AccessMode.READ_ONLY)

4 Annotations for Operations

1.5.x2.xNotes

@Path("/testpath")
@Api("Some API")

public class SomeClass

@Path("/test")
@Tag(name="testpath", description="Some API")

public class SomeClass

@ApiOperation@OperationSee below for usage
@APIResponsesremovedSee below for usage
@APIResponse@ApiResponseSee below for usage; ApiResponse.responseCode is a String now (not int)
@ApiParam(value = "...", example = "...")@Parameter(description = "...", example = "...")


4.1 Examples for Operations

Example for an API Operation
@Operation(summary = "Gets the recurring order with the given identifier",
                    responses = { @ApiResponse(responseCode = OK, description = OK_MSG,
                                    content = @Content(schema = @Schema(implementation = RecurringOrderRO.class))),
                                    @ApiResponse(responseCode = NOT_FOUND, description = NOT_FOUND_MSG) })
@GET
@Path("/{externalID}/")
@Override
public Response get(@Parameter(description = "The external id") @PathParam("externalID") String externalID)
{
    return Response.ok(something).build();
}

5 Others

1.5.x2.xNotes
@SwaggerDefinition(basePath = "/myapi", host="intershop.de"
                info = @Info(...),
                consumes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML },
                produces = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML },
                schemes = { SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS })
@OpenAPIDefinition(
                servers= {
                    @Server(url="http://intershop.de/myapi"),
                    @Server(url="https://intershop.de/myapi")
                },
                info = @Info(...))
basePath, host and schemes are now merged into servers
@SwaggerDefinition.consumes, @SwaggerDefinition.producesremovedWas removed, now MediaTypes are specified per-resource (with @Consumes/@Produces)
@Api(hidden = true)@Hidden@Hidden works for models or operations

Disclaimer

The information provided in the Knowledge Base may not be applicable to all systems and situations. Intershop Communications will not be liable to any party for any direct or indirect damages resulting from the use of the Customer Support section of the Intershop Corporate Web site, including, without limitation, any lost profits, business interruption, loss of programs or other data on your information handling system.

Customer Support
Knowledge Base
Product Resources
Support Tickets