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);
}
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");
}
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");
}
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);
}
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));
}
Aggregations