use of io.swagger.models.Info in project ballerina by ballerina-lang.
the class SwaggerServiceMapper method parseServiceInfoAnnotationAttachment.
/**
* Parses the 'ServiceInfo' annotation and build the swagger definition for it.
* @param service The ballerina service which has the 'ServiceInfo' annotation attachment.
* @param swagger The swagger definition to be built up.
*/
private void parseServiceInfoAnnotationAttachment(ServiceInfo service, Swagger swagger) {
AnnAttachmentInfo swaggerInfoAnnotation = service.getAnnotationAttachmentInfo(SwaggerConstants.SWAGGER_PACKAGE_PATH, "ServiceInfo");
Info info = new Info().version("1.0.0").title(service.getName());
if (null != swaggerInfoAnnotation) {
for (AnnAttributeKeyValuePair annAttributeKeyValuePair : swaggerInfoAnnotation.getAttributeKeyValuePairs()) {
if ("version".equals(annAttributeKeyValuePair.getAttributeName())) {
info.version(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("title".equals(annAttributeKeyValuePair.getAttributeName())) {
info.title(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("description".equals(annAttributeKeyValuePair.getAttributeName())) {
info.description(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("termsOfService".equals(annAttributeKeyValuePair.getAttributeName())) {
info.termsOfService(annAttributeKeyValuePair.getAttributeValue().getStringValue());
} else if ("contact".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createContactModel(annAttributeKeyValuePair.getAttributeValue(), info);
} else if ("license".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createLicenseModel(annAttributeKeyValuePair.getAttributeValue(), info);
} else if ("externalDoc".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createExternalDocModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
} else if ("tags".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createTagModel(annAttributeKeyValuePair.getAttributeValue(), swagger);
} else if ("organization".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createOrganizationModel(annAttributeKeyValuePair.getAttributeValue(), info);
} else if ("developers".equals(annAttributeKeyValuePair.getAttributeName())) {
this.createDevelopersModel(annAttributeKeyValuePair.getAttributeValue(), info);
}
}
}
swagger.setInfo(info);
}
use of io.swagger.models.Info in project endpoints-java by cloudendpoints.
the class SwaggerGenerator method writeSwagger.
private Swagger writeSwagger(Iterable<ApiConfig> configs, SwaggerContext context, GenerationContext genCtx) throws ApiConfigException {
ImmutableListMultimap<ApiKey, ? extends ApiConfig> configsByKey = FluentIterable.from(configs).index(CONFIG_TO_ROOTLESS_KEY);
Swagger swagger = new Swagger().produces("application/json").consumes("application/json").scheme(context.scheme).host(context.hostname).basePath(context.basePath).info(new Info().title(context.hostname).version(context.docVersion));
for (ApiKey apiKey : configsByKey.keySet()) {
writeApi(apiKey, configsByKey.get(apiKey), swagger, genCtx);
}
writeQuotaDefinitions(swagger, genCtx);
return swagger;
}
use of io.swagger.models.Info in project java-chassis by ServiceComb.
the class SwaggerDefinitionProcessor method convertInfo.
private Info convertInfo(io.swagger.annotations.Info infoAnnotation) {
if (infoAnnotation == null) {
return null;
}
Info info = new Info();
info.setTitle(infoAnnotation.title());
info.setVersion(infoAnnotation.version());
if (StringUtils.isNotEmpty(infoAnnotation.description())) {
info.setDescription(infoAnnotation.description());
}
if (StringUtils.isNotEmpty(infoAnnotation.termsOfService())) {
info.setTermsOfService(infoAnnotation.termsOfService());
}
info.setContact(convertContact(infoAnnotation.contact()));
info.setLicense(convertLicense(infoAnnotation.license()));
info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoAnnotation.extensions()));
return info;
}
use of io.swagger.models.Info in project camel by apache.
the class RestSwaggerSupport method initSwagger.
public void initSwagger(BeanConfig swaggerConfig, Map<String, Object> config) {
// configure swagger options
String s = (String) config.get("swagger.version");
if (s != null) {
swaggerConfig.setVersion(s);
}
s = (String) config.get("base.path");
if (s != null) {
swaggerConfig.setBasePath(s);
}
s = (String) config.get("host");
if (s != null) {
swaggerConfig.setHost(s);
}
s = (String) config.get("cors");
if (s != null) {
cors = "true".equalsIgnoreCase(s);
}
s = (String) config.get("schemes");
if (s == null) {
// deprecated due typo
s = (String) config.get("schemas");
}
if (s != null) {
String[] schemes = s.split(",");
swaggerConfig.setSchemes(schemes);
} else {
// assume http by default
swaggerConfig.setSchemes(new String[] { "http" });
}
String version = (String) config.get("api.version");
String title = (String) config.get("api.title");
String description = (String) config.get("api.description");
String termsOfService = (String) config.get("api.termsOfService");
String licenseName = (String) config.get("api.license.name");
String licenseUrl = (String) config.get("api.license.url");
String contactName = (String) config.get("api.contact.name");
String contactUrl = (String) config.get("api.contact.url");
String contactEmail = (String) config.get("api.contact.email");
Info info = new Info();
info.setVersion(version);
info.setTitle(title);
info.setDescription(description);
info.setTermsOfService(termsOfService);
if (licenseName != null || licenseUrl != null) {
License license = new License();
license.setName(licenseName);
license.setUrl(licenseUrl);
info.setLicense(license);
}
if (contactName != null || contactUrl != null || contactEmail != null) {
Contact contact = new Contact();
contact.setName(contactName);
contact.setUrl(contactUrl);
contact.setEmail(contactEmail);
info.setContact(contact);
}
swaggerConfig.setInfo(info);
}
use of io.swagger.models.Info 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);
}
Aggregations