private ResponseWithStatusCode buildResponse(Function<Type, Model> modelFactory, Map<String, Object> attributes, Predicate<Integer> statusCode) { Response response = new Response(); String description = (String) attributes.get("apiResponse.message"); Class type = (Class) attributes.get("apiResponse.response"); if (!isVoid(type)) { response.setResponseSchema(modelFactory.apply(type)); } response.setDescription(description); buildResponseHeader(attributes, "apiResponse.responseHeaders", response::addHeader); Integer code = (Integer) attributes.get("apiResponse.code"); String key = code.toString(); if (statusCode.test(code)) { key += "(" + type.getSimpleName() + ")"; } return new ResponseWithStatusCode(key, response); }
.getOrDefault("apiOperation.code", returns.statusCode()); Response response = new Response(); String doc = returns.description() .orElseGet(() -> FriendlyTypeName.name(returns.type())); .forEach(it -> consumer.accept( new ResponseWithStatusCode(it.getKey().toString(), new Response().description(it.getValue()))) );
public void scanResponse() { if (operation.getResponses() != null) { Response successResponse = operation.getResponses().get(SwaggerConst.SUCCESS_KEY); if (successResponse != null) { if (successResponse.getSchema() == null) { // 标注已经定义了response,但是是void,这可能是在标注上未定义 // 根据函数原型来处理response Property property = createResponseProperty(); successResponse.setSchema(property); } return; } } Property property = createResponseProperty(); Response response = new Response(); response.setSchema(property); operation.addResponse(SwaggerConst.SUCCESS_KEY, response); }
private static void generateResponse(Swagger swagger, ResponseConfig responseConfig) { Response response = new Response(); Property property = generateResponseProperty(swagger, responseConfig); response.setSchema(property); response.setDescription(responseConfig.getDescription()); if (responseConfig.getResponseHeaders() != null) { Map<String, Property> headers = generateResponseHeader(swagger, responseConfig.getResponseHeaders()); response.setHeaders(headers); } responseConfig.setResponse(response); }
Map<String, Property> responseHeaders = parseResponseHeaders(apiResponse.responseHeaders()); Class<?> responseClass = apiResponse.response(); Response response = new Response() .description(apiResponse.message()) .headers(responseHeaders);
Property responseProperty = RESPONSE_CONTAINER_CONVERTER.withResponseContainer(responseContainer, property); operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) if (models.isEmpty()) { Property p = ModelConverters.getInstance().readAsProperty(responseClassType); operation.response(responseCode, new Response() .description("successful operation") .schema(p) operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) operation.defaultResponse(new Response().description("successful operation"));
if (property != null) { Property responseProperty = RESPONSE_CONTAINER_CONVERTER.withResponseContainer(responseContainer, property); operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) if (models.isEmpty()) { Property pp = ModelConverters.getInstance().readAsProperty(responseClass); operation.response(responseCode, new Response() .description("successful operation") .schema(pp) operation.response(responseCode, new Response() .description("successful operation") .schema(responseProperty) ResponseStatus responseStatus = findMergedAnnotation(method, ResponseStatus.class); if (responseStatus != null) { operation.response(responseStatus.value().value(), new Response().description(responseStatus.reason())); int code = responseStatus.code().value(); String description = defaultIfEmpty(responseStatus.reason(), responseStatus.code().getReasonPhrase()); operation.response(code, new Response().description(description)); operation.defaultResponse(new Response().description("successful operation"));
String value = annotation.authorizations()[0].value(); if (value != null && !value.isEmpty()) { operation.response(FORBIDDEN.code(), new Response() .schema(new RefProperty("ErrorMessage")) .description(value + " is invalid"));
private Response getDefaultResponse() { Response response = new Response(); response.setDescription("OK"); return response; }
private Response responseOk() { Response res = new Response(); res.setDescription(DESCRIPTION_SUCCESS); return res; }
private Response responseNoContent() { Response res = new Response(); res.setDescription(DESCRIPTION_ERROR); return res; }
private Response getDefaultResponse() { Response response = new Response(); response.setDescription("OK"); return response; }
protected Response getErrorResponse(String msg) { return new Response() .description(msg) .schema(getErrorSchema()); }
private Response responseGenericError() { Response res = new Response(); res.setDescription(DESCRIPTION_ERROR); res.setSchema(refProperty(modelForPodo(ServiceErrorResponse.class))); return res; }
private Response responseOk(Class<?> type) { Response res = new Response(); res.setDescription(DESCRIPTION_SUCCESS); if (type == null) { return res; } res.setSchema(refProperty(modelForPodo(type))); return res; }
private Response responseOk(ServiceDocument template) { Response res = new Response(); res.setDescription(DESCRIPTION_SUCCESS); res.setSchema(refProperty(modelForServiceDocument(template))); return res; }
@Override public Response mToResponse(Framework.Mapping<?> mapping) { return new Response().schema(mToProperty(mapping)) .description(attach(mapping).desc()); }
private static void generateResponse(Swagger swagger, ResponseConfig responseConfig) { Response response = new Response(); Property property = generateResponseProperty(swagger, responseConfig); response.setSchema(property); response.setDescription(responseConfig.getDescription()); if (responseConfig.getResponseHeaders() != null) { Map<String, Property> headers = generateResponseHeader(swagger, responseConfig.getResponseHeaders()); response.setHeaders(headers); } responseConfig.setResponse(response); }
protected Operation generateEntityDeleteOperation(ModelImpl entityModel) { return new Operation() .tag(entityModel.getName()) .produces(APPLICATION_JSON_VALUE) .summary("Deletes the entity: " + entityModel.getName()) .parameter(new PathParameter() .name("entityId") .description("Entity identifier") .required(true) .property(new StringProperty())) .response(200, new Response().description("Success. Entity was deleted.")) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to delete the entity")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); }
protected Operation generateQueryOperation(RestQueriesConfiguration.QueryInfo query, RequestMethod method) { Operation operation = new Operation() .tag(query.getEntityName() + " Queries") .produces(APPLICATION_JSON_VALUE) .summary(query.getName()) .description("Executes a predefined query. Query parameters must be passed in the request body as JSON map.") .response(200, new Response() .description("Success") .schema(new ArrayProperty(new RefProperty(ENTITY_DEFINITION_PREFIX + query.getEntityName())))) .response(403, getErrorResponse("Forbidden. A user doesn't have permissions to read the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); operation.setParameters(generateQueryOpParams(query, method, true)); return operation; }