Search in sources :

Example 26 with QueryParameter

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

the class QueryParameterConverterTest method convertStringArrayQueryParameter.

@Test
public void convertStringArrayQueryParameter() throws Exception {
    io.swagger.models.apideclaration.Parameter param = new io.swagger.models.apideclaration.Parameter();
    param.setParamType(ParamType.QUERY);
    param.setDescription("a string array query param");
    param.setRequired(false);
    param.setAllowMultiple(true);
    param.setType("string");
    Parameter converted = converter.convertParameter(param);
    assertTrue(converted.getClass().equals(QueryParameter.class));
    QueryParameter qp = (QueryParameter) converted;
    assertEquals(qp.getType(), "array");
    assertEquals(param.getDescription(), qp.getDescription());
    assertNotNull(qp.getItems());
    Property items = qp.getItems();
    assertEquals(items.getType(), "string");
    assertEquals((Boolean) param.getRequired(), (Boolean) qp.getRequired());
    assertEquals(qp.getCollectionFormat(), "csv");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 27 with QueryParameter

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

the class SwaggerParserTest method testIssue292WithCSVCollectionFormat.

@Test
public void testIssue292WithCSVCollectionFormat() {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  version: '0.0.0'\n" + "  title: nada\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      parameters:\n" + "      - name: testParam\n" + "        in: query\n" + "        type: array\n" + "        items:\n" + "          type: string\n" + "        collectionFormat: csv\n" + "      responses:\n" + "        200:\n" + "          description: Successful response";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    Parameter param = swagger.getPaths().get("/persons").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) 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) Test(org.testng.annotations.Test)

Example 28 with QueryParameter

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

the class SwaggerParserTest method testIssue292WithNoCollectionFormat.

@Test
public void testIssue292WithNoCollectionFormat() {
    String yaml = "swagger: '2.0'\n" + "info:\n" + "  version: '0.0.0'\n" + "  title: nada\n" + "paths:\n" + "  /persons:\n" + "    get:\n" + "      parameters:\n" + "      - name: testParam\n" + "        in: query\n" + "        type: array\n" + "        items:\n" + "          type: string\n" + "      responses:\n" + "        200:\n" + "          description: Successful response";
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult result = parser.readWithInfo(yaml);
    Swagger swagger = result.getSwagger();
    Parameter param = swagger.getPaths().get("/persons").getGet().getParameters().get(0);
    QueryParameter qp = (QueryParameter) param;
    assertNull(qp.getCollectionFormat());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) SwaggerDeserializationResult(io.swagger.parser.util.SwaggerDeserializationResult) 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) Test(org.testng.annotations.Test)

Example 29 with QueryParameter

use of io.swagger.models.parameters.QueryParameter 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 30 with QueryParameter

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

the class SwaggerReaderTest method readSimpleExampleWithMinimumValues.

@Test(description = "it should read the simple example with minimum values")
public void readSimpleExampleWithMinimumValues() {
    final SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.read("sampleWithMinimumValues.yaml");
    final QueryParameter qp = (QueryParameter) swagger.getPaths().get("/pets").getGet().getParameters().get(0);
    assertEquals(qp.getMinimum(), new BigDecimal("0.0"));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.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