我是新来的。我有以下代码:
@RestController
@RequestMapping(value = { V1P})
@Api(value = V1P, description= "My Operations Management API")
public class MethodController {
/**
* @return -
*/
@ApiOperation(value = "retrieve task information", notes = "retrieve service instance information", response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Failure")})
@SuppressWarnings("nls")
@RequestMapping(value = BASE_PATH , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> retrieve() {
....
}
@ApiOperation(nickname = "openTaskUsingGet", value = "Open a task", notes = "API to Open a task", response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Failure")})
@ApiImplicitParams({
@ApiImplicitParam(name = "taskReferenceId", value = "Reference ID of the task", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taskSummary", value = "The task's summary description", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "contentDocumentId", value = "The content document ID of the task", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "createdBy", value = "The name of the creating user", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "teamReferenceId", value = "The creating team reference ID", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taskFromTime", value = "Task planned start time", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taskDueTime", value = "Task planned due time", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taskGroup", value = "Task group name", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "taskType", value = "Task type", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteLongitude", value = "Site longitude coordinate", required = true, dataType = "double", paramType = "query"),
@ApiImplicitParam(name = "siteLatitude", value = "Site latitude coordinate", required = true, dataType = "double", paramType = "query"),
@ApiImplicitParam(name = "siteZipCode", value = "Site zip code", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteName", value = "Site name", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteCountry", value = "Site country", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteState", value = "Site state", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteCity", value = "Site city", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteAddress", value = "Site address", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteComments", value = "Site comments", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "siteReferenceId", value = "Site reference ID", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "eqType", value = "Equipment type", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "eqReferenceId", value = "Equipment reference ID", required = true, dataType = "string", paramType = "query")
})
@SuppressWarnings({ "nls", "javadoc" })
@RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> openTask(
@RequestParam("taskReferenceId") String taskReferenceId,
@RequestParam("taskSummary") String taskSummary,
@RequestParam("contentDocumentId") String contentDocumentId,
@RequestParam("createdBy") String createdBy,
@RequestParam("teamReferenceId") String teamReferenceId,
@RequestParam("taskFromTime") String taskFromTime,
@RequestParam("taskDueTime") String taskDueTime,
@RequestParam("taskGroup") String taskGroup,
@RequestParam("taskType") String taskType,
@RequestParam("siteLongitude") double siteLongitude,
@RequestParam("siteLatitude") double siteLatitude,
@RequestParam("siteZipCode") String siteZipCode,
@RequestParam("siteName") String siteName,
@RequestParam("siteCountry") String siteCountry,
@RequestParam("siteState") String siteState,
@RequestParam("siteCity") String siteCity,
@RequestParam("siteAddress") String siteAddress,
@RequestParam("siteComments") String siteComments,
@RequestParam("siteReferenceId") String siteReferenceId,
@RequestParam("eqType") String eqType,
@RequestParam("eqReferenceId") String eqReferenceId){
....
}
@ApiOperation(nickname = "openTaskUsingPOST", value = "Open a task", notes = "API to Open a task", response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Failure")})
@SuppressWarnings({ "nls", "javadoc" })
@RequestMapping(value = BASE_PATH + "/mob/openTask" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> openTask(@RequestBody OpenTaskCmd cmd){
...
}
@ApiOperation(value = "Get an HTML summary of a package content", notes = "API to get an HTML summary of a package content", response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Failure")})
@ApiImplicitParams({
@ApiImplicitParam(name = "packageName", value = "The name of the required package", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "packageVersion", value = "The required package version", required = true, dataType = "string", paramType = "query")
})
@SuppressWarnings({ "nls", "javadoc" })
@RequestMapping(value = BASE_PATH + "/mob/getContent" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.TEXT_HTML_VALUE)
public ResponseEntity<String> getContent(@RequestParam("packageName") String pkgName,
@RequestParam("packageVersion") String pkgVersion){
....
}
@ApiOperation(value = "Get the activities of a project as a Json array", notes = "API to get the activities of a project as a Json array")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 500, message = "Failure")})
@ApiImplicitParams({
@ApiImplicitParam(name = "startIndex", value = "The first activity index", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageSize", value = "The number of activities", required = true, dataType = "string", paramType = "query")
})
@SuppressWarnings("javadoc")
@RequestMapping(value = BASE_PATH + "/mob/readActivities" , method = RequestMethod.GET, consumes = MediaType.TEXT_PLAIN_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> readActivities(@RequestParam("startIndex") int startIndex,
@RequestParam("pageSize") int pageSize){
...
}
}
这是我得到的 json 的一部分:
{"swagger":"2.0","info":{"description":"Operation Management","version":"v1","title":"API","host":"127.0.0.1","basePath":"/","tags":[{"name":"v1","description":"Operations Management API"}],
"paths":{
"/v1/proxy/resource":{..."responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}},
"/v1/proxy/resource/mob/getContent":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}},
"/v1/proxy/resource/mob/openTask":{"post":{"tags":["v1"],"summary":"Open a task","description":"API to Open a task","operationId":"openTaskUsingPOSTUsingPOST","consumes":["application/json"],"produces":["text/plain"],"parameters":[{"in":"body","name":"cmd","description":"cmd","required":true,"schema":{"$ref":"#/definitions/OpenTaskCmd"}}],"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure"}}}},
"/v1/proxy/resource/mob/readActivities":{"get":{...,"responses":{"200":{"description":"Success","schema":{"type":"string"}},"401":{"description":"Unauthorized"},"500":{"description":"Failure","schema":{"$ref":"#/definitions/Error"}}}}}},
"definitions":{"OpenTaskCmd":{...}}}}}
我无法弄清楚Json有两个问题:
- 我有两个 openTask 接口,一个 GET 和一个 POST,但招摇的 Json 只包括 POST 一个。
- 对于某些接口,我得到 "schema":{"$ref":"#/definitions/Error"} 的 500 响应,但我没有这个模式,我不明白为什么我只得到它一些服务。我定义错了什么?谢谢,尼尔