use of io.swagger.models.Info in project swagger-core by swagger-api.
the class WebXMLReader method configure.
@Override
public Swagger configure(Swagger swagger) {
if (swagger != null) {
Info info = swagger.getInfo();
if (info == null) {
swagger.info(new Info());
}
swagger.basePath(basePath).host(host).getInfo().title(title).version(apiVersion);
for (String scheme : this.schemes) {
swagger.scheme(Scheme.forValue(scheme));
}
}
return swagger;
}
use of io.swagger.models.Info in project vertx-swagger by bobxwang.
the class SwaggerApp method initSwagger.
private static synchronized void initSwagger(final Environment environment) {
if (swagger == null) {
swagger = new Swagger();
swagger.setSwagger("2.0");
String value = environment.getProperty("swagger.scanner.path");
if (Strings.isNullOrEmpty(value)) {
throw new RuntimeException("请配置好swagger扫描路径");
}
RouteScanner scanner;
if (value.contains(";")) {
scanner = new RouteScanner(Arrays.asList(value.split(";")));
} else {
scanner = new RouteScanner(value);
}
Info info = new Info();
info.title(environment.getProperty("server.description", "")).version("1.0.0");
swagger.info(info);
Reader.read(swagger, scanner.classes());
}
}
use of io.swagger.models.Info in project swagger-parser by swagger-api.
the class ResourceListingConverterTest method convertResourceListingWithRootPath.
@Test
public void convertResourceListingWithRootPath() throws Exception {
ResourceListing rl = new ResourceListing();
rl.setApiVersion("2.11");
List<ApiDeclaration> apis = new ArrayList<ApiDeclaration>();
ApiDeclaration api = new ApiDeclaration();
api.setBasePath("http://foo.com");
apis.add(api);
Swagger swagger = converter.convert(rl, apis);
assertTrue(swagger.getSchemes().size() == 1);
assertTrue(swagger.getSwagger().equals("2.0"));
Info info = swagger.getInfo();
assertNotNull(info);
assertEquals(info.getVersion(), rl.getApiVersion());
assertEquals(swagger.getBasePath(), "/");
assertEquals(swagger.getHost(), "foo.com");
}
use of io.swagger.models.Info in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateCompositeApiFromSwaggerResource.
@Override
public CompositeAPI.Builder generateCompositeApiFromSwaggerResource(String provider, String apiDefinition) throws APIManagementException {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(apiDefinition);
if (swagger == null) {
throw new APIManagementException("Swagger could not be generated from provided API definition");
}
Info apiInfo = swagger.getInfo();
if (apiInfo == null) {
throw new APIManagementException("Provided Swagger definition doesn't contain API information");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().provider(provider).name(apiName).version(apiVersion).description(apiDescription).context(swagger.getBasePath());
List<APIResource> apiResourceList = parseSwaggerAPIResources(new StringBuilder(apiDefinition));
Map<String, UriTemplate> uriTemplateMap = new HashMap();
for (APIResource apiResource : apiResourceList) {
uriTemplateMap.put(apiResource.getUriTemplate().getTemplateId(), apiResource.getUriTemplate());
}
apiBuilder.uriTemplates(uriTemplateMap);
apiBuilder.id(UUID.randomUUID().toString());
return apiBuilder;
}
}
use of io.swagger.models.Info in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateSwaggerFromResources.
@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
Swagger swagger = new Swagger();
Info info = new Info();
info.setTitle(api.getName());
info.setDescription(api.getDescription());
info.setVersion(api.getVersion());
swagger.setInfo(info);
Map<String, Path> stringPathMap = new HashMap();
for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
String uriTemplateString = uriTemplate.getUriTemplate();
List<Parameter> parameterList = getParameters(uriTemplateString);
if (!HttpMethod.GET.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.DELETE.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.OPTIONS.toString().equalsIgnoreCase(uriTemplate.getHttpVerb()) && !HttpMethod.HEAD.toString().equalsIgnoreCase(uriTemplate.getHttpVerb())) {
parameterList.add(getDefaultBodyParameter());
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.setOperationId(uriTemplate.getTemplateId());
operation.addResponse("200", getDefaultResponse());
if (stringPathMap.containsKey(uriTemplateString)) {
Path path = stringPathMap.get(uriTemplateString);
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
} else {
Path path = new Path();
path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
stringPathMap.put(uriTemplateString, path);
}
}
swagger.setPaths(stringPathMap);
swagger.setPaths(stringPathMap);
return Json.pretty(swagger);
}
Aggregations