public void process()

in fractions/swagger/src/main/java/org/wildfly/swarm/swagger/runtime/SwaggerArchivePreparer.java [91:199]


    public void process() {
        if (this.deploymentContext != null && this.deploymentContext.isImplicit()) {
            return;
        }

        // Append the JAX-RS application path to the context path (as the default value).
        // This value can always be overridden by the various settings in place.
        final String restApplicationPath = getRestApplicationPath();
        if (!restApplicationPath.isEmpty()) {
            String path = contextPath.get() + restApplicationPath;
            path = path.replaceAll("//", "/");
            if (!Objects.equals(contextPath.get(), path)) {
                contextPath.set(path);
            }
        }

        if (archive.getName().endsWith(".war")) {
            // Create a JAX-RS deployment archive
            WARArchive deployment = archive.as(WARArchive.class);
            deployment.addModule("io.swagger");

            // Make the deployment a swagger archive
            SwaggerArchive swaggerArchive = deployment.as(SwaggerArchive.class);
            // SWARM-1667: Add the custom CDI extension to the deployment to provide a workaround solution.
            deployment.addModule("org.wildfly.swarm.swagger", "deployment");
            deployment.addAsServiceProvider(Extension.class.getName(), "org.wildfly.swarm.swagger.deployment.SwaggerExtension");


            if (this.title != null) {
                swaggerArchive.setTitle(this.title);
            }

            if (this.description != null) {
                swaggerArchive.setDescription(this.description);
            }

            if (this.packages != null && !this.packages.isEmpty()) {
                swaggerArchive.setResourcePackages(this.packages.toArray(new String[this.packages.size()]));
            }

            if (this.tosUrl != null) {
                swaggerArchive.setTermsOfServiceUrl(this.tosUrl);
            }

            if (this.license != null) {
                swaggerArchive.setLicense(this.license);
            }

            if (this.licenseUrl != null) {
                swaggerArchive.setLicenseUrl(this.licenseUrl);
            }

            if (this.version != null) {
                swaggerArchive.setVersion(this.version);
            }

            if (this.schemes != null && !this.schemes.isEmpty()) {
                swaggerArchive.setSchemes(this.schemes.toArray(new String[this.schemes.size()]));
            }

            if (this.host != null) {
                swaggerArchive.setHost(this.host);
            }

            // If the context root has not been configured
            // get the context root from the deployment and tell swagger about it
            if (this.root != null) {
                swaggerArchive.setContextRoot(this.root);
            } else {
                if (!swaggerArchive.hasContextRoot()) {
                    if (deployment.getContextRoot() != null) {
                        String path = deployment.getContextRoot();
                        if (!restApplicationPath.isEmpty()) {
                            path = deployment.getContextRoot() + "/" + restApplicationPath;
                            path = path.replaceAll("/+", "/");
                        }
                        swaggerArchive.setContextRoot(path);
                    } else {
                        swaggerArchive.setContextRoot(contextPath.get());
                    }
                }
            }


            // If the archive has not been configured with packages for swagger to scan
            // try to be smart about it, and find the topmost package that's not in the
            // org.wildfly.swarm package space
            if (!swaggerArchive.hasResourcePackages()) {
                String[] packages = getPackagesForScanning(deployment).toArray(new String[0]);
                if (packages.length == 0) {
                    SwaggerMessages.MESSAGES.noEligiblePackages(archive.getName());
                } else {
                    if (packages.length == 1) {
                        SwaggerMessages.MESSAGES.configureSwaggerForPackage(archive.getName(), packages[0]);
                    } else {
                        SwaggerMessages.MESSAGES.configureSwaggerForSeveralPackages(archive.getName(), Arrays.asList(packages));
                    }
                    swaggerArchive.setResourcePackages(packages);
                }
            } else {
                SwaggerMessages.MESSAGES.configureSwaggerForSeveralPackages(archive.getName(),
                                                                            Arrays.asList(swaggerArchive.getResourcePackages()));
            }

            // Now add the swagger resources to our deployment
            deployment.addClass(io.swagger.jaxrs.listing.ApiListingResource.class);
            deployment.addClass(io.swagger.jaxrs.listing.SwaggerSerializers.class);
        }
    }