use of io.swagger.models.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 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 Swagger swagger = new Swagger().info(info).host("petstore.swagger.io").scheme(Scheme.HTTP).consumes("application/json").produces("application/json").model("Person", personModel).model("Error", errorModel);
swagger.securityDefinition("githubAccessCode", new OAuth2Definition().accessCode("http://foo.com/accessCode", "http://foo.com/tokenUrl").scope("user:email", "Grants read access to a user’s email addresses."));
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");
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"));
final Response errorResponse = new Response().description("error response").schema(new RefProperty().asDefault("Error"));
get.response(200, response).defaultResponse(errorResponse).security(new SecurityRequirement("internal_oauth2").scope("user:email")).security(new SecurityRequirement("api_key"));
swagger.path("/pets", new Path().get(get));
final String json = ResourceUtils.loadClassResource(getClass(), "ModelWithSecurityRequirements.json");
SerializationMatchers.assertEqualsToJson(swagger, json);
}
use of io.swagger.models.Contact in project swagger-core by swagger-api.
the class Reader method readInfoConfig.
protected void readInfoConfig(SwaggerDefinition config) {
Info infoConfig = config.info();
io.swagger.models.Info info = swagger.getInfo();
if (info == null) {
info = new io.swagger.models.Info();
swagger.setInfo(info);
}
if (!infoConfig.description().isEmpty()) {
info.setDescription(infoConfig.description());
}
if (!infoConfig.termsOfService().isEmpty()) {
info.setTermsOfService(infoConfig.termsOfService());
}
if (!infoConfig.title().isEmpty()) {
info.setTitle(infoConfig.title());
}
if (!infoConfig.version().isEmpty()) {
info.setVersion(infoConfig.version());
}
if (!infoConfig.contact().name().isEmpty()) {
Contact contact = info.getContact();
if (contact == null) {
contact = new Contact();
info.setContact(contact);
}
contact.setName(infoConfig.contact().name());
if (!infoConfig.contact().email().isEmpty()) {
contact.setEmail(infoConfig.contact().email());
}
if (!infoConfig.contact().url().isEmpty()) {
contact.setUrl(infoConfig.contact().url());
}
}
if (!infoConfig.license().name().isEmpty()) {
License license = info.getLicense();
if (license == null) {
license = new License();
info.setLicense(license);
}
license.setName(infoConfig.license().name());
if (!infoConfig.license().url().isEmpty()) {
license.setUrl(infoConfig.license().url());
}
}
info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoConfig.extensions()));
}
use of io.swagger.models.Contact in project swagger-core by swagger-api.
the class Reader method readInfoConfig.
private void readInfoConfig(SwaggerDefinition config) {
final Info infoConfig = config.info();
io.swagger.models.Info info = swagger.getInfo();
if (info == null) {
info = new io.swagger.models.Info();
swagger.setInfo(info);
}
if (StringUtils.isNotBlank(infoConfig.description())) {
info.setDescription(infoConfig.description());
}
if (StringUtils.isNotBlank(infoConfig.termsOfService())) {
info.setTermsOfService(infoConfig.termsOfService());
}
if (StringUtils.isNotBlank(infoConfig.title())) {
info.setTitle(infoConfig.title());
}
if (StringUtils.isNotBlank(infoConfig.version())) {
info.setVersion(infoConfig.version());
}
if (StringUtils.isNotBlank(infoConfig.contact().name())) {
Contact contact = info.getContact();
if (contact == null) {
contact = new Contact();
info.setContact(contact);
}
contact.setName(infoConfig.contact().name());
if (StringUtils.isNotBlank(infoConfig.contact().email())) {
contact.setEmail(infoConfig.contact().email());
}
if (StringUtils.isNotBlank(infoConfig.contact().url())) {
contact.setUrl(infoConfig.contact().url());
}
}
if (StringUtils.isNotBlank(infoConfig.license().name())) {
License license = info.getLicense();
if (license == null) {
license = new License();
info.setLicense(license);
}
license.setName(infoConfig.license().name());
if (StringUtils.isNotBlank(infoConfig.license().url())) {
license.setUrl(infoConfig.license().url());
}
}
info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoConfig.extensions()));
}
Aggregations