Search in sources :

Example 11 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class SecurityDefinitionTest method createModelWithSecurityRequirements.

@Test(description = "it should create a model with security requirements")
public void createModelWithSecurityRequirements() throws IOException {
    final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
    final Schema errorModel = ModelConverters.getInstance().read(Error.class).get("Error");
    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 oas = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
    oas.schemaRequirement("githubAccessCode", new SecurityScheme().flows(new OAuthFlows().authorizationCode(new OAuthFlow().scopes(new Scopes().addString("user:email", "Grants read access to a user’s email addresses.")))));
    final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id");
    get.addParametersItem(new Parameter().in("query").name("tags").description("tags to filter by").required(false).schema(new StringSchema()));
    get.addParametersItem(new Parameter().in("path").name("petId").description("pet to fetch").schema(new IntegerSchema().format("int64")));
    final ApiResponse response = new ApiResponse().description("pets returned").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person"))));
    final ApiResponse errorResponse = new ApiResponse().description("error response").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Error"))));
    get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse)).addSecurityItem(new SecurityRequirement().addList("internal_oauth2", "user:email")).addSecurityItem(new SecurityRequirement().addList("api_key"));
    oas.path("/pets", new PathItem().get(get));
    final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
    SerializationMatchers.assertEqualsToJson(oas, json);
}
Also used : Server(io.swagger.v3.oas.models.servers.Server) OAuthFlows(io.swagger.v3.oas.models.security.OAuthFlows) 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) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Contact(io.swagger.v3.oas.models.info.Contact) PathItem(io.swagger.v3.oas.models.PathItem) OAuthFlow(io.swagger.v3.oas.models.security.OAuthFlow) Scopes(io.swagger.v3.oas.models.security.Scopes) Content(io.swagger.v3.oas.models.media.Content) Parameter(io.swagger.v3.oas.models.parameters.Parameter) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Person(io.swagger.v3.core.oas.models.Person) OpenAPI(io.swagger.v3.oas.models.OpenAPI) SecurityScheme(io.swagger.v3.oas.models.security.SecurityScheme) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) SecurityRequirement(io.swagger.v3.oas.models.security.SecurityRequirement) Test(org.testng.annotations.Test)

Example 12 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method serializeLongMapProperty.

@Test(description = "it should serialize a long MapProperty")
public void serializeLongMapProperty() throws IOException {
    final Schema p = new MapSchema().additionalProperties(new IntegerSchema().format("int64"));
    final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int64\"}}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) 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) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Test(org.testng.annotations.Test)

Example 13 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class ModelSerializerTest method testIssue2064Ip.

@Test
public void testIssue2064Ip() throws Exception {
    String json = "{\n" + "  \"type\": \"object\",\n" + "  \"properties\": {\n" + "    \"id\": {\n" + "      \"type\": \"integer\",\n" + "      \"format\": \"int32\",\n" + "      \"multipleOf\": 3.0\n" + "    }\n" + "  }\n" + "}";
    final Schema model = Json.mapper().readValue(json, Schema.class);
    IntegerSchema ip = (IntegerSchema) model.getProperties().get("id");
    assertEquals(ip.getMultipleOf(), new BigDecimal("3.0"));
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) 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) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 14 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema in project swagger-core by swagger-api.

the class ModelSerializerTest method integerEnumGeneration.

@Test(description = "it should generate an integer field with enum")
public void integerEnumGeneration() throws IOException {
    final String json = "{\n" + "   \"properties\":{\n" + "      \"id\":{\n" + "         \"description\":\"fun!\",\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\",\n" + "         \"readOnly\":true,\n" + "         \"enum\": [ 0, 1]\n" + "      }\n" + "   }\n" + "}";
    final Schema model = Json.mapper().readValue(json, Schema.class);
    IntegerSchema p = (IntegerSchema) model.getProperties().get("id");
    assertNotNull(p.getEnum());
    assertEquals(p.getEnum().get(0), new Integer(0));
    assertEquals(p.getEnum().get(1), new Integer(1));
}
Also used : DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) 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) Test(org.testng.annotations.Test)

Example 15 with IntegerSchema

use of io.swagger.v3.oas.models.media.IntegerSchema 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)

Aggregations

Test (org.testng.annotations.Test)33 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)32 Schema (io.swagger.v3.oas.models.media.Schema)24 StringSchema (io.swagger.v3.oas.models.media.StringSchema)23 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)14 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)8 BigDecimal (java.math.BigDecimal)8 OpenAPI (io.swagger.v3.oas.models.OpenAPI)7 Info (io.swagger.v3.oas.models.info.Info)7 DateSchema (io.swagger.v3.oas.models.media.DateSchema)6 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)6 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)6 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)6 Components (io.swagger.v3.oas.models.Components)5 Operation (io.swagger.v3.oas.models.Operation)5 BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)5 MapSchema (io.swagger.v3.oas.models.media.MapSchema)5 PathItem (io.swagger.v3.oas.models.PathItem)4 Contact (io.swagger.v3.oas.models.info.Contact)4