Search in sources :

Example 31 with QueryParameter

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

the class SwaggerResolverTest method testSharedSwaggerParametersTest.

@Test(description = "resolve top-level parameters")
public void testSharedSwaggerParametersTest() {
    final Swagger swagger = new Swagger();
    swagger.path("/fun", new Path().get(new Operation().parameter(new RefParameter("username")).response(200, new Response().description("ok!"))));
    swagger.parameter("username", new QueryParameter().name("username").property(new StringProperty()));
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    assertTrue(resolved.getParameters().size() == 1);
    assertTrue(resolved.getPaths().get("/fun").getGet().getParameters().size() == 1);
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) Test(org.testng.annotations.Test)

Example 32 with QueryParameter

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

the class SwaggerResolverTest method testSettingsAddParametersToEachOperationDisabled.

@Test
public void testSettingsAddParametersToEachOperationDisabled() {
    String yaml = "---\n" + "swagger: '2.0'\n" + "info:\n" + "  title: test spec\n" + "  version: '1.0'\n" + "paths:\n" + "  \"/test/{id}\":\n" + "    parameters:\n" + "    - name: id\n" + "      in: path\n" + "      type: string\n" + "      required: true\n" + "    get:\n" + "      description: test get\n" + "      parameters:\n" + "      - name: page\n" + "        in: query\n" + "        type: string\n" + "      responses:\n" + "        default:\n" + "          description: test response\n";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    final Swagger resolved = new SwaggerResolver(swagger, null, null, new SwaggerResolver.Settings().addParametersToEachOperation(false)).resolve();
    assertEquals(resolved.getPaths().get("/test/{id}").getParameters().size(), 1);
    PathParameter pp = (PathParameter) resolved.getPaths().get("/test/{id}").getParameters().get(0);
    assertEquals(pp.getName(), "id");
    assertEquals(resolved.getPaths().get("/test/{id}").getGet().getParameters().size(), 1);
    QueryParameter qp = (QueryParameter) resolved.getPaths().get("/test/{id}").getGet().getParameters().get(0);
    assertEquals(qp.getName(), "page");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 33 with QueryParameter

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

the class SwaggerResolverTest method testIssue291.

@Test
public void testIssue291() {
    String json = "{\n" + "  \"swagger\": \"2.0\",\n" + "  \"info\": {\n" + "    \"title\": \"test spec\",\n" + "    \"version\": \"1.0\"\n" + "  },\n" + "  \"parameters\": {\n" + "    \"testParam\": {\n" + "      \"collectionFormat\": \"csv\",\n" + "      \"name\": \"test\",\n" + "      \"in\": \"query\",\n" + "      \"type\": \"array\",\n" + "      \"items\": {\n" + "        \"type\": \"string\"\n" + "      }\n" + "    }\n" + "  },\n" + "  \"paths\": {\n" + "    \"/test\": {\n" + "      \"get\": {\n" + "        \"description\": \"test get\",\n" + "        \"parameters\": [\n" + "          {\n" + "            \"$ref\": \"#/parameters/testParam\"\n" + "          }\n" + "        ],\n" + "        \"responses\": {\n" + "          \"default\": {\n" + "             \"description\": \"test response\"\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(json);
    Swagger swagger = result.getSwagger();
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    Parameter param = resolved.getPaths().get("/test").getGet().getParameters().get(0);
    QueryParameter qp = (QueryParameter) param;
    assertEquals(qp.getCollectionFormat(), "csv");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) Test(org.testng.annotations.Test)

Example 34 with QueryParameter

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

the class DynamicHtmlGenTestCase method testFromParameter.

@Test
public void testFromParameter() throws Exception {
    Parameter parameter = new QueryParameter();
    parameter.setName("query");
    final String description = "Sample parameter description";
    parameter.setDescription(description);
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    CodegenParameter modified = htmlGen.fromParameter(parameter, new HashSet<>());
    Assert.assertEquals(modified.description, description);
}
Also used : CodegenParameter(io.swagger.codegen.CodegenParameter) QueryParameter(io.swagger.models.parameters.QueryParameter) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) CodegenParameter(io.swagger.codegen.CodegenParameter) Test(org.testng.annotations.Test)

Example 35 with QueryParameter

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

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(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.junit.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