use of io.swagger.v3.oas.models.info.Contact in project swagger-core by swagger-api.
the class SwaggerSerializerTest method convertSpec.
@Test(description = "it should convert a spec")
public void convertSpec() 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 Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "value");
info.addExtension("x-test2", map);
info.addExtension("x-test", "value");
final OpenAPI swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel).schema("Error", errorModel);
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").addTagsItem("Pet Operations").operationId("get pet by id").deprecated(true);
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("application/json", new MediaType().schema(new Schema().$ref("Person")).example("fun")));
final ApiResponse errorResponse = new ApiResponse().description("error response").addLink("myLink", new Link().description("a link").operationId("theLinkedOperationId").addParameter("userId", "gah")).content(new Content().addMediaType("application/json", new MediaType().schema(new Schema().$ref("Error"))));
get.responses(new ApiResponses().addApiResponse("200", response).addApiResponse("default", errorResponse));
final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").addTagsItem("Pet Operations").operationId("add pet").responses(new ApiResponses().addApiResponse("default", errorResponse)).requestBody(new RequestBody().description("the pet to add").content(new Content().addMediaType("*/*", new MediaType().schema(new Schema().$ref("Person")))));
swagger.paths(new Paths().addPathItem("/pets", new PathItem().get(get).post(post)));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
Json.prettyPrint(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
use of io.swagger.v3.oas.models.info.Contact in project swagger-core by swagger-api.
the class SwaggerSerializerTest method writeSpecWithParameterReferences.
@Test(description = "it should write a spec with parameter references")
public void writeSpecWithParameterReferences() throws IOException {
final Schema personModel = ModelConverters.getInstance().read(Person.class).get("Person");
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 swagger = new OpenAPI().info(info).addServersItem(new Server().url("http://petstore.swagger.io")).schema("Person", personModel);
final QueryParameter parameter = (QueryParameter) new QueryParameter().name("id").description("a common get parameter").schema(new IntegerSchema());
final Operation get = new Operation().summary("finds pets in the system").description("a longer description").operationId("get pet by id").addParametersItem(new Parameter().$ref("#/parameters/Foo"));
swagger.components(new Components().addParameters("Foo", parameter)).path("/pets", new PathItem().get(get));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final OpenAPI rebuilt = Json.mapper().readValue(swaggerJson, OpenAPI.class);
assertEquals(Json.pretty(rebuilt), Json.pretty(swagger));
}
use of io.swagger.v3.oas.models.info.Contact 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.oas.models.info.Contact 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.info.Contact in project swagger-core by swagger-api.
the class OpenAPI3_1SerializationTest method testInfoSerialization.
@Test
public void testInfoSerialization() {
OpenAPI openAPI = new OpenAPI().openapi("3.1.0").info(new Info().title("Title test").description("This is a description for test").summary("Test Summary").version("1.0.0").termsOfService("https://test.term.of.services").contact(new Contact().name("Test Contact").url("https://test.contact.url").email("test@email.com")).license(new License().name("test license").url("https://test.license.com").identifier("swagger")));
SerializationMatchers.assertEqualsToYaml31(openAPI, "openapi: 3.1.0\n" + "info:\n" + " title: Title test\n" + " description: This is a description for test\n" + " summary: Test Summary\n" + " termsOfService: https://test.term.of.services\n" + " contact:\n" + " name: Test Contact\n" + " url: https://test.contact.url\n" + " email: test@email.com\n" + " license:\n" + " name: test license\n" + " url: https://test.license.com\n" + " identifier: swagger\n" + " version: 1.0.0");
SerializationMatchers.assertEqualsToJson31(openAPI, "{\n" + " \"openapi\" : \"3.1.0\",\n" + " \"info\" : {\n" + " \"title\" : \"Title test\",\n" + " \"description\" : \"This is a description for test\",\n" + " \"summary\" : \"Test Summary\",\n" + " \"termsOfService\" : \"https://test.term.of.services\",\n" + " \"contact\" : {\n" + " \"name\" : \"Test Contact\",\n" + " \"url\" : \"https://test.contact.url\",\n" + " \"email\" : \"test@email.com\"\n" + " },\n" + " \"license\" : {\n" + " \"name\" : \"test license\",\n" + " \"url\" : \"https://test.license.com\",\n" + " \"identifier\" : \"swagger\"\n" + " },\n" + " \"version\" : \"1.0.0\"\n" + " }\n" + "}");
openAPI.setOpenapi("3.0.3");
SerializationMatchers.assertEqualsToYaml(openAPI, "openapi: 3.0.3\n" + "info:\n" + " title: Title test\n" + " description: This is a description for test\n" + " termsOfService: https://test.term.of.services\n" + " contact:\n" + " name: Test Contact\n" + " url: https://test.contact.url\n" + " email: test@email.com\n" + " license:\n" + " name: test license\n" + " url: https://test.license.com\n" + " version: 1.0.0");
SerializationMatchers.assertEqualsToJson(openAPI, "{\n" + " \"openapi\" : \"3.0.3\",\n" + " \"info\" : {\n" + " \"title\" : \"Title test\",\n" + " \"description\" : \"This is a description for test\",\n" + " \"termsOfService\" : \"https://test.term.of.services\",\n" + " \"contact\" : {\n" + " \"name\" : \"Test Contact\",\n" + " \"url\" : \"https://test.contact.url\",\n" + " \"email\" : \"test@email.com\"\n" + " },\n" + " \"license\" : {\n" + " \"name\" : \"test license\",\n" + " \"url\" : \"https://test.license.com\"\n" + " },\n" + " \"version\" : \"1.0.0\"\n" + " }\n" + "}");
}
Aggregations