我正在运行swagger-ui ver 2.1.3。
我正在使用
生成swagger文档com.mangofactory:swagger-springmvc:1.0.0
我用以下内容注释了我的spring-boot应用程序:
@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(
apiInfo()).includePatterns("/.*");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("User Service", "API for UserService",
"User Service API terms of service","blabla",
"User Service API Licence Type", "User Service API License URL");
return apiInfo;
}
生成的json我们可以看到:
{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "/",
"resourcePath": "/users",
"produces": [
"*/*",
"application/json"
],
"consumes": [
"application/json"
],
"apis": [
{
"path": "/users",
"description": "getMultiple",
"operations": [
{
"method": "GET",
"summary": "getMultiple",
"notes": "getMultiple",
"nickname": "getMultiple",
"produces": [
"*/*"
],
"consumes": [
"application/json"
],
"parameters": [
{
"allowMultiple": false,
"defaultValue": "",
"description": "id",
"name": "body",
"paramType": "body",
"type": "string",
"required": false
}
],
"responseMessages": [
{
"code": 200,
"message": "OK",
"responseModel": "array"
},
{
"code": 401,
"message": "Unauthorized"
},
{
"code": 403,
"message": "Forbidden"
},
{
"code": 404,
"message": "Not Found"
}
],
"deprecated": "false",
"type": "array",
"items": {
"type": "PublicUserProfile"
},
"uniqueItems": false
}
]
},
{
"path": "/users",
"description": "create",
"operations": [
{
"method": "POST",
"summary": "create",
"notes": "create",
"nickname": "create",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"parameters": [
{
"allowMultiple": false,
"defaultValue": "",
"description": "input",
"name": "body",
"paramType": "body",
"type": "User",
"required": false
}
],
"responseMessages": [
{
"code": 200,
"message": null,
"responseModel": "object"
},
{
"code": 201,
"message": "Created"
},
{
"code": 401,
"message": "Unauthorized"
},
{
"code": 403,
"message": "Forbidden"
},
{
"code": 404,
"message": "Not Found"
}
],
"deprecated": "false",
"type": "object"
}
]
},
{
"path": "/users/{userId}",
"description": "getSingle",
"operations": [
{
"method": "GET",
"summary": "getSingle",
"notes": "getSingle",
"nickname": "getSingle",
"produces": [
"*/*"
],
"consumes": [
"application/json"
],
"parameters": [
{
"allowMultiple": false,
"defaultValue": "",
"description": "userId",
"name": "userId",
"paramType": "path",
"type": "string",
"required": true
}
],
"responseMessages": [
{
"code": 200,
"message": "OK",
"responseModel": "PublicUserProfile"
},
{
"code": 401,
"message": "Unauthorized"
},
{
"code": 403,
"message": "Forbidden"
},
{
"code": 404,
"message": "Not Found"
}
],
"deprecated": "false",
"type": "PublicUserProfile"
}
]
}
],
"models": {
"PublicUserProfile": {
"description": "",
"id": "PublicUserProfile",
"properties": {
"userId": {
"required": false,
"type": "string"
},
"name": {
"required": false,
"type": "string"
},
"profileImageUrl": {
"required": false,
"type": "string"
},
"gender": {
"required": false,
"type": "string"
}
}
},
"LocalDateTime": {
"description": "",
"id": "LocalDateTime",
"properties": {}
},
"User": {
"description": "",
"id": "User",
"properties": {
"userId": {
"required": false,
"type": "string"
},
"name": {
"required": false,
"type": "string"
},
"profileImageUrl": {
"required": false,
"type": "string"
},
"gender": {
"required": false,
"type": "string"
},
"primaryEmail": {
"required": false,
"type": "string"
},
"createTime": {
"required": false,
"type": "LocalDateTime"
},
"activationTime": {
"required": false,
"type": "LocalDateTime"
},
"deleted": {
"required": false,
"type": "boolean"
}
}
}
}
}
现在当我发帖时它不会调用它(但请求工作正常) 触发截图:
为什么我使用swagger-ui和POSTS
的帖子有问题/用户发布服务声明:
@RestController
@RequestMapping("/users")
@Slf4j
class PublicUserServicesController {
..
@RequestMapping(method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON)
ResponseEntity<?> create(@RequestBody User input) {
....
return new ResponseEntity<>(user, httpHeaders, HttpStatus.CREATED);
}
..}