Search in sources :

Example 26 with IntegerSchema

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

the class PropertySerializationTest method serializeLongProperty.

@Test(description = "it should serialize a LongProperty")
public void serializeLongProperty() throws IOException {
    final IntegerSchema p = new IntegerSchema().format("int64")._default(8675309);
    final String json = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Test(org.testng.annotations.Test)

Example 27 with IntegerSchema

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

the class HiddenFieldTest method testHiddenField.

@Test(description = "it should ignore a hidden field")
public void testHiddenField() {
    final Map<String, Schema> models = ModelConverters.getInstance().read(ModelWithHiddenFields.class);
    final Schema model = models.get("ModelWithHiddenFields");
    assertNotNull(model);
    assertEquals(model.getProperties().size(), 2);
    final Schema idValue = (Schema) model.getProperties().get("id");
    assertTrue(idValue instanceof IntegerSchema);
    assertTrue(model.getRequired().contains("id"));
    final Schema nameValue = (Schema) model.getProperties().get("name");
    assertTrue(nameValue instanceof StringSchema);
    final Schema passwordValue = (Schema) model.getProperties().get("password");
    assertNull(passwordValue);
}
Also used : IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Example 28 with IntegerSchema

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

the class ReaderTest method testTicket3029.

@Test(description = "Parameter with ref")
public void testTicket3029() {
    Components components = new Components();
    components.addParameters("id", new Parameter().description("Id Description").schema(new IntegerSchema()).in(ParameterIn.QUERY.toString()).example(1).required(true));
    OpenAPI oas = new OpenAPI().info(new Info().description("info")).components(components);
    Reader reader = new Reader(oas);
    OpenAPI openAPI = reader.read(RefParameter3029Resource.class);
    String yaml = "openapi: 3.0.1\n" + "info:\n" + "  description: info\n" + "paths:\n" + "  /2:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      operationId: sendPayload2\n" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "  /1:\n" + "    get:\n" + "      summary: Simple get operation\n" + "      operationId: sendPayload1\n" + "      parameters:\n" + "      - $ref: '#/components/parameters/id'\n" + "      responses:\n" + "        default:\n" + "          description: default response\n" + "          content:\n" + "            '*/*': {}\n" + "components:\n" + "  parameters:\n" + "    id:\n" + "      in: query\n" + "      description: Id Description\n" + "      required: true\n" + "      schema:\n" + "        type: integer\n" + "        format: int32\n" + "      example: 1\n";
    SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
Also used : Components(io.swagger.v3.oas.models.Components) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Info(io.swagger.v3.oas.models.info.Info) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 29 with IntegerSchema

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

the class SchemaTests method AdditionalPropertiesSchema.

@Test
public void AdditionalPropertiesSchema() {
    Map<String, Schema> schemas = new HashMap<>();
    schemas.put("IntegerSchema", new IntegerSchema().description("simple integer schema").multipleOf(new BigDecimal(3)).minimum(new BigDecimal(6)).additionalProperties(new StringSchema()));
}
Also used : HashMap(java.util.HashMap) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 30 with IntegerSchema

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

the class ModelSerializerTest method convertModel.

@Test(description = "it should convert a model")
public void convertModel() throws JsonProcessingException {
    final Schema pet = new Schema();
    final Map<String, Schema> props = new LinkedHashMap<String, Schema>();
    props.put("intValue", new IntegerSchema());
    props.put("longValue", new IntegerSchema().format("int64"));
    props.put("dateValue", new DateSchema());
    props.put("dateTimeValue", new DateTimeSchema());
    pet.setProperties(props);
    pet.setRequired(Arrays.asList("intValue", "name"));
    final String json = "{\n" + "   \"required\":[\n" + "      \"intValue\"\n" + "   ],\n" + "   \"properties\":{\n" + "      \"intValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int32\"\n" + "      },\n" + "      \"longValue\":{\n" + "         \"type\":\"integer\",\n" + "         \"format\":\"int64\"\n" + "      },\n" + "      \"dateValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date\"\n" + "      },\n" + "      \"dateTimeValue\":{\n" + "         \"type\":\"string\",\n" + "         \"format\":\"date-time\"\n" + "      }\n" + "   }\n" + "}";
    SerializationMatchers.assertEqualsToJson(pet, json);
}
Also used : DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) 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) DateSchema(io.swagger.v3.oas.models.media.DateSchema) LinkedHashMap(java.util.LinkedHashMap) 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