Search in sources :

Example 1 with QueryParameter

use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterDeSerializationTest method deserializeQueryParameterWithStyle.

@Test(description = "it should deserialize a QueryParameter with style")
public void deserializeQueryParameterWithStyle() throws IOException {
    final String json = "{\"in\":\"query\",\"style\":\"form\",\"required\":false,\"schema\":{\"type\":\"string\"}}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 2 with QueryParameter

use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterDeSerializationTest method deserializeArrayQueryParameter.

@Test(description = "it should deserialize a QueryParameter with array")
public void deserializeArrayQueryParameter() throws IOException {
    final String json = "{" + "   \"in\":\"query\"," + "   \"required\":false," + "   \"schema\":{" + "     \"type\":\"array\"," + "     \"items\":{" + "        \"type\":\"string\"" + "     }" + "   }" + "}";
    final Parameter p = m.readValue(json, Parameter.class);
    SerializationMatchers.assertEqualsToJson(p, json);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 3 with QueryParameter

use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class SwaggerSerializerTest method writeSpecWithParameterReferences.

@Test(description = "it should write a spec with parameter references")
public void writeSpecWithParameterReferences() throws IOException {
    final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Info info = new Info().version("1.0.0").title("Swagger Petstore");
    final Contact contact = new Contact().name("Swagger API Team").email("foo@bar.baz").url("http://swagger.io");
    info.setContact(contact);
    final OpenAPI swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel);
    final QueryParameter parameter = (QueryParameter) new QueryParameter().name("id").description("a common get parameter").schema(new IntegerSchema());
    final Operation get = new Operation().summary("finds pets in the system").description("a longer description").operationId("get pet by id").addParametersItem(new Parameter().$ref("#/parameters/Foo"));
    swagger.components(new Components().addParameters("Foo", parameter)).path("/pets", new PathItem().get(get));
    final String swaggerJson = Json.mapper().writeValueAsString(swagger);
    final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
    assertEquals(Json.pretty(rebuilt), Json.pretty(swagger));
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) Server(io.swagger.v3.oas.models.servers.Server) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Operation(io.swagger.v3.oas.models.Operation) Info(io.swagger.v3.oas.models.info.Info) Contact(io.swagger.v3.oas.models.info.Contact) Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) Parameter(io.swagger.v3.oas.models.parameters.Parameter) QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) Person(io.swagger.v3.core.oas.models.Person) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 4 with QueryParameter

use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method testBooleanValue.

@Test(description = "should serialize boolean value")
public void testBooleanValue() {
    final QueryParameter param = (QueryParameter) new QueryParameter().required(false);
    Schema schema = new Schema().type("boolean");
    schema.setDefault("false");
    param.setSchema(schema);
    final String json = "{" + "   \"in\":\"query\"," + "   \"required\":false," + "   \"schema\":{" + "      \"type\":\"boolean\"," + "       \"default\":\"false\"" + "   }" + "}";
    SerializationMatchers.assertEqualsToJson(param, json);
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 5 with QueryParameter

use of io.swagger.v3.oas.models.parameters.QueryParameter in project swagger-core by swagger-api.

the class ParameterSerializationTest method testFloatValue.

@Test(description = "should serialize float value")
public void testFloatValue() {
    final QueryParameter param = new QueryParameter();
    param.setSchema(new NumberSchema()._default(new BigDecimal("12.34")).format("float"));
    final String json = "{\"in\":\"query\",\"schema\":{\"type\":\"number\",\"format\":\"float\",\"default\":12.34}}";
    SerializationMatchers.assertEqualsToJson(param, json);
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)17 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)14 StringSchema (io.swagger.v3.oas.models.media.StringSchema)11 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)8 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)8 Schema (io.swagger.v3.oas.models.media.Schema)8 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)7 Parameter (io.swagger.v3.oas.models.parameters.Parameter)7 HeaderParameter (io.swagger.v3.oas.models.parameters.HeaderParameter)3 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)3 BigDecimal (java.math.BigDecimal)3 Components (io.swagger.v3.oas.models.Components)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 Operation (io.swagger.v3.oas.models.Operation)2 PathItem (io.swagger.v3.oas.models.PathItem)2 Contact (io.swagger.v3.oas.models.info.Contact)2 Info (io.swagger.v3.oas.models.info.Info)2 Person (io.swagger.v3.core.oas.models.Person)1 ExternalDocumentation (io.swagger.v3.oas.models.ExternalDocumentation)1 Paths (io.swagger.v3.oas.models.Paths)1