Search in sources :

Example 1 with DepthFirstVisitor

use of com.manydesigns.portofino.dispatcher.visitor.DepthFirstVisitor in project Portofino by ManyDesigns.

the class DocumentedApiRoot method afterScan.

@Override
public void afterScan(OpenApiReader reader, OpenAPI openAPI) {
    final SubResourceReader subResourceReader = getSubResourceReader(openAPI);
    try {
        // TODO actions should be put in a special "inspection mode" to avoid checks (e.g. not-in-use-case),
        // hitting the DB or services, etc.
        Resource root = rootFactory.createRoot();
        root.setResourceContext(getResourceContext());
        initRoot(root);
        if (openAPI.getPaths() == null) {
            openAPI.setPaths(new Paths());
        }
        new DepthFirstVisitor(node -> {
            try {
                OpenAPI subApi = subResourceReader.readSubResource(node);
                openAPI.getPaths().putAll(subApi.getPaths());
            // TODO merge components too
            } catch (Exception e) {
                logger.error("Could not read node at " + node.getLocation(), e);
            }
        }).visit(root);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ReaderListener(io.swagger.v3.jaxrs2.ReaderListener) WithParameters(com.manydesigns.portofino.dispatcher.WithParameters) DepthFirstVisitor(com.manydesigns.portofino.dispatcher.visitor.DepthFirstVisitor) Logger(org.slf4j.Logger) Reader(io.swagger.v3.jaxrs2.Reader) Parameter(io.swagger.v3.oas.models.parameters.Parameter) LoggerFactory(org.slf4j.LoggerFactory) RootFactory(com.manydesigns.portofino.dispatcher.RootFactory) Paths(io.swagger.v3.oas.models.Paths) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ResourceContext(javax.ws.rs.container.ResourceContext) Resource(com.manydesigns.portofino.dispatcher.Resource) OpenApiReader(io.swagger.v3.oas.integration.api.OpenApiReader) PathParameter(io.swagger.v3.oas.models.parameters.PathParameter) Resource(com.manydesigns.portofino.dispatcher.Resource) DepthFirstVisitor(com.manydesigns.portofino.dispatcher.visitor.DepthFirstVisitor) Paths(io.swagger.v3.oas.models.Paths) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Aggregations

Resource (com.manydesigns.portofino.dispatcher.Resource)1 RootFactory (com.manydesigns.portofino.dispatcher.RootFactory)1 WithParameters (com.manydesigns.portofino.dispatcher.WithParameters)1 DepthFirstVisitor (com.manydesigns.portofino.dispatcher.visitor.DepthFirstVisitor)1 Reader (io.swagger.v3.jaxrs2.Reader)1 ReaderListener (io.swagger.v3.jaxrs2.ReaderListener)1 OpenApiReader (io.swagger.v3.oas.integration.api.OpenApiReader)1 OpenAPI (io.swagger.v3.oas.models.OpenAPI)1 Paths (io.swagger.v3.oas.models.Paths)1 Parameter (io.swagger.v3.oas.models.parameters.Parameter)1 PathParameter (io.swagger.v3.oas.models.parameters.PathParameter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ResourceContext (javax.ws.rs.container.ResourceContext)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1