handlebars.JavaJaxRS.resteasy.eap.RestApplication.mustache Maven / Gradle / Ivy
package {{invokerPackage}};
{{#jakarta}}
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import jakarta.servlet.ServletConfig;
import jakarta.ws.rs.core.Context;
{{/jakarta}}
{{^jakarta}}
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import javax.servlet.ServletConfig;
import javax.ws.rs.core.Context;
{{/jakarta}}
import java.util.Set;
import java.util.HashSet;
{{#useSwaggerFeature}}
{{#useOas2}}
import io.swagger.jaxrs.config.BeanConfig;
{{/useOas2}}
{{^useOas2}}
import io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder;
import io.swagger.v3.oas.integration.OpenApiConfigurationException;
import io.swagger.v3.oas.integration.SwaggerConfiguration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import java.util.stream.Collectors;
import java.util.stream.Stream;
{{/useOas2}}
{{/useSwaggerFeature}}
{{#apiInfo}}
{{#apis}}
import {{package}}.impl.{{classname}}ServiceImpl;
{{/apis}}
{{/apiInfo}}
@ApplicationPath("/")
public class RestApplication extends Application {
{{#useSwaggerFeature}}
{{#useOas2}}
public RestApplication() {
super();
// Customize the dynamic contract
BeanConfig beanConfig = new BeanConfig();
beanConfig.setTitle("{{appName}}");
beanConfig.setVersion("{{version}}");
beanConfig.setSchemes(new String[] { "{{scheme}}" });
beanConfig.setHost("{{host}}");
beanConfig.setBasePath("{{basePathWithoutHost}}");
beanConfig.setResourcePackage("{{invokerPackage}}");
beanConfig.setScan(true);
}
{{/useOas2}}
{{^useOas2}}
public RestApplication(@Context ServletConfig servletConfig) {
super();
OpenAPI oas = new OpenAPI();
Info info = new Info()
.title("{{appName}}")
.version("{{version}}");
oas.info(info);
SwaggerConfiguration oasConfig = new SwaggerConfiguration()
.openAPI(oas)
.prettyPrint(true)
.resourcePackages(Stream.of("{{invokerPackage}}").collect(Collectors.toSet()))
.readAllResources(true);
try {
new JaxrsOpenApiContextBuilder()
.servletConfig(servletConfig)
.application(this)
.openApiConfiguration(oasConfig)
.buildContext(true);
} catch (final OpenApiConfigurationException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
{{/useOas2}}
{{/useSwaggerFeature}}
public Set> getClasses() {
Set> resources = new HashSet>();
{{#apiInfo}}
{{#apis}}
resources.add({{classname}}ServiceImpl.class);
{{/apis}}
{{/apiInfo}}
{{#useSwaggerFeature}}
{{#useOas2}}
resources.add(io.swagger.jaxrs.listing.ApiListingResource.class);
resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
{{/useOas2}}
{{/useSwaggerFeature}}
return resources;
}
}