use of io.swagger.v3.jaxrs2.resources.model.Pet 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);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class ModelSerializerTest method serializeArrayModel.
@Test(description = "it should serialize an array model")
public void serializeArrayModel() throws IOException {
final ArraySchema model = new ArraySchema();
model.setItems(new Schema().$ref("Pet"));
assertEquals(m.writeValueAsString(model), "{\"type\":\"array\",\"items\":{\"$ref\":\"#/components/schemas/Pet\"}}");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class ModelSerializerTest method deserializeArrayModel.
@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
final Schema p = m.readValue(json, Schema.class);
assertTrue(p instanceof ArraySchema);
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.jaxrs2.resources.model.Pet in project swagger-core by swagger-api.
the class SchemaSerializationTest method serializeRefSchema3_1.
@Test
public void serializeRefSchema3_1() {
OpenAPI openAPI = new OpenAPI().components(new Components().addSchemas("Pet", new Schema().addProperties("id", new Schema().type("integer")).addProperties("name", new Schema().type("string")).addProperties("tag", new Schema().type("string"))).addSchemas("AnotherPet", new Schema().title("Another Pet").description("Another Pet for petstore referencing Pet schema").$ref("#/components/schemas/Pet").addProperties("category", new Schema().type("string")).addProperties("photoUrl", new Schema().type("string"))));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id: {}\n" + " name: {}\n" + " tag: {}\n" + " AnotherPet:\n" + " title: Another Pet\n" + " properties:\n" + " category: {}\n" + " photoUrl: {}\n" + " description: Another Pet for petstore referencing Pet schema\n" + " $ref: '#/components/schemas/Pet'");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.1\n" + "components:\n" + " schemas:\n" + " Pet:\n" + " properties:\n" + " id:\n" + " type: integer\n" + " name:\n" + " type: string\n" + " tag:\n" + " type: string\n" + " AnotherPet:\n" + " $ref: '#/components/schemas/Pet'");
}
use of io.swagger.v3.jaxrs2.resources.model.Pet 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" + "}");
}
Aggregations