Search in sources :

Example 1 with OpenAPIConfigBuilder

use of io.swagger.v3.oas.integration.api.OpenAPIConfigBuilder in project swagger-core by swagger-api.

the class ServletOpenApiConfigurationLoader method load.

@Override
public OpenAPIConfiguration load(String path) throws IOException {
    if (servletConfig == null) {
        return null;
    }
    if (StringUtils.isBlank(path)) {
        // we want to resolve from servlet params
        SwaggerConfiguration configuration = new SwaggerConfiguration().resourcePackages(resolveResourcePackages(servletConfig)).filterClass(getInitParam(servletConfig, OPENAPI_CONFIGURATION_FILTER_KEY)).resourceClasses(resolveResourceClasses(servletConfig)).readAllResources(getBooleanInitParam(servletConfig, OPENAPI_CONFIGURATION_READALLRESOURCES_KEY)).prettyPrint(getBooleanInitParam(servletConfig, OPENAPI_CONFIGURATION_PRETTYPRINT_KEY)).sortOutput(getBooleanInitParam(servletConfig, OPENAPI_CONFIGURATION_SORTOUTPUT_KEY)).alwaysResolveAppPath(getBooleanInitParam(servletConfig, OPENAPI_CONFIGURATION_ALWAYSRESOLVEAPPPATH_KEY)).readerClass(getInitParam(servletConfig, OPENAPI_CONFIGURATION_READER_KEY)).cacheTTL(getLongInitParam(servletConfig, OPENAPI_CONFIGURATION_CACHE_TTL_KEY)).scannerClass(getInitParam(servletConfig, OPENAPI_CONFIGURATION_SCANNER_KEY)).objectMapperProcessorClass(getInitParam(servletConfig, OPENAPI_CONFIGURATION_OBJECT_MAPPER_PROCESSOR_KEY)).modelConverterClasses(resolveModelConverterClasses(servletConfig));
        return configuration;
    }
    String location = ServletConfigContextUtils.getInitParam(servletConfig, path);
    if (!StringUtils.isBlank(location)) {
        if (classpathOpenApiConfigurationLoader.exists(location)) {
            return classpathOpenApiConfigurationLoader.load(location);
        } else if (fileOpenApiConfigurationLoader.exists(location)) {
            return fileOpenApiConfigurationLoader.load(location);
        }
    }
    String builderClassName = getInitParam(servletConfig, OPENAPI_CONFIGURATION_BUILDER_KEY);
    if (StringUtils.isNotBlank(builderClassName)) {
        try {
            Class cls = getClass().getClassLoader().loadClass(builderClassName);
            // TODO instantiate with configuration
            OpenAPIConfigBuilder builder = (OpenAPIConfigBuilder) cls.newInstance();
            return builder.build();
        } catch (Exception e) {
            LOGGER.error("error loading builder: " + e.getMessage(), e);
        }
    }
    return null;
}
Also used : OpenAPIConfigBuilder(io.swagger.v3.oas.integration.api.OpenAPIConfigBuilder) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) IOException(java.io.IOException)

Aggregations

SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)1 OpenAPIConfigBuilder (io.swagger.v3.oas.integration.api.OpenAPIConfigBuilder)1 IOException (java.io.IOException)1