Java Code Examples for io.swagger.models.properties.Property#setDescription()

The following examples show how to use io.swagger.models.properties.Property#setDescription() . 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 vote down vote up
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 vote down vote up
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 3
Source File: ControllerReaderExtension.java    From jboot with Apache License 2.0 6 votes vote down vote up
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 4
Source File: Reader.java    From dorado with Apache License 2.0 5 votes vote down vote up
private Map<String, Property> parseResponseHeaders(ResponseHeader[] headers, JsonView jsonView) {
	Map<String, Property> responseHeaders = null;
	if (headers != null) {
		for (ResponseHeader header : headers) {
			String name = header.name();
			if (!"".equals(name)) {
				if (responseHeaders == null) {
					responseHeaders = new LinkedHashMap<String, Property>();
				}
				String description = header.description();
				Class<?> cls = header.response();

				if (!isVoid(cls)) {
					final Property property = ModelConverters.getInstance().readAsProperty(cls, jsonView);
					if (property != null) {
						Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(),
								property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
						responseProperty.setDescription(description);
						responseHeaders.put(name, responseProperty);
						appendModels(cls);
					}
				}
			}
		}
	}
	return responseHeaders;
}
 
Example 5
Source File: Reader.java    From proteus with Apache License 2.0 5 votes vote down vote up
private Map<String, Property> parseResponseHeaders(ResponseHeader[] headers) {
    Map<String, Property> responseHeaders = null;
    if (headers != null) {
        for (ResponseHeader header : headers) {
            String name = header.name();
            if (!"".equals(name)) {
                if (responseHeaders == null) {
                    responseHeaders = new LinkedHashMap<>();
                }
                String description = header.description();
                Class<?> cls = header.response();

                if (!isVoid(cls)) {
                    final Property property = ModelConverters.getInstance().readAsProperty(cls);
                    if (property != null) {
                        Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(), property,
                                ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
                        responseProperty.setDescription(description);
                        responseHeaders.put(name, responseProperty);
                        appendModels(cls);
                    }
                }
            }
        }
    }
    return responseHeaders;
}
 
Example 6
Source File: ParameterDiff.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
private Property mapToProperty(Parameter rightPara) {
    Property prop = new StringProperty();
    prop.setAccess(rightPara.getAccess());
    prop.setAllowEmptyValue(rightPara.getAllowEmptyValue());
    prop.setDescription(rightPara.getDescription());
    prop.setName(rightPara.getName());
    prop.setReadOnly(rightPara.isReadOnly());
    prop.setRequired(rightPara.getRequired());
    return prop;
}
 
Example 7
Source File: ExtendedSwaggerReader.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private Map<String, Property> parseResponseHeaders(ResponseHeader[] headers) {
    Map<String, Property> responseHeaders = null;
    if (headers != null && headers.length > 0) {
        for (ResponseHeader header : headers) {
            String name = header.name();
            if (!"".equals(name)) {
                if (responseHeaders == null) {
                    responseHeaders = new HashMap<>();
                }
                String description = header.description();
                Class<?> cls = header.response();

                if (!isVoid(cls)) {
                    final Property property = ModelConverters.getInstance().readAsProperty(cls);
                    if (property != null) {
                        Property responseProperty = ContainerWrapper
                                .wrapContainer(header.responseContainer(), property, ContainerWrapper.ARRAY,
                                               ContainerWrapper.LIST, ContainerWrapper.SET);
                        responseProperty.setDescription(description);
                        responseHeaders.put(name, responseProperty);
                        appendModels(cls);
                    }
                }
            }
        }
    }
    return responseHeaders;
}
 
Example 8
Source File: TestSchemaFieldInterceptor.java    From spring-openapi with MIT License 4 votes vote down vote up
@Override
public void intercept(Class<?> clazz, Field field, Property transformedFieldSchema) {
	transformedFieldSchema.setDescription(TestUtils.emptyIfNull(transformedFieldSchema.getDescription()) + ". Test schemaField interceptor");
}
 
Example 9
Source File: PojoOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private void wrapParametersToBody(List<ParameterGenerator> bodyFields) {
  String simpleRef = MethodUtils.findSwaggerMethodName(method) + "Body";

  bodyModel = new ModelImpl();
  bodyModel.setType(ModelImpl.OBJECT);
  for (ParameterGenerator parameterGenerator : bodyFields) {
    // to collect all information by swagger mechanism
    // must have a parameter type
    // but all these parameters will be wrap to be one body parameter, their parameter type must be null
    // so we first set to be BODY, after collected, set back to be null
    parameterGenerator.setHttpParameterType(HttpParameterType.BODY);
    scanMethodParameter(parameterGenerator);

    Property property = ModelConverters.getInstance().readAsProperty(parameterGenerator.getGenericType());
    property.setDescription(parameterGenerator.getGeneratedParameter().getDescription());
    bodyModel.addProperty(parameterGenerator.getParameterName(), property);

    parameterGenerator.setHttpParameterType(null);
  }
  swagger.addDefinition(simpleRef, bodyModel);

  SwaggerGeneratorFeature feature = swaggerGenerator.getSwaggerGeneratorFeature();
  // bodyFields.size() > 1 is no reason, just because old version do this......
  // if not care for this, then can just delete all logic about EXT_JAVA_CLASS/EXT_JAVA_INTF
  if (feature.isExtJavaClassInVendor()
      && bodyFields.size() > 1
      && StringUtils.isNotEmpty(feature.getPackageName())) {
    bodyModel.getVendorExtensions().put(SwaggerConst.EXT_JAVA_CLASS, feature.getPackageName() + "." + simpleRef);
  }

  RefModel refModel = new RefModel();
  refModel.setReference("#/definitions/" + simpleRef);

  bodyParameter = new BodyParameter();
  bodyParameter.name(simpleRef);
  bodyParameter.setSchema(refModel);
  bodyParameter.setName(parameterGenerators.size() == 1 ? parameterGenerators.get(0).getParameterName() : simpleRef);

  List<ParameterGenerator> newParameterGenerators = new ArrayList<>();
  newParameterGenerators.add(new ParameterGenerator(
      bodyParameter.getName(),
      Collections.emptyList(),
      null,
      HttpParameterType.BODY,
      bodyParameter));
  parameterGenerators.stream().filter(p -> p.getHttpParameterType() != null)
      .forEach(p -> newParameterGenerators.add(p));
  parameterGenerators = newParameterGenerators;
}