Search in sources :

Example 1 with QueryParameter

use of io.swagger.models.parameters.QueryParameter 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 QueryParameter

use of io.swagger.models.parameters.QueryParameter 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 3 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ScannerTest method scanBeanParamResource.

@Test(description = "scan a bean param resource")
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(headerParam1.getDefaultValue(), 1);
    assertEquals(headerParam1.getName(), "test order annotation 1");
    final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
    assertEquals(headerParam2.getDefaultValue(), 2);
    assertEquals(headerParam2.getName(), "test order annotation 2");
    final QueryParameter priority1 = (QueryParameter) params.get(2);
    assertNull(priority1.getDefaultValue());
    assertEquals(priority1.getName(), "test priority 1");
    final QueryParameter priority2 = (QueryParameter) params.get(3);
    assertEquals(priority2.getDefaultValue(), 4);
    assertEquals(priority2.getName(), "test priority 2");
    final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
    assertEquals(bodyParam1.getDefaultValue(), "bodyParam");
}
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.testng.annotations.Test)

Example 4 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ReaderTest method scanBeanValidation.

@Test(description = "it should scan parameters with Swagger and JSR-303 bean validation annotations")
public void scanBeanValidation() {
    Swagger swagger = getSwagger(ResourceWithValidation.class);
    assertNotNull(swagger);
    QueryParameter par = (QueryParameter) swagger.getPaths().get("/303").getOperations().get(0).getParameters().get(0);
    assertTrue(par.getRequired());
    assertEquals(par.getMinimum(), new BigDecimal(10));
    par = (QueryParameter) swagger.getPaths().get("/swagger-and-303").getOperations().get(0).getParameters().get(0);
    assertTrue(par.getRequired());
    assertEquals(par.getMinimum(), new BigDecimal(7));
    par = (QueryParameter) swagger.getPaths().get("/swagger").getOperations().get(0).getParameters().get(0);
    assertTrue(par.getRequired());
    assertEquals(par.getMinimum(), new BigDecimal(7));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 5 with QueryParameter

use of io.swagger.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class SimpleReaderTest method scanClassWithImplicitExampleQuery.

@Test(description = "scan a resource with implicit operation query example")
public void scanClassWithImplicitExampleQuery() {
    Swagger swagger = getSwagger(ClassWithExamplePost.class);
    Parameter param = swagger.getPaths().get("/external/info2").getGet().getParameters().get(0);
    QueryParameter bp = (QueryParameter) param;
    assertNotNull(bp.getExample());
    Object value = bp.getExample();
    assertEquals("77", value);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Aggregations

QueryParameter (io.swagger.models.parameters.QueryParameter)88 Test (org.testng.annotations.Test)58 Parameter (io.swagger.models.parameters.Parameter)41 PathParameter (io.swagger.models.parameters.PathParameter)34 BodyParameter (io.swagger.models.parameters.BodyParameter)28 Swagger (io.swagger.models.Swagger)25 HeaderParameter (io.swagger.models.parameters.HeaderParameter)15 Operation (io.swagger.models.Operation)11 FormParameter (io.swagger.models.parameters.FormParameter)11 Test (org.junit.Test)11 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 StringProperty (io.swagger.models.properties.StringProperty)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 Type (java.lang.reflect.Type)9 BigDecimal (java.math.BigDecimal)9 HashMap (java.util.HashMap)9 RefProperty (io.swagger.models.properties.RefProperty)8 Response (io.swagger.models.Response)7 Method (java.lang.reflect.Method)7