Search in sources :

Example 56 with ModelImpl

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

the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelElementForWSDLOperationElement.

@Test
public void testGetSwaggerModelElementForWSDLOperationElement() throws Exception {
    List<ModelImpl> inputParameterModel = operations.iterator().next().getInputParameterModel();
    Assert.assertEquals(1, operations.iterator().next().getOutputParameterModel().size());
    for (ModelImpl model : inputParameterModel) {
        Assert.assertTrue("CheckPhoneNumbers".equals(model.getName()) || "CheckPhoneNumber".equals(model.getName()));
    }
}
Also used : ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 57 with ModelImpl

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

the class TestApiOperation method testMap.

private void testMap(Path path) {
    Operation operation = path.getPost();
    Model result200 = operation.getResponses().get("200").getResponseSchema();
    Assert.assertEquals(ModelImpl.class, result200.getClass());
    Assert.assertTrue(((ModelImpl) result200).getAdditionalProperties() != null);
}
Also used : Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation) ModelImpl(io.swagger.models.ModelImpl)

Example 58 with ModelImpl

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

the class TestApiOperation method testPrimitive.

private void testPrimitive(Path path) {
    Operation operation = path.getPost();
    Assert.assertEquals(2, operation.getResponses().size());
    ModelImpl result200 = (ModelImpl) operation.getResponses().get("200").getResponseSchema();
    Assert.assertEquals("integer", result200.getType());
    Assert.assertEquals("int32", result200.getFormat());
    ModelImpl result202 = (ModelImpl) operation.getResponses().get("202").getResponseSchema();
    Assert.assertEquals("string", result202.getType());
    Assert.assertEquals(null, result202.getFormat());
}
Also used : ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.models.Operation) ModelImpl(io.swagger.models.ModelImpl)

Example 59 with ModelImpl

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

the class AbstractOperationGenerator method fillBodyParameter.

protected void fillBodyParameter(Swagger swagger, Parameter parameter, Type type, List<Annotation> annotations) {
    // so strange, for bodyParameter, swagger return a new instance
    // that will cause lost some information
    // so we must merge them
    BodyParameter newBodyParameter = (BodyParameter) io.swagger.util.ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations);
    // swagger missed enum data, fix it
    ModelImpl model = SwaggerUtils.getModelImpl(swagger, newBodyParameter);
    if (model != null) {
        Property property = ModelConverters.getInstance().readAsProperty(type);
        if (property instanceof StringProperty) {
            model.setEnum(((StringProperty) property).getEnum());
        }
    }
    // swagger 2.0 do not support NotBlank and NotEmpty annotations, fix it
    if (((JavaType) type).getBindings().getTypeParameters().isEmpty()) {
        convertAnnotationProperty(((JavaType) type).getRawClass());
    } else {
        ((JavaType) type).getBindings().getTypeParameters().stream().forEach(javaType -> convertAnnotationProperty(javaType.getRawClass()));
    }
    mergeBodyParameter((BodyParameter) parameter, newBodyParameter);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) 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 60 with ModelImpl

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

the class ModelResolverExt method resolve.

@Override
public Model resolve(JavaType type, ModelConverterContext context, Iterator<ModelConverter> next) {
    // property is not a model
    if (propertyCreatorMap.containsKey(type.getRawClass())) {
        return null;
    }
    Model model = super.resolve(type, context, next);
    if (model == null) {
        return null;
    }
    checkType(type);
    // 只有声明model的地方才需要标注类型
    if (model instanceof ModelImpl && !StringUtils.isEmpty(((ModelImpl) model).getName())) {
        setType(type, model.getVendorExtensions());
    }
    return model;
}
Also used : Model(io.swagger.models.Model) ModelImpl(io.swagger.models.ModelImpl)

Aggregations

ModelImpl (io.swagger.models.ModelImpl)112 Test (org.testng.annotations.Test)46 Model (io.swagger.models.Model)43 Property (io.swagger.models.properties.Property)40 StringProperty (io.swagger.models.properties.StringProperty)32 RefProperty (io.swagger.models.properties.RefProperty)29 BodyParameter (io.swagger.models.parameters.BodyParameter)28 ArrayProperty (io.swagger.models.properties.ArrayProperty)27 RefModel (io.swagger.models.RefModel)24 IntegerProperty (io.swagger.models.properties.IntegerProperty)18 Swagger (io.swagger.models.Swagger)16 JavaType (com.fasterxml.jackson.databind.JavaType)15 Map (java.util.Map)15 MapProperty (io.swagger.models.properties.MapProperty)14 Test (org.junit.Test)14 Parameter (io.swagger.models.parameters.Parameter)12 HashMap (java.util.HashMap)12 ArrayModel (io.swagger.models.ArrayModel)11 ComposedModel (io.swagger.models.ComposedModel)11 ArrayList (java.util.ArrayList)11