Search in sources :

Example 66 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.

the class OperationGenerator method processBodyBasedParameter.

protected void processBodyBasedParameter() {
    List<BodyParameter> bodyParameters = collectBodyBasedParameters();
    if (bodyParameters.isEmpty()) {
        return;
    }
    if (bodyParameters.size() == 1) {
        Parameter bodyParameter = bodyParameters.get(0);
        replaceBodyBasedParameter(bodyParameter);
        return;
    }
    // 将多个pending合并成一个body
    mergeBodyBasedParameters(bodyParameters);
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter) PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter)

Example 67 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.

the class OperationGenerator method mergeBodyBasedParameters.

protected void mergeBodyBasedParameters(List<BodyParameter> bodyParameters) {
    for (Parameter parameter : bodyParameters) {
        swaggerParameters.remove(parameter);
    }
    // 将这些body包装为一个class,整体做为一个body参数
    String bodyParamName = ParamUtils.generateBodyParameterName(providerMethod);
    Class<?> cls = ClassUtils.getOrCreateBodyClass(this, bodyParameters);
    BodyParameter bodyParameter = ParamUtils.createBodyParameter(swagger, bodyParamName, cls);
    swaggerParameters.add(bodyParameter);
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) ContextParameter(io.servicecomb.swagger.extend.parameter.ContextParameter) PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) BodyParameter(io.swagger.models.parameters.BodyParameter)

Example 68 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project carbon-apimgt by wso2.

the class APIDefinitionFromSwagger20 method getDefaultBodyParameter.

private BodyParameter getDefaultBodyParameter() {
    BodyParameter bodyParameter = new BodyParameter();
    bodyParameter.setName("Payload");
    bodyParameter.setDescription("Request Body");
    bodyParameter.setRequired(false);
    Model model = new ModelImpl();
    Map<String, Property> properties = new HashMap<>();
    Property property = new StringProperty();
    properties.put("payload", property);
    model.setProperties(properties);
    bodyParameter.setSchema(model);
    return bodyParameter;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) BodyParameter(io.swagger.models.parameters.BodyParameter) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) Property(io.swagger.models.properties.Property)

Example 69 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project minijax by minijax.

the class ScannerTest method scanBeanParamResource.

@Test
public void scanBeanParamResource() {
    final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
    final List<Parameter> params = getParameters(swagger, "/bean/{id}");
    final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
    assertEquals(1, headerParam1.getDefaultValue());
    assertEquals("test order annotation 1", headerParam1.getName());
    final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
    assertEquals(2, headerParam2.getDefaultValue());
    assertEquals("test order annotation 2", headerParam2.getName());
    final QueryParameter priority1 = (QueryParameter) params.get(2);
    assertNull(priority1.getDefaultValue());
    assertEquals("test priority 1", priority1.getName());
    final QueryParameter priority2 = (QueryParameter) params.get(3);
    assertEquals(4, priority2.getDefaultValue());
    assertEquals("test priority 2", priority2.getName());
    final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
    assertEquals("bodyParam", bodyParam1.getDefaultValue());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test)

Example 70 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project incubator-servicecomb-java-chassis by apache.

the class RequestBodyAnnotationProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator, int paramIdx) {
    BodyParameter bodyParameter = ParamUtils.createBodyParameter(operationGenerator, paramIdx);
    operationGenerator.addProviderParameter(bodyParameter);
}
Also used : BodyParameter(io.swagger.models.parameters.BodyParameter)

Aggregations

BodyParameter (io.swagger.models.parameters.BodyParameter)96 Test (org.testng.annotations.Test)42 Parameter (io.swagger.models.parameters.Parameter)34 Model (io.swagger.models.Model)30 Operation (io.swagger.models.Operation)28 QueryParameter (io.swagger.models.parameters.QueryParameter)26 ModelImpl (io.swagger.models.ModelImpl)23 Swagger (io.swagger.models.Swagger)23 PathParameter (io.swagger.models.parameters.PathParameter)23 RefModel (io.swagger.models.RefModel)22 ArrayModel (io.swagger.models.ArrayModel)21 Property (io.swagger.models.properties.Property)21 Path (io.swagger.models.Path)20 RefProperty (io.swagger.models.properties.RefProperty)19 StringProperty (io.swagger.models.properties.StringProperty)18 ArrayProperty (io.swagger.models.properties.ArrayProperty)13 HeaderParameter (io.swagger.models.parameters.HeaderParameter)12 Response (io.swagger.models.Response)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 ArrayList (java.util.ArrayList)9