allwefantasy / ServiceFramework

Java MVC framework, agile, fast, rich domain model, made especially for server side of mobile application (一个敏捷,快速,富领域模型的Java MVC 框架,专为 移动应用后端量身定做)
545 stars 255 forks source link

添加类似swagger的接口描述信息 #61

Closed allwefantasy closed 5 years ago

allwefantasy commented 5 years ago

现在你可以这么定义一个接口:

@OpenAPIDefinition(
        info = @BasicInfo(desc = "标签管理接口集合",
                contact = @Contact(url = "", name = "allwefantasy", email = "allwefantasy@gmail.com"),
                license = @License(name = "Apache", url = "...")
        ), externalDocs = @ExternalDocumentation(description = ""), servers = {
        @Server(url = "http://127.0.0.1", description = "测试服务器")
}
)
public class TagController extends ApplicationController {

    @At(path = "/tag", types = {RestRequest.Method.POST})
    @Parameters(
            @Parameter(name = "name", required = true, description = "标签的名字")
    )
    @Responses(
            @ApiResponse(
                    responseCode = "200",
                    description = "返回值为json",
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(type = "string", format = "json", description = "")

                    )
            )
    )
    public void save() {
        Tag tag = Tag.create(params());
        if (tag.save()) {
            render(200, "成功", ViewType.string);
        }
        render(400, "失败", ViewType.string);
    }

然后通过接口 http://..../openapi/ui/spec/ 可以访问到这些描述信息。