Search in sources :

Example 6 with QueryParameter

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);
}
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) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Test(org.testng.annotations.Test)

Example 7 with QueryParameter

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);
}
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) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) Test(org.testng.annotations.Test)

Example 8 with QueryParameter

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);
}
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 9 with QueryParameter

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));
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) HashMap(java.util.HashMap) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ArrayList(java.util.ArrayList) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Components(io.swagger.v3.oas.models.Components) PathItem(io.swagger.v3.oas.models.PathItem) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Paths(io.swagger.v3.oas.models.Paths) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Info(io.swagger.v3.oas.models.info.Info) BigDecimal(java.math.BigDecimal) Contact(io.swagger.v3.oas.models.info.Contact) Content(io.swagger.v3.oas.models.media.Content) Tag(io.swagger.v3.oas.models.tags.Tag) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Link(io.swagger.v3.oas.models.links.Link) Test(org.testng.annotations.Test)

Example 10 with QueryParameter

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);
}
Also used : Parameter(io.swagger.v3.oas.models.parameters.Parameter) 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