use of io.swagger.models.Contact in project java-chassis by ServiceComb.
the class SwaggerDefinitionProcessor method convertContact.
private Contact convertContact(io.swagger.annotations.Contact contactAnnotation) {
Contact contact = new Contact();
contact.setName(contactAnnotation.name());
contact.setUrl(contactAnnotation.url());
contact.setEmail(contactAnnotation.email());
return contact;
}
use of io.swagger.models.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 Model personModel = ModelConverters.getInstance().read(Person.class).get("Person");
final Model 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.setVendorExtension("x-test2", map);
info.setVendorExtension("x-test", "value");
final Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").deprecated(true);
get.parameter(new QueryParameter().name("tags").description("tags to filter by").required(false).property(new StringProperty()));
get.parameter(new PathParameter().name("petId").description("pet to fetch").property(new LongProperty()));
final Response response = new Response().description("pets returned").schema(new RefProperty().asDefault("Person")).example("application/json", "fun!");
final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
get.response(200, response).defaultResponse(errorResponse);
final Operation post = new Operation().summary("adds a new pet").description("you can add a new pet this way").tag("Pet Operations").operationId("add pet").defaultResponse(errorResponse).parameter(new BodyParameter().description("the pet to add").schema(new RefModel().asDefault("Person")));
swagger.path("/pets", new Path().get(get).post(post));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
SerializationMatchers.assertEqualsToJson(rebuilt, swaggerJson);
}
use of io.swagger.models.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 Model 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 Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").securityDefinition("api-key", new ApiKeyAuthDefinition("key", In.HEADER)).scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel);
final QueryParameter parameter = new QueryParameter().name("id").description("a common get parameter").property(new LongProperty());
final Operation get = new Operation().produces("application/json").summary("finds pets in the system").description("a longer description").tag("Pet Operations").operationId("get pet by id").parameter(new RefParameter("foo"));
swagger.parameter("foo", parameter).path("/pets", new Path().get(get));
final String swaggerJson = Json.mapper().writeValueAsString(swagger);
final Swagger rebuilt = Json.mapper().readValue(swaggerJson, Swagger.class);
assertEquals(Json.pretty(swagger), Json.pretty(rebuilt));
}
use of io.swagger.models.Contact in project swagger-core by swagger-api.
the class BeanConfig method updateInfoFromConfig.
private void updateInfoFromConfig() {
info = getSwagger().getInfo();
if (info == null) {
info = new Info();
}
if (StringUtils.isNotBlank(description)) {
info.description(description);
}
if (StringUtils.isNotBlank(title)) {
info.title(title);
}
if (StringUtils.isNotBlank(version)) {
info.version(version);
}
if (StringUtils.isNotBlank(termsOfServiceUrl)) {
info.termsOfService(termsOfServiceUrl);
}
if (contact != null) {
this.info.contact(new Contact().name(contact));
}
if (license != null && licenseUrl != null) {
this.info.license(new License().name(license).url(licenseUrl));
}
if (schemes != null) {
for (String scheme : schemes) {
reader.getSwagger().scheme(Scheme.forValue(scheme));
}
}
reader.getSwagger().setInfo(info);
}
use of io.swagger.models.Contact in project apiee by phillip-kruger.
the class SwaggerCache method getSwaggerContact.
private Contact getSwaggerContact() {
String name = whiteLabel.getProperty(INFO_CONTACT_NAME, null);
String email = whiteLabel.getProperty(INFO_CONTACT_EMAIL, null);
String url = whiteLabel.getProperty(INFO_CONTACT_URL, null);
if (isSet(name, email, url)) {
Contact contact = new Contact();
if (isSet(email))
contact.setEmail(email);
if (isSet(name))
contact.setName(name);
if (isSet(url))
contact.setUrl(url);
return contact;
}
return null;
}
Aggregations