io.swagger.v3.oas.integration.OpenApiConfigurationException Java Examples

The following examples show how to use io.swagger.v3.oas.integration.OpenApiConfigurationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bootstrap.java    From submarine with Apache License 2.0 5 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {

  OpenAPI oas = new OpenAPI();
  Info info = new Info()
           .title("Submarine Experiment API")
           .description("The Submarine REST API allows you to create, list, and get experiments. The\n" +
                   "API is hosted under the /v1/experiment route on the Submarine server. For example,\n" +
                   "to list experiments on a server hosted at http://localhost:8080, access\n" +
                   "http://localhost:8080/api/v1/experiment/")
           .termsOfService("http://swagger.io/terms/")
           .contact(new Contact()
           .email("[email protected]"))
           .version("0.4.0")
           .license(new License()
           .name("Apache 2.0")
           .url("http://www.apache.org/licenses/LICENSE-2.0.html"));

  oas.info(info);
  List<Server> servers = new ArrayList<>();
  servers.add(new Server().url("/api"));
  oas.servers(servers);
  SwaggerConfiguration oasConfig = new SwaggerConfiguration()
          .openAPI(oas)
          .resourcePackages(Stream.of("org.apache.submarine.server.rest").collect(Collectors.toSet()));

  try {
    new JaxrsOpenApiContextBuilder()
            .servletConfig(config)
            .openApiConfiguration(oasConfig)
            .buildContext(true);
  } catch (OpenApiConfigurationException e) {
    throw new ServletException(e.getMessage(), e);
  }
}
 
Example #2
Source File: SwaggerServiceImpl.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
private OpenAPI buildOpenApi() {
    try {
        restfulServices = getAllRestfulService();
        SwaggerConfiguration oasConfig = new SwaggerConfiguration().resourceClasses(restfulServices);

        OpenApiContext oac = new JaxrsOpenApiContextBuilder()
            .openApiConfiguration(oasConfig)
            .buildContext(true);
        return oac.read();
    } catch (OpenApiConfigurationException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
Example #3
Source File: MCRRestV2App.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private void setupOAS() {
    OpenAPI oas = new OpenAPI();
    Info oasInfo = new Info();
    oas.setInfo(oasInfo);
    oasInfo.setVersion(MCRCoreVersion.getVersion());
    oasInfo.setTitle(getApplicationName());
    License oasLicense = new License();
    oasLicense.setName("GNU General Public License, version 3");
    oasLicense.setUrl("http://www.gnu.org/licenses/gpl-3.0.txt");
    oasInfo.setLicense(oasLicense);
    URI baseURI = URI.create(MCRFrontendUtil.getBaseURL());
    Server oasServer = new Server();
    oasServer.setUrl(baseURI.resolve("api").toString());
    oas.addServersItem(oasServer);
    SwaggerConfiguration oasConfig = new SwaggerConfiguration()
        .openAPI(oas)
        .resourcePackages(Stream.of(getRestPackages()).collect(Collectors.toSet()))
        .ignoredRoutes(
            MCRConfiguration2.getString("MCR.RestAPI.V2.OpenAPI.IgnoredRoutes")
                .map(MCRConfiguration2::splitValue)
                .orElseGet(Stream::empty)
                .collect(Collectors.toSet()))
        .prettyPrint(true);
    try {
        new JaxrsOpenApiContextBuilder()
            .application(getApplication())
            .openApiConfiguration(oasConfig)
            .buildContext(true);
    } catch (OpenApiConfigurationException e) {
        throw new InternalServerErrorException(e);
    }
}
 
Example #4
Source File: JaxRsActivatorNew.java    From pnc with Apache License 2.0 5 votes vote down vote up
private void configureSwagger() {
    OpenAPI oas = new OpenAPI();
    Info info = new Info().title("PNC")
            .description("PNC build system")
            .termsOfService("http://swagger.io/terms/")
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    oas.info(info);
    oas.addServersItem(new Server().url("/pnc-rest-new"));

    final SecurityScheme authScheme = getAuthScheme();
    if (authScheme == null) {
        logger.warn("Not adding auth scheme to openapi definition as auth scheme could not been generated.");
    } else {
        oas.schemaRequirement(KEYCLOAK_AUTH, authScheme);
        oas.addSecurityItem(new SecurityRequirement().addList(KEYCLOAK_AUTH));
    }

    SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);

    try {
        new JaxrsOpenApiContextBuilder().servletConfig(servletConfig)
                .application(this)
                .openApiConfiguration(oasConfig)
                .buildContext(true);
    } catch (OpenApiConfigurationException ex) {
        throw new IllegalArgumentException("Failed to setup OpenAPI configuration", ex);
    }
}
 
Example #5
Source File: OpenApiFeature.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean)server
            .getEndpoint()
            .get(JAXRSServiceFactoryBean.class.getName());

    final ServerProviderFactory factory = (ServerProviderFactory)server
            .getEndpoint()
            .get(ServerProviderFactory.class.getName());

    final Set<String> packages = new HashSet<>();
    if (resourcePackages != null) {
        packages.addAll(resourcePackages);
    }

    // Generate random Context ID for Swagger
    if (useContextBasedConfig) {
        ctxId = UUID.randomUUID().toString();
    }

    Properties swaggerProps = null;
    GenericOpenApiContextBuilder<?> openApiConfiguration;
    final Application application = DefaultApplicationFactory.createApplicationOrDefault(server, factory,
            sfb, bus, resourcePackages, isScan());

    String defaultConfigLocation = getConfigLocation();
    if (scanKnownConfigLocations && StringUtils.isEmpty(defaultConfigLocation)) {
        defaultConfigLocation = OpenApiDefaultConfigurationScanner.locateDefaultConfiguration().orElse(null);
    }

    if (StringUtils.isEmpty(defaultConfigLocation)) {
        swaggerProps = getSwaggerProperties(propertiesLocation, bus);

        if (isScan()) {
            packages.addAll(scanResourcePackages(sfb));
        }

        final OpenAPI oas = new OpenAPI().info(getInfo(swaggerProps));
        registerComponents(securityDefinitions).ifPresent(oas::setComponents);

        final SwaggerConfiguration config = new SwaggerConfiguration()
                .openAPI(oas)
                .prettyPrint(getOrFallback(isPrettyPrint(), swaggerProps, PRETTY_PRINT_PROPERTY))
                .readAllResources(isReadAllResources())
                .ignoredRoutes(getIgnoredRoutes())
                .filterClass(getOrFallback(getFilterClass(), swaggerProps, FILTER_CLASS_PROPERTY))
                .resourceClasses(getResourceClasses())
                .resourcePackages(getOrFallback(packages, swaggerProps, RESOURCE_PACKAGE_PROPERTY));
        
        if (!StringUtils.isEmpty(getScannerClass())) {
            config.setScannerClass(getScannerClass());
        }

        openApiConfiguration = new JaxrsOpenApiContextBuilder<>()
                .application(application)
                .openApiConfiguration(config)
                .ctxId(ctxId); /* will be null if not used */
    } else {
        openApiConfiguration = new JaxrsOpenApiContextBuilder<>()
                .application(application)
                .configLocation(defaultConfigLocation)
                .ctxId(ctxId); /* will be null if not used */
    }

    try {
        final OpenApiContext context = openApiConfiguration.buildContext(true);
        final Properties userProperties = getUserProperties(
                context
                        .getOpenApiConfiguration()
                        .getUserDefinedOptions());
        registerOpenApiResources(sfb, packages, context.getOpenApiConfiguration());
        registerSwaggerUiResources(sfb, combine(swaggerProps, userProperties), factory, bus);
        registerSwaggerContainerRequestFilter(factory, application);

        if (useContextBasedConfig) {
            registerServletConfigProvider(factory);
        }

        if (customizer != null) {
            customizer.setApplicationInfo(factory.getApplicationProvider());
        }

        bus.setProperty("openapi.service.description.available", "true");
    } catch (OpenApiConfigurationException ex) {
        throw new RuntimeException("Unable to initialize OpenAPI context", ex);
    }
}