Search in sources :

Example 71 with QueryParameter

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

the class LegacyConverterTest method convertSingleFile.

/**
 * reads a single-file swagger definition
 */
@Test
public void convertSingleFile() throws Exception {
    Swagger swagger = converter.read("src/test/resources/specs/v1_2/singleFile.json");
    assertTrue(swagger.getSecurityDefinitions().size() == 2);
    SecuritySchemeDefinition auth = swagger.getSecurityDefinitions().get("oauth2");
    assertNotNull(auth);
    assertEquals(auth.getClass(), OAuth2Definition.class);
    OAuth2Definition oauth2 = (OAuth2Definition) auth;
    assertEquals(oauth2.getFlow(), "implicit");
    assertEquals(oauth2.getAuthorizationUrl(), "http://petstore.swagger.io/oauth/dialog");
    assertTrue(oauth2.getScopes().size() == 2);
    Map<String, String> scopes = oauth2.getScopes();
    assertEquals(scopes.get("email"), "Access to your email address");
    assertEquals(scopes.get("pets"), "Access to your pets");
    auth = swagger.getSecurityDefinitions().get("apiKey");
    assertNotNull(auth);
    assertEquals(auth.getClass(), ApiKeyAuthDefinition.class);
    ApiKeyAuthDefinition apiKey = (ApiKeyAuthDefinition) auth;
    assertEquals(apiKey.getName(), "api_key");
    assertEquals(apiKey.getIn(), In.HEADER);
    assertEquals(swagger.getSwagger(), "2.0");
    assertEquals(swagger.getHost(), "petstore.swagger.io");
    assertEquals(swagger.getBasePath(), "/api");
    assertNotNull(swagger.getInfo());
    Info info = swagger.getInfo();
    assertEquals(info.getVersion(), "1.0.0");
    assertEquals(info.getTitle(), "Swagger Sample App");
    assertEquals(info.getTermsOfService(), "http://swagger.io/terms/");
    Contact contact = info.getContact();
    assertEquals(contact.getUrl(), "apiteam@swagger.io");
    License license = info.getLicense();
    assertEquals(license.getName(), "Apache 2.0");
    assertEquals(license.getUrl(), "http://www.apache.org/licenses/LICENSE-2.0.html");
    assertTrue(swagger.getDefinitions().size() == 3);
    assertTrue(swagger.getPaths().size() == 5);
    Operation patchOperation = swagger.getPaths().get("/pet/{petId}").getPatch();
    List<Map<String, List<String>>> security = patchOperation.getSecurity();
    assertTrue(security.size() == 1);
    Map<String, List<String>> securityDetail = security.get(0);
    String key = securityDetail.keySet().iterator().next();
    assertEquals(key, "oauth2");
    List<String> oauth2Scopes = securityDetail.get(key);
    assertEquals(oauth2Scopes.size(), 1);
    assertEquals(oauth2Scopes.get(0), "test:anything");
    Operation fetchOperation = swagger.getPaths().get("/pet/findByStatus").getGet();
    QueryParameter param = (QueryParameter) fetchOperation.getParameters().get(0);
    assertEquals(param.getDefaultValue(), "available");
    List<String> _enum = param.getEnum();
    assertEquals(_enum.get(0), "available");
    assertEquals(_enum.get(1), "pending");
    assertEquals(_enum.get(2), "sold");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) OAuth2Definition(io.swagger.models.auth.OAuth2Definition) License(io.swagger.models.License) SecuritySchemeDefinition(io.swagger.models.auth.SecuritySchemeDefinition) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) Contact(io.swagger.models.Contact) ApiKeyAuthDefinition(io.swagger.models.auth.ApiKeyAuthDefinition) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 72 with QueryParameter

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

the class QueryParameterConverterTest method convertDateQueryParameter.

@Test
public void convertDateQueryParameter() throws Exception {
    io.swagger.models.apideclaration.Parameter param = new io.swagger.models.apideclaration.Parameter();
    param.setParamType(ParamType.QUERY);
    param.setDescription("a string query param");
    param.setRequired(false);
    param.setAllowMultiple(false);
    param.setType("string");
    param.setFormat(Format.DATE_TIME);
    Parameter converted = converter.convertParameter(param);
    assertTrue(converted.getClass().equals(QueryParameter.class));
    QueryParameter qp = (QueryParameter) converted;
    assertEquals(param.getType(), qp.getType());
    assertEquals(qp.getFormat(), "date-time");
    assertEquals(param.getDescription(), qp.getDescription());
    assertEquals((Boolean) param.getRequired(), (Boolean) qp.getRequired());
    assertNull(qp.getCollectionFormat());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 73 with QueryParameter

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

the class QueryParameterConverterTest method convertStringQueryParameter.

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

Example 74 with QueryParameter

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

the class QueryParameterConverterTest method convertIntegerQueryParameter.

@Test
public void convertIntegerQueryParameter() throws Exception {
    io.swagger.models.apideclaration.Parameter param = new io.swagger.models.apideclaration.Parameter();
    param.setParamType(ParamType.QUERY);
    param.setDescription("a string query param");
    param.setRequired(false);
    param.setAllowMultiple(false);
    param.setType("integer");
    param.setFormat(Format.INT32);
    Parameter converted = converter.convertParameter(param);
    assertTrue(converted.getClass().equals(QueryParameter.class));
    QueryParameter qp = (QueryParameter) converted;
    assertEquals(param.getType(), qp.getType());
    assertEquals(qp.getFormat(), "int32");
    assertEquals(param.getDescription(), qp.getDescription());
    assertEquals((Boolean) param.getRequired(), (Boolean) qp.getRequired());
    assertNull(qp.getCollectionFormat());
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Test(org.testng.annotations.Test)

Example 75 with QueryParameter

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

the class SwaggerParserTest method testBadFormat.

public void testBadFormat() throws Exception {
    SwaggerParser parser = new SwaggerParser();
    final Swagger swagger = parser.read("src/test/resources/bad_format.yaml");
    Path path = swagger.getPath("/pets");
    Parameter parameter = path.getGet().getParameters().get(0);
    assertNotNull(parameter);
    assertTrue(parameter instanceof QueryParameter);
    QueryParameter queryParameter = (QueryParameter) parameter;
    assertEquals(queryParameter.getName(), "query-param-int32");
    assertNotNull(queryParameter.getEnum());
    assertEquals(queryParameter.getEnum().size(), 3);
    List<Object> enumValues = queryParameter.getEnumValue();
    assertEquals(enumValues.get(0), 1);
    assertEquals(enumValues.get(1), 2);
    assertEquals(enumValues.get(2), 7);
    parameter = path.getGet().getParameters().get(1);
    assertNotNull(parameter);
    assertTrue(parameter instanceof QueryParameter);
    queryParameter = (QueryParameter) parameter;
    assertEquals(queryParameter.getName(), "query-param-invalid-format");
    assertNotNull(queryParameter.getEnum());
    assertEquals(queryParameter.getEnum().size(), 3);
    enumValues = queryParameter.getEnumValue();
    assertEquals(enumValues.get(0), 1);
    assertEquals(enumValues.get(1), 2);
    assertEquals(enumValues.get(2), 7);
    parameter = path.getGet().getParameters().get(2);
    assertNotNull(parameter);
    assertTrue(parameter instanceof QueryParameter);
    queryParameter = (QueryParameter) parameter;
    assertEquals(queryParameter.getName(), "query-param-collection-format-and-uniqueItems");
    assertEquals(queryParameter.getCollectionFormat(), "multi");
    assertEquals(queryParameter.isUniqueItems(), true);
}
Also used : Path(io.swagger.models.Path) QueryParameter(io.swagger.models.parameters.QueryParameter) 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)

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