use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method testLongValue.
@Test(description = "should serialize long value")
public void testLongValue() {
final QueryParameter param = (QueryParameter) new QueryParameter().required(false);
Schema schema = new IntegerSchema().format("int64");
schema.setDefault("1234");
param.setSchema(schema);
final String json = "{" + " \"in\":\"query\"," + " \"required\":false," + " \"schema\":{" + " \"type\":\"integer\"," + " \"default\":1234," + " \"format\":\"int64\"" + " }" + "}";
SerializationMatchers.assertEqualsToJson(param, json);
}
use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method testIncorrectDouble.
@Test(description = "should not serialize incorrect double value")
public void testIncorrectDouble() {
final QueryParameter param = (QueryParameter) new QueryParameter().required(false);
Schema schema = new NumberSchema().format("double");
schema.setDefault("test");
param.setSchema(schema);
final String json = "{" + " \"in\":\"query\"," + " \"required\":false," + " \"schema\":{" + " \"type\":\"number\"," + " \"format\":\"double\"" + " }" + "}";
SerializationMatchers.assertEqualsToJson(param, json);
}
use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ParameterSerializationTest method testStringValue.
@Test(description = "should serialize string value")
public void testStringValue() {
final QueryParameter param = (QueryParameter) new QueryParameter().required(false);
Schema schema = new Schema().type("string");
schema.setDefault("false");
param.setSchema(schema);
final String json = "{" + " \"in\":\"query\"," + " \"required\":false," + " \"schema\":{" + " \"type\":\"string\"," + " \"default\":\"false\"" + " }" + "}";
SerializationMatchers.assertEqualsToJson(param, json);
}
use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class SimpleBuilderTest method testBuilder.
@Test
public void testBuilder() throws Exception {
// basic metadata
OpenAPI oai = new OpenAPI().info(new Info().contact(new Contact().email("tony@eatbacon.org").name("Tony the Tam").url("https://foo.bar"))).externalDocs(new ExternalDocumentation().description("read more here").url("http://swagger.io")).addTagsItem(new Tag().name("funky dunky").description("all about neat things")).extensions(new HashMap<String, Object>() {
{
put("x-fancy-extension", "something");
}
});
Map<String, Schema> schemas = new HashMap<>();
schemas.put("StringSchema", new StringSchema().description("simple string schema").minLength(3).maxLength(100).example("it works"));
schemas.put("IntegerSchema", new IntegerSchema().description("simple integer schema").multipleOf(new BigDecimal(3)).minimum(new BigDecimal(6)));
oai.components(new Components().schemas(schemas));
schemas.put("Address", new Schema().description("address object").addProperties("street", new StringSchema().description("the street number")).addProperties("city", new StringSchema().description("city")).addProperties("state", new StringSchema().description("state").minLength(2).maxLength(2)).addProperties("zip", new StringSchema().description("zip code").pattern("^\\d{5}(?:[-\\s]\\d{4})?$").minLength(2).maxLength(2)).addProperties("country", new StringSchema()._enum(new ArrayList<String>() {
{
this.add("US");
}
})).description("2-digit country code").minLength(2).maxLength(2));
oai.paths(new Paths().addPathItem("/foo", new PathItem().description("the foo path").get(new Operation().addParametersItem(new QueryParameter().description("Records to skip").required(false).schema(new IntegerSchema())).responses(new ApiResponses().addApiResponse("200", new ApiResponse().description("it worked").content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("#/components/schemas/Address")))).addLink("funky", new Link().operationId("getFunky")))))));
System.out.println(writeJson(oai));
}
use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.
the class ParameterDeSerializationTest method deserializeQueryParameter.
@Test(description = "it should deserialize a QueryParameter")
public void deserializeQueryParameter() throws IOException {
final String json = "{\"in\":\"query\",\"required\":false,\"schema\":{\"type\":\"string\"}}";
final Parameter p = m.readValue(json, Parameter.class);
SerializationMatchers.assertEqualsToJson(p, json);
}
Aggregations