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);
}
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" + "}");
}
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());
}
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));
}
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);
}
Aggregations