Jersey 기반 REST API 문서화를 위해 swagger 도구를 사용하고 있습니다. (2014 년 6 월에 다운로드 한 swaggerui는이 버전이 이후 버전에서 수정되었는지는 모릅니다. 하지만 코드에 많은 사용자 정의를 했으므로 다시 사용자 정의하기 위해 많은 시간을 투자하지 않고 최신을 다운로드 할 수있는 옵션이 없습니다.)Swagger UI에 포함 된 json 속성 모델이 표시되지 않음
지금까지 지금까지 모든 전송 객체는 한 레벨의 깊은 속성 (임베디드 pojos가 없음)을가집니다. 하지만 더 복잡한 객체 (두 단계의 깊이)를 반환하는 나머지 경로를 추가 했으므로 SwaggerUI는 객체를 포함 할 때 JSON 모델 스키마를 확장하지 않는다는 것을 알았습니다.
가 여기에 자신감 된 문서의 중요한 부분입니다 : JSON 응답과 같이
...
{
"path": "/user/combo",
"operations": [{
"method": "POST",
"summary": "Inserts a combo (user, address)",
"notes": "Will insert a new user and a address definition in a single step",
"type": "UserAndAddressWithIdSwaggerDto",
"nickname": "insertCombo",
"consumes": ["application/json"],
"parameters": [{
"name": "body",
"description": "New user and address combo",
"required": true,
"type": "UserAndAddressWithIdSwaggerDto",
"paramType": "body",
"allowMultiple": false
}],
"responseMessages": [{
"code": 200,
"message": "OK",
"responseModel": "UserAndAddressWithIdSwaggerDto"
}]
}]
}
...
"models": {
"UserAndAddressWithIdSwaggerDto": {
"id": "UserAndAddressWithIdSwaggerDto",
"description": "",
"required": ["user",
"address"],
"properties": {
"user": {
"$ref": "UserDto",
"description": "User"
},
"address": {
"$ref": "AddressDto",
"description": "Address"
}
}
},
"UserDto": {
"id": "UserDto",
"properties": {
"userId": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},...
},
"AddressDto": {
"id": "AddressDto",
"properties": {
"addressId": {
"type": "integer",
"format": "int64"
},
"street": {
"type": "string"
},...
}
}
...
내장 객체가 사용자와 주소입니다, 자신의 모델이 제대로 만들어지고있다.
그러나 SwaggerUI을 열 때 나는 단지 볼 수 있습니다{
"user": "UserDto",
"address": "AddressDto"
}
하지만이 같은 것을 볼 수 : 내부 속성을 확장 코드, 자바 스크립트에서 잘못 될 수있다
{
"user": {
"userId": "integer",
"name": "string",...
},
"address": {
"addressId": "integer",
"street": "string",...
}
}
뭔가 콘솔에 오류가 표시되지 않으므로 버그라고 가정합니다. swagger.js에서
이 정의에 대한 조건부 검사와 getSampleValue 기능이있는 파일 :