Search in sources :

Example 81 with ModelImpl

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

the class ModelImplConverter method doConvert.

@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object model) {
    ModelImpl modelImpl = (ModelImpl) model;
    JavaType javaType = ConverterMgr.findJavaType(modelImpl.getType(), modelImpl.getFormat());
    if (javaType != null) {
        return javaType;
    }
    if (modelImpl.getReference() != null) {
        return ConverterMgr.findByRef(classLoader, packageName, swagger, modelImpl.getReference());
    }
    // 根据name、property动态生成class
    if (packageName == null) {
        throw new Error("packageName should not be null");
    }
    String clsName = packageName + "." + modelImpl.getName();
    Class<?> cls = ClassUtils.getOrCreateClass(classLoader, packageName, swagger, modelImpl, clsName);
    return TypeFactory.defaultInstance().constructType(cls);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ModelImpl(io.swagger.models.ModelImpl)

Example 82 with ModelImpl

use of io.swagger.models.ModelImpl 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 83 with ModelImpl

use of io.swagger.models.ModelImpl 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 84 with ModelImpl

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

the class PendingBodyParameter method toRefModel.

// swagger中的body只能是ref,不能是简单类型
private RefModel toRefModel(String modelType) {
    if (RefProperty.class.isInstance(property)) {
        return (RefModel) PropertyBuilder.toModel(property);
    }
    ModelImpl modelImpl = new ModelImpl();
    modelImpl.setType("object");
    modelImpl.setName(name);
    modelImpl.addProperty(name, property);
    operationGenerator.getSwagger().addDefinition(modelType, modelImpl);
    RefModel refModel = new RefModel();
    refModel.setReference("#/definitions/" + modelType);
    return refModel;
}
Also used : RefModel(io.swagger.models.RefModel) ModelImpl(io.swagger.models.ModelImpl)

Example 85 with ModelImpl

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

the class ModelImplConverter method doConvert.

@Override
public JavaType doConvert(ClassLoader classLoader, String packageName, Swagger swagger, Object model) {
    ModelImpl modelImpl = (ModelImpl) model;
    JavaType javaType = ConverterMgr.findJavaType(modelImpl.getType(), modelImpl.getFormat());
    if (javaType != null) {
        return javaType;
    }
    if (modelImpl.getReference() != null) {
        return ConverterMgr.findByRef(classLoader, packageName, swagger, modelImpl.getReference());
    }
    if (modelImpl.getAdditionalProperties() != null) {
        return MapPropertyConverter.findJavaType(classLoader, packageName, swagger, modelImpl.getAdditionalProperties());
    }
    if (ObjectProperty.TYPE.equals(modelImpl.getType()) && modelImpl.getProperties() == null && modelImpl.getName() == null) {
        return TypeFactory.defaultInstance().constructType(Object.class);
    }
    return getOrCreateType(classLoader, packageName, swagger, modelImpl);
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) 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