Search in sources :

Example 76 with QueryParameter

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

the class SwaggerParserTest method testIssue146.

@Test
public void testIssue146() {
    SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.read("src/test/resources/issue_146.yaml");
    assertNotNull(swagger);
    QueryParameter p = ((QueryParameter) swagger.getPaths().get("/checker").getGet().getParameters().get(0));
    StringProperty pp = (StringProperty) p.getItems();
    assertTrue("registration".equalsIgnoreCase(pp.getEnum().get(0)));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) StringProperty(io.swagger.models.properties.StringProperty) Test(org.testng.annotations.Test)

Example 77 with QueryParameter

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

the class SwaggerResolverTest method testOperationParameterRemoteRefs.

@Test(description = "resolve operation parameter remote refs")
public void testOperationParameterRemoteRefs() {
    final Swagger swagger = new Swagger();
    swagger.path("/fun", new Path().get(new Operation().parameter(new RefParameter("#/parameters/SampleParameter"))));
    swagger.parameter("SampleParameter", new QueryParameter().name("skip").property(new IntegerProperty()));
    final Swagger resolved = new SwaggerResolver(swagger, null).resolve();
    final List<Parameter> params = swagger.getPaths().get("/fun").getGet().getParameters();
    assertEquals(params.size(), 1);
    final QueryParameter param = (QueryParameter) params.get(0);
    assertEquals(param.getName(), "skip");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) RefParameter(io.swagger.models.parameters.RefParameter) 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 78 with QueryParameter

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

the class SwaggerResolverTest method testSharedPathParametersTest.

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

Example 79 with QueryParameter

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

the class SwaggerDeserializerTest method testArrayQueryParam.

@Test
public void testArrayQueryParam() throws Exception {
    String json = "{\n" + "  \"swagger\": \"2.0\",\n" + "  \"paths\": {\n" + "    \"/pet/findByStatus\": {\n" + "      \"get\": {\n" + "        \"parameters\": [\n" + "          {\n" + "            \"name\": \"status\",\n" + "            \"in\": \"query\",\n" + "            \"description\": \"Status values that need to be considered for filter\",\n" + "            \"required\": false,\n" + "            \"type\": \"array\",\n" + "            \"items\": {\n" + "              \"type\": \"string\"\n" + "            },\n" + "            \"collectionFormat\": \"pipes\",\n" + "            \"default\": \"available\"\n" + "          }\n" + "        ],\n" + "        \"responses\": {\n" + "          \"200\": {\n" + "            \"description\": \"successful operation\",\n" + "            \"schema\": {\n" + "              \"$ref\": \"#/definitions/PetArray\"\n" + "            }\n" + "          }\n" + "        }\n" + "      }\n" + "    }\n" + "  }\n" + "}";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(json);
    Swagger swagger = result.getSwagger();
    Parameter param = swagger.getPath("/pet/findByStatus").getGet().getParameters().get(0);
    assertTrue(param instanceof QueryParameter);
    QueryParameter qp = (QueryParameter) param;
    Property p = qp.getItems();
    assertEquals(qp.getType(), "array");
    assertTrue(p instanceof StringProperty);
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 80 with QueryParameter

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

the class SwaggerDeserializerTest method testIssue343Parameter.

@Test
public void testIssue343Parameter() {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  description: 'bleh'\n" + "  version: '2.0.0'\n" + "  title: 'Test'\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      parameters:\n" + "        - in: query\n" + "          name: skip\n" + "          type: integer\n" + "          format: int32\n" + "          multipleOf: 3\n" + "        - in: body\n" + "          name: body\n" + "          required: true\n" + "          schema:\n" + "            type: object\n" + "            additionalProperties:\n" + "              type: string\n" + "      responses:\n" + "        200:\n" + "          description: 'OK'\n" + "definitions:\n" + "  Fun:\n" + "    properties:\n" + "      id:\n" + "        type: integer\n" + "        format: int32\n" + "        multipleOf: 5\n" + "      mySet:\n" + "        type: array\n" + "        uniqueItems: true\n" + "        items:\n" + "          type: string";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    QueryParameter qp = (QueryParameter) swagger.getPath("/foo").getPost().getParameters().get(0);
    assertEquals(qp.getMultipleOf(), 3.0);
    BodyParameter bp = (BodyParameter) swagger.getPath("/foo").getPost().getParameters().get(1);
    ModelImpl schema = (ModelImpl) bp.getSchema();
    assertTrue(schema.getAdditionalProperties() != null);
    IntegerProperty id = (IntegerProperty) swagger.getDefinitions().get("Fun").getProperties().get("id");
    assertEquals(id.getMultipleOf(), new BigDecimal("5"));
    ArrayProperty ap = (ArrayProperty) swagger.getDefinitions().get("Fun").getProperties().get("mySet");
    assertTrue(ap.getUniqueItems());
}
Also used : SwaggerParser(io.swagger.parser.SwaggerParser) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

QueryParameter (io.swagger.models.parameters.QueryParameter)92 Test (org.testng.annotations.Test)58 Parameter (io.swagger.models.parameters.Parameter)42 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 Test (org.junit.Test)12 Operation (io.swagger.models.Operation)11 FormParameter (io.swagger.models.parameters.FormParameter)11 SerializableParameter (io.swagger.models.parameters.SerializableParameter)10 StringProperty (io.swagger.models.properties.StringProperty)10 HashMap (java.util.HashMap)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 Type (java.lang.reflect.Type)9 BigDecimal (java.math.BigDecimal)9 RefProperty (io.swagger.models.properties.RefProperty)8 Response (io.swagger.models.Response)7 Method (java.lang.reflect.Method)7