yaml
swagger: "2.0"
info:
title: "Example API"
description: "This is an example API"
version: "1.0.0"
basePath: "/api"
paths:
/users:
get:
summary: "Get all users"
responses:
200:
description: "Successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/User"
definitions:
User:
type: "object"
properties:
id:
type: "integer"
name:
type: "string"
shell
swagger-codegen generate -i swagger.yaml -l spring-boot -o myproject
@SpringBootApplication
public class MyProjectApplication {
public static void main(String[] args) {
SpringApplication.run(MyProjectApplication.class, args);
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example"))
.paths(PathSelectors.any())
.build();
}
}
shell
java -jar myproject.jar