Java Code Examples for io.swagger.models.parameters.BodyParameter#setName()

The following examples show how to use io.swagger.models.parameters.BodyParameter#setName() . 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: OperationsTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
private io.swagger.models.parameters.Parameter createStandardRequestBody(Method method, ParameterNamePair requestBodyParameter, ModelImpl content,
																		 Property property) {
	BodyParameter requestBody = new BodyParameter();
	requestBody.setSchema(content);
	requestBody.setRequired(true);
	requestBody.setName(resolveRequestBodyName(property, requestBodyParameter.getName()));
	requestBody.setDescription(requestBody.getName());

	requestBodyInterceptors.forEach(interceptor ->
											interceptor.intercept(method, requestBodyParameter.getParameter(), requestBodyParameter.getName(), requestBody)
	);

	return requestBody;
}
 
Example 2
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;
}