Search in sources :

Example 31 with StringSchema

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

the class ParameterSerializationTest method serializeBodyParameterToYaml.

@Test(description = "it should serialize a BodyParameter to yaml")
public void serializeBodyParameterToYaml() {
    final Schema model = new Schema().title("Cat").addProperties("name", new StringSchema());
    final RequestBody p = new RequestBody().content(new Content().addMediaType("*/*", new MediaType().schema(model)));
    final String yaml = "---\n" + "content:\n" + "  '*/*':\n" + "    schema:\n" + "      title: Cat\n" + "      properties:\n" + "        name:\n" + "          type: string";
    SerializationMatchers.assertEqualsToYaml(p, yaml);
}
Also used : Content(io.swagger.v3.oas.models.media.Content) 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) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 32 with StringSchema

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

the class OpenAPI3_1SerializationTest method testDiscriminatorSerialization.

@Test
public void testDiscriminatorSerialization() {
    Schema<String> propertySchema1 = new StringSchema();
    propertySchema1.addType(propertySchema1.getType());
    Schema<String> propertySchema2 = new StringSchema();
    propertySchema2.addType(propertySchema2.getType());
    Discriminator discriminator = new Discriminator().propertyName("type");
    discriminator.addExtension("x-otherName", "discriminationType");
    Schema schema = new ObjectSchema().addProperties("name", propertySchema1).addProperties("type", propertySchema1).discriminator(discriminator);
    schema.addType(schema.getType());
    OpenAPI openAPI = new OpenAPI().openapi("3.1.0").components(new Components().addSchemas("pet", schema));
    SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "components:\n" + "  schemas:\n" + "    pet:\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        type:\n" + "          type: string\n" + "      discriminator:\n" + "        propertyName: type\n" + "        x-otherName: discriminationType\n" + "      type: object");
    SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + "  \"openapi\" : \"3.1.0\",\n" + "  \"components\" : {\n" + "    \"schemas\" : {\n" + "      \"pet\" : {\n" + "        \"properties\" : {\n" + "          \"name\" : {\n" + "            \"type\" : \"string\"\n" + "          },\n" + "          \"type\" : {\n" + "            \"type\" : \"string\"\n" + "          }\n" + "        },\n" + "        \"discriminator\" : {\n" + "          \"propertyName\" : \"type\",\n" + "          \"x-otherName\" : \"discriminationType\"\n" + "        },\n" + "        \"type\" : \"object\"\n" + "      }\n" + "    }\n" + "  }\n" + "}");
    openAPI.openapi("3.0.3");
    SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + "components:\n" + "  schemas:\n" + "    pet:\n" + "      properties:\n" + "        name:\n" + "          type: string\n" + "        type:\n" + "          type: string\n" + "      discriminator:\n" + "        propertyName: type\n" + "      type: object");
    SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + "  \"openapi\" : \"3.0.3\",\n" + "  \"components\" : {\n" + "    \"schemas\" : {\n" + "      \"pet\" : {\n" + "        \"properties\" : {\n" + "          \"name\" : {\n" + "            \"type\" : \"string\"\n" + "          },\n" + "          \"type\" : {\n" + "            \"type\" : \"string\"\n" + "          }\n" + "        },\n" + "        \"discriminator\" : {\n" + "          \"propertyName\" : \"type\"\n" + "        },\n" + "        \"type\" : \"object\"\n" + "      }\n" + "    }\n" + "  }\n" + "}");
}
Also used : Components(io.swagger.v3.oas.models.Components) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Discriminator(io.swagger.v3.oas.models.media.Discriminator) Test(org.testng.annotations.Test)

Example 33 with StringSchema

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

the class FormParamBeanTest method shouldSerializeTypeParameter.

@Test(description = "check schema of serialized BeanParam containing FormParams")
public void shouldSerializeTypeParameter() {
    OpenAPI openApi = new Reader(new OpenAPI()).read(MyFormBeanParamResource.class);
    RequestBody requestBody = openApi.getPaths().get("/").getGet().getRequestBody();
    Assert.assertNotNull(requestBody);
    MediaType mediaType = requestBody.getContent().get("application/x-www-form-urlencoded");
    Assert.assertNotNull(mediaType);
    Schema schema = mediaType.getSchema();
    Assert.assertEquals(schema.getProperties().size(), 2);
    Assert.assertEquals(schema.getProperties().get("param1"), new StringSchema());
    Assert.assertEquals(schema.getProperties().get("param2"), new StringSchema());
}
Also used : StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) StringSchema(io.swagger.v3.oas.models.media.StringSchema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Example 34 with StringSchema

use of io.swagger.v3.oas.models.media.StringSchema 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 35 with StringSchema

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

the class PropertySerializationTest method serializeReadOnlyStringProperty.

@Test(description = "it should serialize a string property with readOnly set")
public void serializeReadOnlyStringProperty() throws IOException {
    final Schema p = new StringSchema().readOnly(true);
    final String json = "{\"type\":\"string\",\"readOnly\":true}";
    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) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Test(org.testng.annotations.Test)

Aggregations

StringSchema (io.swagger.v3.oas.models.media.StringSchema)88 Test (org.testng.annotations.Test)79 Schema (io.swagger.v3.oas.models.media.Schema)69 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)53 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)52 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)47 OpenAPI (io.swagger.v3.oas.models.OpenAPI)40 PathItem (io.swagger.v3.oas.models.PathItem)22 Operation (io.swagger.v3.oas.models.Operation)21 MediaType (io.swagger.v3.oas.models.media.MediaType)21 Content (io.swagger.v3.oas.models.media.Content)20 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)19 MapSchema (io.swagger.v3.oas.models.media.MapSchema)19 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)19 DateSchema (io.swagger.v3.oas.models.media.DateSchema)17 Components (io.swagger.v3.oas.models.Components)15 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)15 Parameter (io.swagger.v3.oas.models.parameters.Parameter)15 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)14