use of io.swagger.models.parameters.PathParameter in project swagger-parser by swagger-api.
the class SwaggerParserTest method testIssue339.
@Test
public void testIssue339() throws Exception {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/issue-339.json");
Parameter param = swagger.getPath("/store/order/{orderId}").getGet().getParameters().get(0);
assertTrue(param instanceof PathParameter);
PathParameter pp = (PathParameter) param;
assertTrue(pp.getMinimum().toString().equals("1"));
assertTrue(pp.getMaximum().toString().equals("5"));
}
use of io.swagger.models.parameters.PathParameter in project swagger-parser by swagger-api.
the class SwaggerReaderTest method testIssue192.
@Test
public void testIssue192() {
String spec = "swagger: '2.0'\n" + "info:\n" + " title: issue 192\n" + "paths:\n" + " /foo:\n" + " get:\n" + " parameters:\n" + " - name: Code\n" + " in: path\n" + " description: The code\n" + " required: true\n" + " type: string\n" + " minLength: 4\n" + " maxLength: 5\n" + " pattern: '^[a-zA-Z]'\n" + " responses:\n" + " 200:\n" + " description: 'the pet'";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
Swagger swagger = result.getSwagger();
Parameter param = swagger.getPath("/foo").getGet().getParameters().get(0);
assertTrue(param instanceof PathParameter);
PathParameter pathParameter = (PathParameter) param;
assertEquals(pathParameter.getMinLength(), new Integer(4));
assertEquals(pathParameter.getMaxLength(), new Integer(5));
assertNull(pathParameter.isReadOnly());
assertEquals(pathParameter.getPattern(), "^[a-zA-Z]");
}
use of io.swagger.models.parameters.PathParameter in project swagger-parser by swagger-api.
the class SwaggerReaderTest method testIssue364.
@Test
public void testIssue364() {
String spec = "swagger: '2.0'\n" + "info:\n" + " title: issue 192\n" + "paths:\n" + " /foo:\n" + " get:\n" + " parameters:\n" + " - name: Code\n" + " in: query\n" + " description: The code\n" + " required: true\n" + " readOnly: true\n" + " allowEmptyValue: true\n" + " responses:\n" + " 200:\n" + " description: 'the pet'";
SwaggerDeserializationResult result = new SwaggerParser().readWithInfo(spec);
Swagger swagger = result.getSwagger();
Parameter param = swagger.getPath("/foo").getGet().getParameters().get(0);
assertTrue(param instanceof QueryParameter);
QueryParameter pathParameter = (QueryParameter) param;
assertTrue(pathParameter.isReadOnly());
assertTrue(pathParameter.getAllowEmptyValue());
}
use of io.swagger.models.parameters.PathParameter 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.PathParameter in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method getParameters.
public static List<Parameter> getParameters(String uriTemplate) {
List<Parameter> parameters = new ArrayList<>();
StringTokenizer stringTokenizer = new StringTokenizer(uriTemplate, "/");
while (stringTokenizer.hasMoreElements()) {
String part1 = stringTokenizer.nextToken();
if (part1.contains("{")) {
String pathParam = part1.replace("{", "").replace("}", "");
PathParameter parameter = new PathParameter();
parameter.setName(pathParam);
parameter.setType("string");
parameters.add(parameter);
}
}
return parameters;
}
Aggregations