Search in sources :

Example 1 with Parameter

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

the class TestPath method testQueryVarParamWriter.

@Test
public void testQueryVarParamWriter() throws Exception {
    boolean status = true;
    new MockUp<RestParam>() {

        @Mock
        public String getParamName() {
            return "queryVar";
        }
    };
    new MockUp<QueryVarParamWriter>() {

        @Mock
        protected Object getParamValue(Object[] args) {
            return args[0];
        }
    };
    Parameter parameter = new QueryParameter();
    QueryVarParamWriter writer = new QueryVarParamWriter('&', new RestParam(0, parameter, String.class));
    try {
        verify(writer, "T", "&queryVar=T");
        verify(writer, null, "&");
        verify(writer, new String[] { "a", "b" }, "&queryVar=a&queryVar=b");
        verify(writer, new String[] { "a", null, "b" }, "&queryVar=a&queryVar=&queryVar=b");
        verify(writer, Arrays.asList("Lars", "Simon"), "&queryVar=Lars&queryVar=Simon");
        verify(writer, "测试", "&queryVar=%E6%B5%8B%E8%AF%95");
        verify(writer, "a b", "&queryVar=a+b");
        verify(writer, "a+b", "&queryVar=a%2Bb");
    } catch (Exception e) {
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) QueryVarParamWriter(io.servicecomb.common.rest.definition.path.QueryVarParamWriter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 2 with Parameter

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

the class TestRestCodec method beforeClass.

@BeforeClass
public static void beforeClass() {
    restOperation = Mockito.mock(RestOperationMeta.class);
    //        clientRequest = Mockito.mock(RestClientRequest.class);
    paramList = new ArrayList<>();
    Parameter hp = new HeaderParameter();
    hp.setName("header");
    paramList.add(new RestParam(0, hp, int.class));
    when(restOperation.getParamList()).thenReturn(paramList);
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Parameter(io.swagger.models.parameters.Parameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) RestParam(io.servicecomb.common.rest.definition.RestParam) BeforeClass(org.junit.BeforeClass)

Example 3 with Parameter

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

the class TestPath method testUrlPathBuilder.

@Test
public void testUrlPathBuilder() throws Exception {
    Map<String, RestParam> paramMap = new HashMap<>();
    Parameter pathParameter = new PathParameter();
    pathParameter.setName("id");
    RestParam oRestParam = new RestParam(0, pathParameter, int.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    Parameter queryParameter = new QueryParameter();
    queryParameter.setName("q");
    oRestParam = new RestParam(1, queryParameter, String.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
    Object[] args = new Object[] { 100, "query" };
    Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(args));
    Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(args));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HashMap(java.util.HashMap) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) URLPathBuilder(io.servicecomb.common.rest.definition.path.URLPathBuilder) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.junit.Test)

Example 4 with Parameter

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

the class ProducerSchemaFactory method connectToProvider.

@Override
protected void connectToProvider(ProducerSchemaContext context) {
    if (context.getGenerator() == null) {
        generateSwagger(context);
    }
    // 建立契约与producer之间的参数映射关系
    Class<?> swaggerIntf = ClassUtils.getJavaInterface(context.getSchemaMeta().getSwagger());
    for (OperationMeta operationMeta : context.getSchemaMeta().getOperations()) {
        OperationGenerator operationGenerator = context.getGenerator().getOperationGeneratorMap().get(operationMeta.getOperationId());
        Method swaggerMethod = ReflectUtils.findMethod(swaggerIntf, operationMeta.getOperationId());
        List<Parameter> swaggerParameters = operationMeta.getSwaggerOperation().getParameters();
        Method producerMethod = operationGenerator.getProviderMethod();
        List<Parameter> producerParameters = operationGenerator.getProviderParameters();
        ProducerArgumentsMapper argsMapper = producerArgsMapperFactory.createArgumentsMapper(context.getSchemaMeta().getSwagger(), swaggerMethod, swaggerParameters, producerMethod, producerParameters);
        createOperation(context, operationMeta, argsMapper);
    }
}
Also used : ProducerArgumentsMapper(io.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapper) Parameter(io.swagger.models.parameters.Parameter) OperationMeta(io.servicecomb.core.definition.OperationMeta) Method(java.lang.reflect.Method) OperationGenerator(io.servicecomb.swagger.generator.core.OperationGenerator)

Example 5 with Parameter

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

the class AnnotationUtils method createParameter.

public static Parameter createParameter(Swagger swagger, ApiImplicitParam paramAnnotation) {
    Parameter parameter = createParameterInstance(paramAnnotation);
    Type dataType = ReflectionUtils.typeFromString(paramAnnotation.dataType());
    parameter = ParameterProcessor.applyAnnotations(swagger, parameter, dataType, Arrays.asList(paramAnnotation));
    return parameter;
}
Also used : Type(java.lang.reflect.Type) HeaderParameter(io.swagger.models.parameters.HeaderParameter) CookieParameter(io.swagger.models.parameters.CookieParameter) FormParameter(io.swagger.models.parameters.FormParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter)

Aggregations

Parameter (io.swagger.models.parameters.Parameter)186 BodyParameter (io.swagger.models.parameters.BodyParameter)102 QueryParameter (io.swagger.models.parameters.QueryParameter)101 PathParameter (io.swagger.models.parameters.PathParameter)89 Test (org.testng.annotations.Test)80 HeaderParameter (io.swagger.models.parameters.HeaderParameter)66 Swagger (io.swagger.models.Swagger)63 FormParameter (io.swagger.models.parameters.FormParameter)52 Operation (io.swagger.models.Operation)31 SerializableParameter (io.swagger.models.parameters.SerializableParameter)29 Test (org.junit.Test)25 Type (java.lang.reflect.Type)23 ArrayList (java.util.ArrayList)23 Path (io.swagger.models.Path)19 Annotation (java.lang.annotation.Annotation)17 JavaType (com.fasterxml.jackson.databind.JavaType)14 Response (io.swagger.models.Response)14 Method (java.lang.reflect.Method)14 Property (io.swagger.models.properties.Property)13 ModelImpl (io.swagger.models.ModelImpl)12