Search in sources :

Example 6 with Info

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;
}
Also used : Info(io.swagger.models.Info)

Example 7 with Info

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());
    }
}
Also used : Swagger(io.swagger.models.Swagger) RouteScanner(com.bob.vertx.swagger.RouteScanner) Info(io.swagger.models.Info)

Example 8 with Info

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");
}
Also used : ApiDeclaration(io.swagger.models.apideclaration.ApiDeclaration) ResourceListing(io.swagger.models.resourcelisting.ResourceListing) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) Info(io.swagger.models.Info) Test(org.testng.annotations.Test)

Example 9 with Info

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;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) APIResource(org.wso2.carbon.apimgt.core.models.APIResource) Info(io.swagger.models.Info) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) SwaggerParser(io.swagger.parser.SwaggerParser) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Swagger(io.swagger.models.Swagger) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI)

Example 10 with Info

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);
}
Also used : Path(io.swagger.models.Path) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Swagger(io.swagger.models.Swagger) FormParameter(io.swagger.models.parameters.FormParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) Operation(io.swagger.models.Operation) Info(io.swagger.models.Info) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate)

Aggregations

Info (io.swagger.models.Info)39 Swagger (io.swagger.models.Swagger)26 Contact (io.swagger.models.Contact)12 Operation (io.swagger.models.Operation)10 Path (io.swagger.models.Path)9 Test (org.testng.annotations.Test)8 License (io.swagger.models.License)7 QueryParameter (io.swagger.models.parameters.QueryParameter)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 ApiKeyAuthDefinition (io.swagger.models.auth.ApiKeyAuthDefinition)5 PathParameter (io.swagger.models.parameters.PathParameter)5 Model (io.swagger.models.Model)4 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)4 Parameter (io.swagger.models.parameters.Parameter)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)4 ServiceMethodInfo (org.wso2.msf4j.ServiceMethodInfo)4 Response (io.swagger.models.Response)3 Scheme (io.swagger.models.Scheme)3