io.swagger.util.ReflectionUtils Java Examples
The following examples show how to use
io.swagger.util.ReflectionUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 6 votes |
private static Map<String, Property> parseResponseHeaders(ReaderContext context, ResponseHeader[] headers) { Map<String, Property> responseHeaders = null; for (ResponseHeader header : headers) { final String name = header.name(); if (StringUtils.isNotEmpty(name)) { if (responseHeaders == null) { responseHeaders = new HashMap<String, Property>(); } final Class<?> cls = header.response(); if (!ReflectionUtils.isVoid(cls)) { final Property property = ModelConverters.getInstance().readAsProperty(cls); if (property != null) { final Property responseProperty = ContainerWrapper.wrapContainer( header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET); responseProperty.setDescription(header.description()); responseHeaders.put(name, responseProperty); appendModels(context.getSwagger(), cls); } } } } return responseHeaders; }
Example #2
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 6 votes |
@Override public void applySchemes(ReaderContext context, Operation operation, Method method) { final List<Scheme> schemes = new ArrayList<Scheme>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiOperation != null) { schemes.addAll(parseSchemes(apiOperation.protocols())); } if (schemes.isEmpty() && apiAnnotation != null) { schemes.addAll(parseSchemes(apiAnnotation.protocols())); } for (Scheme scheme : schemes) { operation.scheme(scheme); } }
Example #3
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 6 votes |
private static Map<String, Property> parseResponseHeaders(ReaderContext context, ResponseHeader[] headers) { Map<String, Property> responseHeaders = null; for (ResponseHeader header : headers) { final String name = header.name(); if (StringUtils.isNotEmpty(name)) { if (responseHeaders == null) { responseHeaders = new HashMap<String, Property>(); } final Class<?> cls = header.response(); if (!ReflectionUtils.isVoid(cls)) { final Property property = ModelConverters.getInstance().readAsProperty(cls); if (property != null) { final Property responseProperty = ContainerWrapper.wrapContainer( header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET); responseProperty.setDescription(header.description()); responseHeaders.put(name, responseProperty); appendModels(context.getSwagger(), cls); } } } } return responseHeaders; }
Example #4
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 6 votes |
private static Map<String, Property> parseResponseHeaders(Swagger swagger, ReaderContext context, ResponseHeader[] headers) { Map<String, Property> responseHeaders = null; for (ResponseHeader header : headers) { final String name = header.name(); if (StringUtils.isNotEmpty(name)) { if (responseHeaders == null) { responseHeaders = new HashMap<String, Property>(); } final Class<?> cls = header.response(); if (!ReflectionUtils.isVoid(cls)) { final Property property = ModelConverters.getInstance().readAsProperty(cls); if (property != null) { final Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET); responseProperty.setDescription(header.description()); responseHeaders.put(name, responseProperty); appendModels(swagger, cls); } } } } return responseHeaders; }
Example #5
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 6 votes |
@Override public void applyProduces(ReaderContext context, Operation operation, Method method) { final List<String> produces = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { produces.addAll(parseStringValues(apiOperation.produces())); } if (produces.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { produces.addAll(parseStringValues(apiAnnotation.produces())); } produces.addAll(context.getParentProduces()); } for (String produce : produces) { operation.produces(produce); } }
Example #6
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 6 votes |
@Override public void applyConsumes(ReaderContext context, Operation operation, Method method) { final List<String> consumes = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { consumes.addAll(parseStringValues(apiOperation.consumes())); } if (consumes.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { consumes.addAll(parseStringValues(apiAnnotation.consumes())); } consumes.addAll(context.getParentConsumes()); } for (String consume : consumes) { operation.consumes(consume); } }
Example #7
Source File: Reader.java From proteus with Apache License 2.0 | 6 votes |
protected Parameter readImplicitParam(ApiImplicitParam param) { final Parameter p; if (param.paramType().equalsIgnoreCase("path")) { p = new PathParameter(); } else if (param.paramType().equalsIgnoreCase("query")) { p = new QueryParameter(); } else if (param.paramType().equalsIgnoreCase("form") || param.paramType().equalsIgnoreCase("formData")) { p = new FormParameter(); } else if (param.paramType().equalsIgnoreCase("body")) { p = null; } else if (param.paramType().equalsIgnoreCase("header")) { p = new HeaderParameter(); } else { LOGGER.warn("Unknown implicit parameter type: [{}]", param.paramType()); return null; } final Type type = ReflectionUtils.typeFromString(param.dataType()); return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type, Arrays.<Annotation>asList(param)); }
Example #8
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 6 votes |
public void applyConsumes(ReaderContext context, Operation operation, Method method) { final List<String> consumes = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { consumes.addAll(parseStringValues(apiOperation.consumes())); } if (consumes.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { consumes.addAll(parseStringValues(apiAnnotation.consumes())); } consumes.addAll(context.getParentConsumes()); } for (String consume : consumes) { operation.consumes(consume); } }
Example #9
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 6 votes |
public void applyProduces(ReaderContext context, Operation operation, Method method) { final List<String> produces = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { produces.addAll(parseStringValues(apiOperation.produces())); } if (produces.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { produces.addAll(parseStringValues(apiAnnotation.produces())); } produces.addAll(context.getParentProduces()); } for (String produce : produces) { operation.produces(produce); } }
Example #10
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 6 votes |
public void applySchemes(ReaderContext context, Operation operation, Method method) { final List<Scheme> schemes = new ArrayList<Scheme>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiOperation != null) { schemes.addAll(parseSchemes(apiOperation.protocols())); } if (schemes.isEmpty() && apiAnnotation != null) { schemes.addAll(parseSchemes(apiAnnotation.protocols())); } for (Scheme scheme : schemes) { operation.scheme(scheme); } }
Example #11
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public void applySchemes(ReaderContext context, Operation operation, Method method) { final List<Scheme> schemes = new ArrayList<Scheme>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiOperation != null) { schemes.addAll(parseSchemes(apiOperation.protocols())); } if (schemes.isEmpty() && apiAnnotation != null) { schemes.addAll(parseSchemes(apiAnnotation.protocols())); } for (Scheme scheme : schemes) { operation.scheme(scheme); } }
Example #12
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 6 votes |
public void applySecurityRequirements(ReaderContext context, Operation operation, Method method) { final List<SecurityRequirement> securityRequirements = new ArrayList<SecurityRequirement>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiOperation != null) { securityRequirements.addAll(parseAuthorizations(apiOperation.authorizations())); } if (securityRequirements.isEmpty() && apiAnnotation != null) { securityRequirements.addAll(parseAuthorizations(apiAnnotation.authorizations())); } for (SecurityRequirement securityRequirement : securityRequirements) { operation.security(securityRequirement); } }
Example #13
Source File: ApiImplicitParamProcessor.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Override public Type getGenericType(ApiImplicitParam apiImplicitParam) { Type dataTypeClass = apiImplicitParam.dataTypeClass(); if (ReflectionUtils.isVoid(dataTypeClass)) { if (StringUtils.isEmpty(apiImplicitParam.dataType())) { return null; } dataTypeClass = ReflectionUtils.typeFromString(apiImplicitParam.dataType()); } if ("array".equals(apiImplicitParam.type())) { return Types.arrayOf(dataTypeClass); } return dataTypeClass; }
Example #14
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public void applyProduces(ReaderContext context, Operation operation, Method method) { final List<String> produces = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { produces.addAll(parseStringValues(apiOperation.produces())); } if (produces.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { produces.addAll(parseStringValues(apiAnnotation.produces())); } produces.addAll(context.getParentProduces()); } for (String produce : produces) { operation.produces(produce); } }
Example #15
Source File: RpcReaderExtension.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public void applyConsumes(ReaderContext context, Operation operation, Method method) { final List<String> consumes = new ArrayList<String>(); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null) { consumes.addAll(parseStringValues(apiOperation.consumes())); } if (consumes.isEmpty()) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); if (apiAnnotation != null) { consumes.addAll(parseStringValues(apiAnnotation.consumes())); } consumes.addAll(context.getParentConsumes()); } for (String consume : consumes) { operation.consumes(consume); } }
Example #16
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 5 votes |
public void applyOperationId(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.nickname())) { operation.operationId(apiOperation.nickname()); } else { operation.operationId(method.getName()); } }
Example #17
Source File: ReaderUtils.java From dorado with Apache License 2.0 | 5 votes |
/** * Collects field-level parameters from class. * * @param cls is a class for collecting * @param swagger is the instance of the Swagger * @return the collection of supported parameters */ public static List<Parameter> collectFieldParameters(Class<?> cls, Swagger swagger) { final List<Parameter> parameters = new ArrayList<Parameter>(); for (Field field : ReflectionUtils.getDeclaredFields(cls)) { final List<Annotation> annotations = Arrays.asList(field.getAnnotations()); final Type genericType = field.getGenericType(); for (Parameter parameter : collectParameters(genericType, annotations)) { if (ParameterProcessor.applyAnnotations(swagger, parameter, genericType, annotations) != null) { parameters.add(parameter); } } } return parameters; }
Example #18
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 5 votes |
public String getPath(ReaderContext context, Method method) { final Api apiAnnotation = context.getCls().getAnnotation(Api.class); final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); final String operationPath = apiOperation == null ? null : apiOperation.nickname(); return PathUtils.collectPath(context.getParentPath(), apiAnnotation == null ? null : apiAnnotation.value(), StringUtils.isBlank(operationPath) ? method.getName() : operationPath); }
Example #19
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 5 votes |
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) { final Parameter p = ParameterFactory.createParam(param.paramType()); if (p == null) { return null; } final Type type = ReflectionUtils.typeFromString(param.dataType()); return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type, Collections.<Annotation>singletonList(param)); }
Example #20
Source File: AbstractOperationGenerator.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected Model createResponseModel() { Type responseType = ParamUtils .getGenericParameterType(clazz, method.getDeclaringClass(), method.getGenericReturnType()); if (ReflectionUtils.isVoid(responseType)) { return null; } ResponseTypeProcessor processor = findResponseTypeProcessor(responseType); return processor.process(swaggerGenerator, this, responseType); }
Example #21
Source File: ControllerReaderExtension.java From jboot with Apache License 2.0 | 5 votes |
private static Type getResponseType(Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && !ReflectionUtils.isVoid(apiOperation.response())) { return apiOperation.response(); } else { return method.getGenericReturnType(); } }
Example #22
Source File: DefaultResponseTypeProcessor.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public Model process(SwaggerGenerator swaggerGenerator, OperationGenerator operationGenerator, Type genericResponseType) { Type responseType = extractResponseType(swaggerGenerator, operationGenerator, genericResponseType); if (responseType == null || ReflectionUtils.isVoid(responseType)) { return null; } if (responseType instanceof Class && Part.class.isAssignableFrom((Class<?>) responseType)) { responseType = Part.class; } SwaggerUtils.addDefinitions(swaggerGenerator.getSwagger(), responseType); Property property = ModelConverters.getInstance().readAsProperty(responseType); return new PropertyModelConverter().propertyToModel(property); }
Example #23
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
private Parameter readImplicitParam(Swagger swagger, ApiImplicitParam param) { PrimitiveType fromType = PrimitiveType.fromName(param.paramType()); final Parameter p = null == fromType ? new FormParameter() : new QueryParameter(); final Type type = ReflectionUtils.typeFromString(param.dataType()); return ParameterProcessor.applyAnnotations(swagger, p, type == null ? String.class : type, Collections.<Annotation> singletonList(param)); }
Example #24
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
private static Type getResponseType(Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && !ReflectionUtils.isVoid(apiOperation.response())) { return apiOperation.response(); } else { return method.getGenericReturnType(); } }
Example #25
Source File: ResourceReaderExtension.java From mdw with Apache License 2.0 | 5 votes |
@Override public String getHttpMethod(ReaderContext context, Method method) { ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && apiOperation.httpMethod() != null && !apiOperation.httpMethod().isEmpty()) { return apiOperation.httpMethod(); } else { Class<?> declaringClass = method.getDeclaringClass(); if (declaringClass.getPackage().getName().equals(BASE_REST_PKG)) return null; // JAX-RS annotations GET get = ReflectionUtils.getAnnotation(method, GET.class); if (get != null) return "get"; PUT put = ReflectionUtils.getAnnotation(method, PUT.class); if (put != null) { if (method.getName().equals("patch")) return "patch"; return "put"; } POST post = ReflectionUtils.getAnnotation(method, POST.class); if (post != null) return "post"; DELETE delete = ReflectionUtils.getAnnotation(method, DELETE.class); if (delete != null) return "delete"; // MDW REST if (RestService.class.isAssignableFrom(declaringClass)) return method.getName(); return null; } }
Example #26
Source File: JaxrsReader.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
public static Annotation[][] findParamAnnotations(Method method) { Annotation[][] paramAnnotation = method.getParameterAnnotations(); Method overriddenMethod = ReflectionUtils.getOverriddenMethod(method); while(overriddenMethod != null) { paramAnnotation = merge(overriddenMethod.getParameterAnnotations(), paramAnnotation); overriddenMethod = ReflectionUtils.getOverriddenMethod(overriddenMethod); } return paramAnnotation; }
Example #27
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
@Override public void applyDescription(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.notes())) { operation.description(apiOperation.notes()); } operation.description(operation.getDescription() == null ? outputMethod(method) : (outputMethod(method) + operation.getDescription())); }
Example #28
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
@Override public void applySummary(Operation operation, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); if (apiOperation != null && StringUtils.isNotBlank(apiOperation.value())) { operation.summary(apiOperation.value()); } }
Example #29
Source File: DubboReaderExtension.java From swagger-dubbo with Apache License 2.0 | 5 votes |
@Override public String getPath(ReaderContext context, Method method) { final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); String operationId = null == apiOperation ? "" : StringUtils.isBlank(apiOperation.nickname()) ? null : apiOperation.nickname(); return PathUtils.collectPath(context.getParentPath(), context.getInterfaceCls().getName(), method.getName(), operationId); }
Example #30
Source File: Reader.java From dorado with Apache License 2.0 | 5 votes |
private void readExternalDocs(Method method, Operation operation) { io.swagger.annotations.ExternalDocs externalDocs = ReflectionUtils.getAnnotation(method, io.swagger.annotations.ExternalDocs.class); if (externalDocs != null) { operation.setExternalDocs(new ExternalDocs(externalDocs.value(), externalDocs.url())); } }