Search in sources :

Example 61 with Property

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

the class ClassUtils method getOrCreateClass.

// 获取modelImpl对应的class
public static Class<?> getOrCreateClass(ClassLoader classLoader, String packageName, Swagger swagger, ModelImpl modelImpl, String clsName) {
    Class<?> cls = getClassByName(classLoader, clsName);
    if (cls != null) {
        return cls;
    }
    ClassConfig classConfig = new ClassConfig();
    classConfig.setClassName(clsName);
    for (Entry<String, Property> entry : modelImpl.getProperties().entrySet()) {
        JavaType propertyJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, entry.getValue());
        classConfig.addField(entry.getKey(), propertyJavaType);
    }
    cls = JavassistUtils.createClass(classConfig);
    return cls;
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) ClassConfig(io.servicecomb.common.javassist.ClassConfig) Property(io.swagger.models.properties.Property)

Example 62 with Property

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

the class OperationGenerator method scanResponse.

public void scanResponse() {
    if (operation.getResponses() != null) {
        Response successResponse = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
        if (successResponse != null) {
            if (successResponse.getSchema() == null) {
                // 标注已经定义了response,但是是void,这可能是在标注上未定义
                // 根据函数原型来处理response
                Property property = createResponseProperty();
                successResponse.setSchema(property);
            }
            return;
        }
    }
    Property property = createResponseProperty();
    Response response = new Response();
    response.setSchema(property);
    operation.addResponse(SwaggerConst.SUCCESS_KEY, response);
}
Also used : Response(io.swagger.models.Response) Property(io.swagger.models.properties.Property)

Example 63 with Property

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

the class ParamUtils method createPendingBodyParameter.

public static PendingBodyParameter createPendingBodyParameter(OperationGenerator operationGenerator, String paramName, Type paramType) {
    addDefinitions(operationGenerator.getSwagger(), paramType);
    Property property = ModelConverters.getInstance().readAsProperty(paramType);
    PendingBodyParameter pendingBodyParameter = new PendingBodyParameter();
    pendingBodyParameter.setName(paramName);
    pendingBodyParameter.setProperty(property);
    pendingBodyParameter.setType(paramType);
    pendingBodyParameter.setOperationGenerator(operationGenerator);
    return pendingBodyParameter;
}
Also used : PendingBodyParameter(io.servicecomb.swagger.extend.parameter.PendingBodyParameter) MapProperty(com.fasterxml.jackson.databind.ser.std.MapProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property)

Example 64 with Property

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

the class TestApiResponse method checkApiResponseHeader.

private void checkApiResponseHeader(SwaggerGenerator generator) {
    Swagger swagger = generator.getSwagger();
    Path path = swagger.getPaths().get("/testApiResponseHeader");
    Operation operation = path.getOperations().get(0);
    Assert.assertEquals("testApiResponseHeader", operation.getOperationId());
    Response response = operation.getResponses().get("200");
    Property property = response.getHeaders().get("k1");
    Assert.assertEquals(Integer.class, ConverterMgr.findJavaType(generator, property).getRawClass());
    property = response.getHeaders().get("k2");
    Assert.assertEquals(String.class, ConverterMgr.findJavaType(generator, property).getRawClass());
}
Also used : Path(io.swagger.models.Path) Response(io.swagger.models.Response) ApiResponse(io.swagger.annotations.ApiResponse) Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Property(io.swagger.models.properties.Property)

Example 65 with Property

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

the class ResponseMeta method init.

public void init(ClassLoader classLoader, String packageName, Swagger swagger, Response response) {
    if (javaType == null) {
        Property property = response.getSchema();
        javaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, property);
    }
    if (response.getHeaders() == null) {
        return;
    }
    for (Entry<String, Property> entry : response.getHeaders().entrySet()) {
        JavaType headerJavaType = ConverterMgr.findJavaType(classLoader, packageName, swagger, entry.getValue());
        headers.put(entry.getKey(), headerJavaType);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) Property(io.swagger.models.properties.Property)

Aggregations

Property (io.swagger.models.properties.Property)145 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)86 StringProperty (io.swagger.models.properties.StringProperty)75 RefProperty (io.swagger.models.properties.RefProperty)65 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)52 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)17 Response (io.swagger.models.Response)16