Search in sources :

Example 16 with PathParameter

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"));
}
Also used : Swagger(io.swagger.models.Swagger) SerializableParameter(io.swagger.models.parameters.SerializableParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) 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) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 17 with PathParameter

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]");
}
Also used : SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 18 with PathParameter

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());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 19 with PathParameter

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");
}
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 20 with PathParameter

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter)

Aggregations

PathParameter (io.swagger.models.parameters.PathParameter)51 QueryParameter (io.swagger.models.parameters.QueryParameter)35 Parameter (io.swagger.models.parameters.Parameter)32 Test (org.testng.annotations.Test)32 BodyParameter (io.swagger.models.parameters.BodyParameter)26 HeaderParameter (io.swagger.models.parameters.HeaderParameter)16 Swagger (io.swagger.models.Swagger)14 StringProperty (io.swagger.models.properties.StringProperty)12 FormParameter (io.swagger.models.parameters.FormParameter)11 Operation (io.swagger.models.Operation)10 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 Response (io.swagger.models.Response)8 IntegerProperty (io.swagger.models.properties.IntegerProperty)8 RefProperty (io.swagger.models.properties.RefProperty)8 Path (io.swagger.models.Path)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 HashMap (java.util.HashMap)6 ModelImpl (io.swagger.models.ModelImpl)5 RefModel (io.swagger.models.RefModel)5 ArrayList (java.util.ArrayList)5