use of org.wildfly.swarm.microprofile.openapi.api.models.PathsImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiDocument method initialize.
public void initialize() {
synchronized (INSTANCE) {
if (model != null) {
modelAlreadyInitialized();
}
// Check all the required parts are set
if (config == null) {
throw new IllegalStateException("OpenApiConfig must be set before init");
}
// Phase 1: Use OASModelReader
OpenAPI merged = readerModel;
// Phase 2: Merge any static OpenAPI file packaged in the app
merged = MergeUtil.mergeObjects(merged, staticFileModel);
// Phase 3: Merge annotations
merged = MergeUtil.mergeObjects(merged, annotationsModel);
// Phase 4: Filter model via OASFilter
merged = filterModel(merged);
// Phase 5: Default empty document if model == null
if (merged == null) {
merged = new OpenAPIImpl();
merged.setOpenapi(OpenApiConstants.OPEN_API_VERSION);
}
// Phase 6: Provide missing required elements
if (merged.getPaths() == null) {
merged.setPaths(new PathsImpl());
}
if (merged.getInfo() == null) {
merged.setInfo(new InfoImpl());
}
if (merged.getInfo().getTitle() == null) {
merged.getInfo().setTitle((archiveName == null ? "Generated" : archiveName) + " API");
}
if (merged.getInfo().getVersion() == null) {
merged.getInfo().setVersion("1.0");
}
// Phase 7: Use Config values to add Servers (global, pathItem, operation)
ServersUtil.configureServers(config, merged);
model = merged;
LOGGER.info("OpenAPI document initialized: " + model);
clear();
}
}
use of org.wildfly.swarm.microprofile.openapi.api.models.PathsImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method scan.
/**
* Scan the deployment for relevant annotations. Returns an OpenAPI data model that was
* built from those found annotations.
*/
public OpenAPIImpl scan() {
LOG.debug("Scanning deployment for OpenAPI and JAX-RS Annotations.");
// Initialize a new OAI document. Even if nothing is found, this will be returned.
oai = new OpenAPIImpl();
oai.setOpenapi(OpenApiConstants.OPEN_API_VERSION);
// Get all jax-rs applications and convert them to OAI models (and merge them into a single one)
Collection<ClassInfo> applications = this.index.getAllKnownSubclasses(DotName.createSimple(Application.class.getName()));
for (ClassInfo classInfo : applications) {
oai = MergeUtil.merge(oai, jaxRsApplicationToOpenApi(classInfo));
}
// TODO find all OpenAPIDefinition annotations at the package level
// Now find all jax-rs endpoints
Collection<ClassInfo> resourceClasses = JandexUtil.getJaxRsResourceClasses(this.index);
for (ClassInfo resourceClass : resourceClasses) {
processJaxRsResourceClass(oai, resourceClass);
}
// Now that all paths have been created, sort them (we don't have a better way to organize them).
if (oai != null) {
Paths paths = oai.getPaths();
if (paths != null) {
Paths sortedPaths = new PathsImpl();
TreeSet<String> sortedKeys = new TreeSet<>(paths.keySet());
for (String pathKey : sortedKeys) {
PathItem pathItem = paths.get(pathKey);
sortedPaths.addPathItem(pathKey, pathItem);
}
sortedPaths.setExtensions(paths.getExtensions());
oai.setPaths(sortedPaths);
}
}
return oai;
}
use of org.wildfly.swarm.microprofile.openapi.api.models.PathsImpl in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readPaths.
/**
* Reads the {@link Paths} OpenAPI nodes.
* @param node
*/
private Paths readPaths(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
PathsImpl model = new PathsImpl();
for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
String fieldName = fieldNames.next();
if (fieldName.startsWith(OpenApiConstants.EXTENSION_PROPERTY_PREFIX)) {
continue;
}
model.addPathItem(fieldName, readPathItem(node.get(fieldName)));
}
readExtensions(node, model);
return model;
}
Aggregations