스프링 API 2.92.2와 Spring 4.3 및 Jackson 2.22.2로 구성된 내 API를 쓸데없는 문서로 만들려고합니다. 엔드 포인트 선언의Swagger 1.5가 유효한 JSON 설명을 생성하지 않음
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<scope>compile</scope>
<version>1.5.12</version>
</dependency>
일 :
내가 사용하고있어 자신감 패키지는
@POST
@ApiOperation(
value = "creates folder hierarchy type client|lead",
notes = "creates folder hierarchy type client|lead"
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "creation successfull")
})
@Path("create_type")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createHierarchy(
@ApiParam(value = "hierarchy type", required = true) @NotNull @FormDataParam("type") EHierarchyType hierarchyType,
@ApiParam(value = "parametric part of the hierarchy", required = true) @NotNull @FormDataParam("params") Map<String, Folder2> folderMap
) throws ItemExistsException, AccessDeniedException, PathNotFoundException, WebserviceException, RepositoryException, DatabaseException, ExtensionException, AutomationException, UnknowException, IOException, UserQuotaExceededException, LockException, VersionException {
StopWatch stopWatch = new StopWatch();
folderCtrl.createHierarchy(folderMap, hierarchyType);
logger.info("create hierarchy took: " + stopWatch.getElapsedTime());
return Response.ok().build();
}
이 생성 된 JSON이 엔드 포인트에 대해 같은 모습입니다 :
"/folder/create_type" : {
"post" : {
"tags" : [ "folder" ],
"summary" : "creates folder hierarchy type client|lead",
"description" : "creates folder hierarchy type client|lead",
"operationId" : "createHierarchy",
"consumes" : [ "multipart/form-data" ],
"parameters" : [ {
"name" : "type",
"in" : "formData",
"description" : "hierarchy type",
"required" : true,
"type" : "string",
"enum" : [ "CLIENT", "LEAD" ]
}, {
"name" : "params",
"in" : "formData",
"description" : "parametric part of the hierarchy",
"required" : true,
"type" : "object"
} ],
"responses" : {
"200" : {
"description" : "creation successfull"
}
}
}
}
swagger editor에서이 출력을 구문 분석하려고하면 오류가 다시 반환되며 그 이유는 "paramas"names 매개 변수에서 스키마 대신 객체 유형을 생성했을 수도 있습니다. 이유는 무엇입니까? 흔들리는 부분에 버그가 있습니까? 아니면 놓친 부분이 있습니까?
또한 다른 끝 점에는 @ApiModel로 주석 된 pojo 모델 객체 인 @FormDataParam이 있습니다. 이것은 'ref'유형으로 swagger에 의해 번역되었지만 사용자에게이 객체가 무엇인지 또는 어떤 필드가 포함되어야하는지에 대한 다른 단서를 제공하지 않습니다. Swagger-UI에서는 param 유형으로 '정의되지 않음'만 표시됩니다. 이것은별로 알려주지 않습니다. 객체의 구조를보고, json 정의를 예제로 제공하기 위해 내가해야 할 일은 무엇입니까? 감사합니다.
'formData' 매개 변수는 원시 유형이나 배열을합니다 ([사양의 관련 부분]을 참조 지원 (HTTPS ://github.com/OOAI/OpenAPI-Specification/blob/master/versions/2.0.md#user-content-parameterType)). 'Map'과 같은 객체를 전달하려면 대신'body' 매개 변수를 사용해야합니다. 대부분 두 입력 매개 변수는 단일 본문 스키마로 표현되어야합니다. 하지만 어노테이션을 사용하여 표현하는 방법을 모르겠습니다. – Helen
사실 이것은 바로, 헬렌!멀티 파트 본문 요청이고 둘 이상의 매개 변수가있는 한 입력 개체를 형식으로 매핑하지 않습니다. 내가 보여준 엔드 포인트를 본문에있는 하나의 맵으로 변환 할 수 있지만 다른 엔드 포인트와 함께 메타 데이터 오브젝트와 함께 파일을 수신해야 할 때 수행 할 작업은 무엇입니까? – greengold