Search in sources :

Example 1 with OpenAPI

use of org.eclipse.microprofile.openapi.models.OpenAPI 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();
    }
}
Also used : OpenAPIImpl(org.wildfly.swarm.microprofile.openapi.api.models.OpenAPIImpl) PathsImpl(org.wildfly.swarm.microprofile.openapi.api.models.PathsImpl) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) InfoImpl(org.wildfly.swarm.microprofile.openapi.api.models.info.InfoImpl)

Aggregations

OpenAPI (org.eclipse.microprofile.openapi.models.OpenAPI)1 OpenAPIImpl (org.wildfly.swarm.microprofile.openapi.api.models.OpenAPIImpl)1 PathsImpl (org.wildfly.swarm.microprofile.openapi.api.models.PathsImpl)1 InfoImpl (org.wildfly.swarm.microprofile.openapi.api.models.info.InfoImpl)1