Java Code Examples for org.eclipse.microprofile.openapi.models.PathItem

The following examples show how to use org.eclipse.microprofile.openapi.models.PathItem. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: smallrye-open-api   Source File: ServersUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static final void configureServers(OpenApiConfig config, OpenAPI oai) {
    // Start with the global servers.
    Set<String> servers = config.servers();
    if (servers != null && !servers.isEmpty()) {
        oai.servers(new ArrayList<>());
        for (String server : servers) {
            Server s = new ServerImpl();
            s.setUrl(server);
            oai.addServer(s);
        }
    }

    // Now the PathItem and Operation servers
    Map<String, PathItem> pathItems = oai.getPaths().getPathItems();
    if (pathItems != null) {
        pathItems.entrySet().forEach(entry -> configureServers(config, entry.getKey(), entry.getValue()));
    }
}
 
Example 2
Source Project: smallrye-open-api   Source File: ServersUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Configures the servers for a PathItem.
 * 
 * @param config OpenApiConfig
 * @param pathName String representing the pathName
 * @param pathItem String representing the pathItem
 */
protected static void configureServers(OpenApiConfig config, String pathName, PathItem pathItem) {
    if (pathItem == null) {
        return;
    }

    Set<String> pathServers = config.pathServers(pathName);
    if (pathServers != null && !pathServers.isEmpty()) {
        pathItem.servers(new ArrayList<>());
        for (String pathServer : pathServers) {
            Server server = new ServerImpl();
            server.setUrl(pathServer);
            pathItem.addServer(server);
        }
    }

    configureServers(config, pathItem.getGET());
    configureServers(config, pathItem.getPUT());
    configureServers(config, pathItem.getPOST());
    configureServers(config, pathItem.getDELETE());
    configureServers(config, pathItem.getHEAD());
    configureServers(config, pathItem.getOPTIONS());
    configureServers(config, pathItem.getPATCH());
    configureServers(config, pathItem.getTRACE());
}
 
Example 3
Source Project: smallrye-open-api   Source File: CallbackWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Writes a {@link Callback} object to the JSON tree.
 * 
 * @param parent the parent node
 * @param model the callback model
 * @param name the name of the node
 */
private static void writeCallback(ObjectNode parent, Callback model, String name) {
    if (model == null) {
        return;
    }
    ObjectNode node = parent.putObject(name);

    if (StringUtil.isNotEmpty(model.getRef())) {
        JsonUtil.stringProperty(node, Referenceable.PROP_$REF, model.getRef());
    } else {
        if (model.getPathItems() != null) {
            Set<Map.Entry<String, PathItem>> entrySet = model.getPathItems().entrySet();
            for (Map.Entry<String, PathItem> entry : entrySet) {
                PathsWriter.writePathItem(node, entry.getValue(), entry.getKey());
            }
        }

        ExtensionWriter.writeExtensions(node, model);
    }
}
 
Example 4
Source Project: smallrye-open-api   Source File: PathsWriter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Writes a {@link PathItem} to the JSON tree.
 * 
 * @param parent parent json node
 * @param model PathItem model
 * @param pathName the node name (path)
 */
public static void writePathItem(ObjectNode parent, PathItem model, String pathName) {
    if (model == null) {
        return;
    }
    ObjectNode node = parent.putObject(pathName);
    JsonUtil.stringProperty(node, Referenceable.PROP_$REF, model.getRef());
    JsonUtil.stringProperty(node, PathsConstant.PROP_SUMMARY, model.getSummary());
    JsonUtil.stringProperty(node, PathsConstant.PROP_DESCRIPTION, model.getDescription());
    OperationWriter.writeOperation(node, model.getGET(), PathsConstant.PROP_GET);
    OperationWriter.writeOperation(node, model.getPUT(), PathsConstant.PROP_PUT);
    OperationWriter.writeOperation(node, model.getPOST(), PathsConstant.PROP_POST);
    OperationWriter.writeOperation(node, model.getDELETE(), PathsConstant.PROP_DELETE);
    OperationWriter.writeOperation(node, model.getOPTIONS(), PathsConstant.PROP_OPTIONS);
    OperationWriter.writeOperation(node, model.getHEAD(), PathsConstant.PROP_HEAD);
    OperationWriter.writeOperation(node, model.getPATCH(), PathsConstant.PROP_PATCH);
    OperationWriter.writeOperation(node, model.getTRACE(), PathsConstant.PROP_TRACE);
    ParameterWriter.writeParameterList(node, model.getParameters());
    ServerWriter.writeServers(node, model.getServers());
    ExtensionWriter.writeExtensions(node, model);
}
 
Example 5
Source Project: smallrye-open-api   Source File: PathsReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads the PathItem.
 * Also used in CallbackOperation
 * 
 * @param context the scanning context
 * @param annotationValue the annotation value
 * @return PathItem model
 */
public static PathItem readPathItem(final AnnotationScannerContext context,
        final AnnotationValue annotationValue) {
    if (annotationValue == null) {
        return null;
    }

    AnnotationInstance[] nestedArray = annotationValue.asNestedArray();
    PathItem pathItem = new PathItemImpl();
    for (AnnotationInstance operationAnno : nestedArray) {
        String method = JandexUtil.stringValue(operationAnno, PathsConstant.PROP_METHOD);
        Operation operation = OperationReader.readOperation(context, operationAnno);
        if (method == null) {
            continue;
        }
        try {
            PropertyDescriptor descriptor = new PropertyDescriptor(method.toUpperCase(), pathItem.getClass());
            Method mutator = descriptor.getWriteMethod();
            mutator.invoke(pathItem, operation);
        } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            IoLogging.log.readingCallbackOperation(e);
        }
    }
    return pathItem;
}
 
Example 6
Source Project: smallrye-open-api   Source File: PathsReader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads a {@link PathItem} OpenAPI node.
 * 
 * @param node json object
 * @return PathItem model
 */
public static PathItem readPathItem(final JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    IoLogging.log.singleJsonNode("PathItem");
    PathItem pathItem = new PathItemImpl();
    pathItem.setRef(JsonUtil.stringProperty(node, Referenceable.PROP_$REF));
    pathItem.setSummary(JsonUtil.stringProperty(node, PathsConstant.PROP_SUMMARY));
    pathItem.setDescription(JsonUtil.stringProperty(node, PathsConstant.PROP_DESCRIPTION));
    pathItem.setGET(OperationReader.readOperation(node.get(PathsConstant.PROP_GET)));
    pathItem.setPUT(OperationReader.readOperation(node.get(PathsConstant.PROP_PUT)));
    pathItem.setPOST(OperationReader.readOperation(node.get(PathsConstant.PROP_POST)));
    pathItem.setDELETE(OperationReader.readOperation(node.get(PathsConstant.PROP_DELETE)));
    pathItem.setOPTIONS(OperationReader.readOperation(node.get(PathsConstant.PROP_OPTIONS)));
    pathItem.setHEAD(OperationReader.readOperation(node.get(PathsConstant.PROP_HEAD)));
    pathItem.setPATCH(OperationReader.readOperation(node.get(PathsConstant.PROP_PATCH)));
    pathItem.setTRACE(OperationReader.readOperation(node.get(PathsConstant.PROP_TRACE)));
    pathItem.setParameters(ParameterReader.readParameterList(node.get(PathsConstant.PROP_PARAMETERS)).orElse(null));
    pathItem.setServers(ServerReader.readServers(node.get(PathsConstant.PROP_SERVERS)).orElse(null));
    ExtensionReader.readExtensions(node, pathItem);
    return pathItem;
}
 
Example 7
Source Project: smallrye-open-api   Source File: FilterUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns the filter to use for the test.
 */
private OASFilter filter() {
    return new OASFilter() {
        /**
         * @see org.eclipse.microprofile.openapi.OASFilter#filterOpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI)
         */
        @Override
        public void filterOpenAPI(OpenAPI openAPI) {
            openAPI.getInfo().setLicense(null);
            openAPI.getInfo().setTitle("Updated API Title");
        }

        /**
         * @see org.eclipse.microprofile.openapi.OASFilter#filterPathItem(org.eclipse.microprofile.openapi.models.PathItem)
         */
        @Override
        public PathItem filterPathItem(PathItem pathItem) {
            if (pathItem.getRef() != null) {
                return null;
            } else {
                return pathItem;
            }
        }
    };
}
 
Example 8
Source Project: smallrye-open-api   Source File: JaxRsAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Process the JAX-RS Operation methods
 * 
 * @param context the scanning context
 * @param resourceClass the class containing the methods
 * @param openApi the OpenApi model being processed
 * @param locatorPathParameters path parameters
 */
private void processResourceMethods(final AnnotationScannerContext context,
        final ClassInfo resourceClass,
        OpenAPI openApi,
        List<Parameter> locatorPathParameters) {

    // Process tags (both declarations and references).
    Set<String> tagRefs = processTags(resourceClass, openApi, false);

    // Process exception mapper to auto generate api response based on method exceptions
    Map<DotName, AnnotationInstance> exceptionAnnotationMap = processExceptionMappers(context);

    for (MethodInfo methodInfo : getResourceMethods(context, resourceClass)) {
        final AtomicInteger resourceCount = new AtomicInteger(0);

        JaxRsConstants.HTTP_METHODS
                .stream()
                .filter(methodInfo::hasAnnotation)
                .map(DotName::withoutPackagePrefix)
                .map(PathItem.HttpMethod::valueOf)
                .forEach(httpMethod -> {
                    resourceCount.incrementAndGet();
                    processResourceMethod(context, resourceClass, methodInfo, httpMethod, openApi, tagRefs,
                            locatorPathParameters, exceptionAnnotationMap);
                });

        if (resourceCount.get() == 0 && methodInfo.hasAnnotation(JaxRsConstants.PATH)) {
            processSubResource(context, resourceClass, methodInfo, openApi, locatorPathParameters);
        }
    }
}
 
Example 9
Source Project: smallrye-open-api   Source File: FilterUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Filters the given model.
 * 
 * @param filter
 * @param model
 */
private static void filterCallback(OASFilter filter, Callback model) {
    if (model != null) {
        Collection<String> keys = new ArrayList<>(model.getPathItems().keySet());
        for (String key : keys) {
            PathItem childModel = model.getPathItem(key);
            filterPathItem(filter, childModel);

            if (filter.filterPathItem(childModel) == null) {
                model.removePathItem(key);
            }
        }
    }
}
 
Example 10
Source Project: smallrye-open-api   Source File: FilterUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Filters the given model.
 * 
 * @param filter
 * @param model
 */
private static void filterPathItem(OASFilter filter, PathItem model) {
    if (model != null) {
        model.setParameters(filterParameterList(filter, model.getParameters()));
        filterOperation(filter, model.getDELETE());
        if (model.getDELETE() != null) {
            model.setDELETE(filter.filterOperation(model.getDELETE()));
        }
        filterOperation(filter, model.getGET());
        if (model.getGET() != null) {
            model.setGET(filter.filterOperation(model.getGET()));
        }
        filterOperation(filter, model.getHEAD());
        if (model.getHEAD() != null) {
            model.setHEAD(filter.filterOperation(model.getHEAD()));
        }
        filterOperation(filter, model.getOPTIONS());
        if (model.getOPTIONS() != null) {
            model.setOPTIONS(filter.filterOperation(model.getOPTIONS()));
        }
        filterOperation(filter, model.getPATCH());
        if (model.getPATCH() != null) {
            model.setPATCH(filter.filterOperation(model.getPATCH()));
        }
        filterOperation(filter, model.getPOST());
        if (model.getPOST() != null) {
            model.setPOST(filter.filterOperation(model.getPOST()));
        }
        filterOperation(filter, model.getPUT());
        if (model.getPUT() != null) {
            model.setPUT(filter.filterOperation(model.getPUT()));
        }
        filterOperation(filter, model.getTRACE());
        if (model.getTRACE() != null) {
            model.setTRACE(filter.filterOperation(model.getTRACE()));
        }
        filterServers(filter, model.getServers());
    }
}
 
Example 11
Source Project: smallrye-open-api   Source File: FilterUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Filters the given model.
 * 
 * @param filter
 * @param model
 */
private static void filterPaths(OASFilter filter, Paths model) {
    if (model != null) {
        Collection<String> keys = new ArrayList<>(model.getPathItems().keySet());
        for (String key : keys) {
            PathItem childModel = model.getPathItem(key);
            filterPathItem(filter, childModel);

            if (filter.filterPathItem(childModel) == null) {
                model.removePathItem(key);
            }
        }
    }
}
 
Example 12
Source Project: smallrye-open-api   Source File: AnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the created operation to the pathItem
 * 
 * @param methodType the HTTP method type
 * @param pathItem the pathItem to set
 * @param operation the operation
 */
default void setOperationOnPathItem(PathItem.HttpMethod methodType, PathItem pathItem, Operation operation) {
    switch (methodType) {
        case DELETE:
            pathItem.setDELETE(operation);
            break;
        case GET:
            pathItem.setGET(operation);
            break;
        case HEAD:
            pathItem.setHEAD(operation);
            break;
        case OPTIONS:
            pathItem.setOPTIONS(operation);
            break;
        case PATCH:
            pathItem.setPATCH(operation);
            break;
        case POST:
            pathItem.setPOST(operation);
            break;
        case PUT:
            pathItem.setPUT(operation);
            break;
        case TRACE:
            pathItem.setTRACE(operation);
            break;
        default:
            break;
    }
}
 
Example 13
Source Project: smallrye-open-api   Source File: AnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Now that all paths have been created, sort them.
 * (we don't have a better way to organize them)
 * 
 * @param openApi the openApi model
 */
default void sortPaths(OpenAPI openApi) {
    Paths paths = openApi.getPaths();
    if (paths != null) {
        Paths sortedPaths = new PathsImpl();
        TreeSet<String> sortedKeys = new TreeSet<>(paths.getPathItems().keySet());
        for (String pathKey : sortedKeys) {
            PathItem pathItem = paths.getPathItem(pathKey);
            sortedPaths.addPathItem(pathKey, pathItem);
        }
        sortedPaths.setExtensions(paths.getExtensions());
        openApi.setPaths(sortedPaths);
    }
}
 
Example 14
Source Project: smallrye-open-api   Source File: PathsWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Writes a {@link Paths} to the JSON tree.
 * 
 * @param parent the parent json node
 * @param paths Paths model
 */
public static void writePaths(ObjectNode parent, Paths paths) {
    if (paths == null) {
        return;
    }
    ObjectNode pathsNode = parent.putObject(DefinitionConstant.PROP_PATHS);
    if (paths.getPathItems() != null) {
        Set<Map.Entry<String, PathItem>> entrySet = paths.getPathItems().entrySet();
        for (Map.Entry<String, PathItem> entry : entrySet) {
            writePathItem(pathsNode, entry.getValue(), entry.getKey());
        }
    }
    ExtensionWriter.writeExtensions(pathsNode, paths);
}
 
Example 15
/**
 * Test method for
 * {@link OASFactoryResolverImpl#createObject(java.lang.Class)}.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateObject_All() {
    Class modelClasses[] = { APIResponse.class, APIResponses.class, Callback.class, Components.class,
            Contact.class, Content.class, Discriminator.class, Encoding.class, Example.class,
            ExternalDocumentation.class, Header.class, Info.class, License.class, Link.class, MediaType.class,
            OAuthFlow.class, OAuthFlows.class, OpenAPI.class, Operation.class, Parameter.class, PathItem.class,
            Paths.class, RequestBody.class, Schema.class, SecurityRequirement.class,
            SecurityScheme.class, Server.class, ServerVariable.class, Tag.class, XML.class };
    for (Class modelClass : modelClasses) {
        Constructible object = OASFactory.createObject(modelClass);
        Assert.assertNotNull(object);
    }
}
 
Example 16
Source Project: microprofile-open-api   Source File: Callback.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check whether a path item is present to the map. This is a convenience method for <code>getPathItems().containsKey(name)</code>
 * 
 * @param name a path name in the format valid for a Paths object.
 * @return a boolean to indicate if the path item is present or not.
 */
default boolean hasPathItem(String name) {
    Map<String, PathItem> map = getPathItems();
    if (map == null) {
        return false;
    }
    return map.containsKey(name);
}
 
Example 17
Source Project: microprofile-open-api   Source File: Callback.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a path item for a given name. This is a convenience method for <code>getPathItems().get(name)</code>
 * 
 * @param name a path name in the format valid for a Paths object.
 * @return the corresponding path item or null.
 */
default PathItem getPathItem(String name) {
    Map<String, PathItem> map = getPathItems();
    if (map == null) {
        return null;
    }
    return map.get(name);
}
 
Example 18
@Test
public void pathsTest() {
    final Paths p = processConstructible(Paths.class);
    
    final String pathItemKey = "/myPathItem";
    final PathItem pathItemValue = createConstructibleInstance(PathItem.class);
    p.setPathItems(Collections.singletonMap(pathItemKey, pathItemValue));
    assertTrue(p.hasPathItem(pathItemKey), pathItemKey + " is present in the map");
    assertEquals(p.getPathItems().size(), 1, "The map is expected to contain one entry.");
    assertSame(p.getPathItem(pathItemKey), pathItemValue, 
            "The value associated with the key: " + pathItemKey + " is expected to be the same one that was added.");
    checkMapEntry(p.getPathItems(), pathItemKey, pathItemValue);
    
    final String pathItemKey2 = "/myPathItem2";
    assertFalse(p.hasPathItem(pathItemKey2), pathItemKey2 + " is absent in the map");
    final PathItem pathItemValue2 = createConstructibleInstance(PathItem.class);
    checkSameObject(p, p.addPathItem(pathItemKey2, pathItemValue2));
    assertTrue(p.hasPathItem(pathItemKey2), pathItemKey2 + " is present in the map");
    assertEquals(p.getPathItems().size(), 2, "The map is expected to contain two entries.");
    assertSame(p.getPathItem(pathItemKey2), pathItemValue2, 
            "The value associated with the key: " + pathItemKey2 + " is expected to be the same one that was added.");
    checkMapEntry(p.getPathItems(), pathItemKey2, pathItemValue2);
    
    p.removePathItem(pathItemKey);
    assertFalse(p.hasPathItem(pathItemKey), pathItemKey + " is absent in the map");
    assertEquals(p.getPathItems().size(), 1, "The map is expected to contain one entry.");
    
    p.removePathItem(pathItemKey2);
    assertFalse(p.hasPathItem(pathItemKey2), pathItemKey + " is absent in the map");
    assertEquals(p.getPathItems().size(), 0, "The map is expected to contain 0 entries.");
    
    final PathItem otherValue = createConstructibleInstance(PathItem.class);
    checkMapImmutable(p, Paths::getPathItems, "/otherPathItem", otherValue);
    checkNullValueInAdd(p::getPathItems, p::addPathItem, "/other", otherValue);
}
 
Example 19
@Test
public void callbackTest() {
    final Callback c = processConstructible(Callback.class);
    
    final String pathItemKey = "myPathItem";
    final PathItem pathItemValue = createConstructibleInstance(PathItem.class);
    c.setPathItems(Collections.singletonMap(pathItemKey, pathItemValue));
    assertTrue(c.hasPathItem(pathItemKey), pathItemKey + " is present in the map");
    assertEquals(c.getPathItems().size(), 1, "The map is expected to contain one entry.");
    assertSame(c.getPathItem(pathItemKey), pathItemValue, 
            "The value associated with the key: " + pathItemKey + " is expected to be the same one that was added.");
    checkMapEntry(c.getPathItems(), pathItemKey, pathItemValue);
    
    final String pathItemKey2 = "myPathItem2";
    assertFalse(c.hasPathItem(pathItemKey2), pathItemKey2 + " is absent in the map");
    final PathItem pathItemValue2 = createConstructibleInstance(PathItem.class);
    checkSameObject(c, c.addPathItem(pathItemKey2, pathItemValue2));
    assertTrue(c.hasPathItem(pathItemKey2), pathItemKey2 + " is present in the map");
    assertEquals(c.getPathItems().size(), 2, "The map is expected to contain two entries.");
    assertSame(c.getPathItem(pathItemKey2), pathItemValue2, 
            "The value associated with the key: " + pathItemKey2 + " is expected to be the same one that was added.");
    checkMapEntry(c.getPathItems(), pathItemKey2, pathItemValue2);
    
    c.removePathItem(pathItemKey);
    assertFalse(c.hasPathItem(pathItemKey), pathItemKey + " is absent in the map");
    assertEquals(c.getPathItems().size(), 1, "The map is expected to contain one entry.");
    
    c.removePathItem(pathItemKey2);
    assertFalse(c.hasPathItem(pathItemKey2), pathItemKey + " is absent in the map");
    assertEquals(c.getPathItems().size(), 0, "The map is expected to contain 0 entries.");
    
    final PathItem otherValue = createConstructibleInstance(PathItem.class);
    checkMapImmutable(c, Callback::getPathItems, "otherPathItem", otherValue);
    checkNullValueInAdd(c::getPathItems, c::addPathItem, "other", otherValue);
}
 
Example 20
private String createReference(Reference<?> r, String v) {
    final StringBuilder sb = new StringBuilder();
    if (r instanceof APIResponse) {
        sb.append("#/components/responses/");
    }
    else if (r instanceof Callback) {
        sb.append("#/components/callbacks/");
    }
    else if (r instanceof Example) {
        sb.append("#/components/examples/");
    }
    else if (r instanceof Header) {
        sb.append("#/components/headers/");
    }
    else if (r instanceof Link) {
        sb.append("#/components/links/");
    }
    else if (r instanceof Parameter) {
        sb.append("#/components/parameters/");
    }
    else if (r instanceof PathItem) {
        sb.append("http://www.abc.def.ghi/");
    }
    else if (r instanceof RequestBody) {
        sb.append("#/components/requestBodies/");
    }
    else if (r instanceof Schema) {
        sb.append("#/components/schemas/");
    }
    else if (r instanceof SecurityScheme) {
        sb.append("#/components/securitySchemes/");
    }
    sb.append(v);
    return sb.toString();
}
 
Example 21
Source Project: microprofile-open-api   Source File: AirlinesOASFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PathItem filterPathItem(PathItem pathItem){
    if(pathItem.getGET() != null && "Retrieve all available flights".equals(pathItem.getGET().getSummary())){
        //Add new operation
        pathItem.PUT(OASFactory.createObject(Operation.class).
                summary("filterPathItem - added put operation")
                .responses(OASFactory.createObject(APIResponses.class).addAPIResponse("200", 
                        OASFactory.createObject(APIResponse.class).description("filterPathItem - successfully put airlines"))));
        
        //Spec states : All filterable descendant elements of a filtered element must be called before its ancestor
        //Override the operatioId value that was previously overridden by the filterOperation method
        pathItem.getGET().setOperationId("filterPathItemGetFlights");
    }
    
    if (pathItem.getPOST() != null && "createBooking".equals(pathItem.getPOST().getOperationId())) {
        Map<String, Callback> callbacks = pathItem.getPOST().getCallbacks();
        if (callbacks.containsKey("bookingCallback")) {
            Callback callback = callbacks.get("bookingCallback");
            if (callback.hasPathItem("http://localhost:9080/airlines/bookings")
                    && callback.getPathItem("http://localhost:9080/airlines/bookings").getGET() != null) {
                if ("child - Retrieve all bookings for current user".equals(callback.getPathItem("http://localhost:9080/airlines/bookings")
                        .getGET().getDescription())) {   
                    callback.getPathItem("http://localhost:9080/airlines/bookings").getGET()
                    .setDescription("parent - Retrieve all bookings for current user"); 
                }
            }
        }   
    }
    
    return pathItem;
}
 
Example 22
private void validateOperations() {
    for (String key : openAPI.getPaths().getPathItems().keySet()) {
        PathItem path = openAPI.getPaths().getPathItems().get(key);
        for (PathItem.HttpMethod method : path.getOperations().keySet()) {
            Operation op = path.getOperations().get(method);
            if (parameters.isValidateOperationOperationId()) {
                if (op.getOperationId() == null || op.getOperationId().isEmpty()) {
                    errorAggregator.logMissingOrEmptyOperationAttribute(key, method, "operationId");
                }
            }

            if (parameters.isValidateOperationDescription()) {
                if (op.getDescription() == null || op.getDescription().isEmpty()) {
                    errorAggregator.logMissingOrEmptyOperationAttribute(key, method, "description");
                }
            }

            if (parameters.isValidateOperationSummary()) {
                if (op.getSummary() == null || op.getSummary().isEmpty()) {
                    errorAggregator.logMissingOrEmptyOperationAttribute(key, method, "summary");
                }
            }

            if (parameters.isValidateOperationTag()) {
                if (op.getTags() == null || op.getTags().isEmpty()) {
                    errorAggregator.logMissingOrEmptyOperationCollection(key, method, "tags");
                }
            }
        }
    }
}
 
Example 23
public OperationStyleError(String fieldNames,
                           String description,
                           String path,
                           PathItem.HttpMethod method) {
    super(StyleCheckSection.Operations, fieldNames, description);
    this.path = path;
    this.method = method;

}
 
Example 24
Source Project: thorntail   Source File: OpenApiDeploymentProcessorTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.microprofile.openapi.OASFilter#filterPathItem(org.eclipse.microprofile.openapi.models.PathItem)
 */
@Override
public PathItem filterPathItem(PathItem pathItem) {
    if (pathItem.getRef() != null) {
        return null;
    } else {
        return pathItem;
    }
}
 
Example 25
Source Project: smallrye-open-api   Source File: JaxRsAnnotationScanner.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process a single JAX-RS method to produce an OpenAPI Operation.
 * 
 * @param openApi
 * @param resourceClass
 * @param method
 * @param methodType
 * @param resourceTags
 * @param locatorPathParameters
 */
private void processResourceMethod(final AnnotationScannerContext context,
        final ClassInfo resourceClass,
        final MethodInfo method,
        final PathItem.HttpMethod methodType,
        OpenAPI openApi,
        Set<String> resourceTags,
        List<Parameter> locatorPathParameters,
        Map<DotName, AnnotationInstance> exceptionAnnotationMap) {

    JaxRsLogging.log.processingMethod(method.toString());

    // Figure out the current @Produces and @Consumes (if any)
    CurrentScannerInfo.setCurrentConsumes(getMediaTypes(method, JaxRsConstants.CONSUMES).orElse(null));
    CurrentScannerInfo.setCurrentProduces(getMediaTypes(method, JaxRsConstants.PRODUCES).orElse(null));

    // Process any @Operation annotation
    Optional<Operation> maybeOperation = processOperation(context, method);
    if (!maybeOperation.isPresent()) {
        return; // If the operation is marked as hidden, just bail here because we don't want it as part of the model.
    }
    final Operation operation = maybeOperation.get();

    // Process tags - @Tag and @Tags annotations combines with the resource tags we've already found (passed in)
    processOperationTags(method, openApi, resourceTags, operation);

    // Process @Parameter annotations.
    Function<AnnotationInstance, Parameter> reader = t -> ParameterReader.readParameter(context, t);

    ResourceParameters params = ParameterProcessor.process(context, resourceClass, method,
            reader, context.getExtensions());
    operation.setParameters(params.getOperationParameters());

    PathItem pathItem = new PathItemImpl();
    pathItem.setParameters(ListUtil.mergeNullableLists(locatorPathParameters, params.getPathItemParameters()));

    // Process any @RequestBody annotation (note: the @RequestBody annotation can be found on a method argument *or* on the method)
    RequestBody requestBody = processRequestBody(context, method, params);
    if (requestBody != null) {
        operation.setRequestBody(requestBody);
    }

    // Process @APIResponse annotations
    processResponse(context, method, operation, exceptionAnnotationMap);

    // Process @SecurityRequirement annotations
    processSecurityRequirementAnnotation(resourceClass, method, operation);

    // Process @Callback annotations
    processCallback(context, method, operation);

    // Process @Server annotations
    processServerAnnotation(method, operation);

    // Process @Extension annotations
    processExtensions(context, method, operation);

    // Process Security Roles
    JavaSecurityProcessor.processSecurityRoles(method, operation);

    // Now set the operation on the PathItem as appropriate based on the Http method type
    setOperationOnPathItem(methodType, pathItem, operation);

    // Figure out the path for the operation.  This is a combination of the App, Resource, and Method @Path annotations
    final String path;

    if (this.subResourceStack.isEmpty()) {
        path = super.makePath(params.getFullOperationPath());
    } else {
        // When processing a sub-resource tree, ignore any @Path information from the current class
        path = super.makePath(params.getOperationPath());
    }

    // Get or create a PathItem to hold the operation
    PathItem existingPath = ModelUtil.paths(openApi).getPathItem(path);

    if (existingPath == null) {
        ModelUtil.paths(openApi).addPathItem(path, pathItem);
    } else {
        // Changes applied to 'existingPath', no need to re-assign or add to OAI.
        MergeUtil.mergeObjects(existingPath, pathItem);
    }
}
 
Example 26
Source Project: smallrye-open-api   Source File: SpringAnnotationScanner.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Process a single Spring method to produce an OpenAPI Operation.
 *
 * @param openApi
 * @param resourceClass
 * @param method
 * @param methodType
 * @param resourceTags
 * @param locatorPathParameters
 */
private void processControllerMethod(final AnnotationScannerContext context,
        final ClassInfo resourceClass,
        final MethodInfo method,
        final PathItem.HttpMethod methodType,
        OpenAPI openApi,
        Set<String> resourceTags,
        List<Parameter> locatorPathParameters) {

    SpringLogging.log.processingMethod(method.toString());

    // Figure out the current @Produces and @Consumes (if any)
    CurrentScannerInfo.setCurrentConsumes(getMediaTypes(method, MediaTypeProperty.consumes).orElse(null));
    CurrentScannerInfo.setCurrentProduces(getMediaTypes(method, MediaTypeProperty.produces).orElse(null));

    // Process any @Operation annotation
    Optional<Operation> maybeOperation = processOperation(context, method);
    if (!maybeOperation.isPresent()) {
        return; // If the operation is marked as hidden, just bail here because we don't want it as part of the model.
    }
    final Operation operation = maybeOperation.get();

    // Process tags - @Tag and @Tags annotations combines with the resource tags we've already found (passed in)
    processOperationTags(method, openApi, resourceTags, operation);

    // Process @Parameter annotations.
    PathItem pathItem = new PathItemImpl();
    Function<AnnotationInstance, Parameter> reader = t -> ParameterReader.readParameter(context, t);
    ResourceParameters params = ParameterProcessor.process(context.getIndex(), resourceClass, method, reader,
            context.getExtensions());
    operation.setParameters(params.getOperationParameters());

    pathItem.setParameters(ListUtil.mergeNullableLists(locatorPathParameters, params.getPathItemParameters()));

    // Process any @RequestBody annotation (note: the @RequestBody annotation can be found on a method argument *or* on the method)
    RequestBody requestBody = processRequestBody(context, method, params);
    if (requestBody != null) {
        operation.setRequestBody(requestBody);
    }

    // Process @APIResponse annotations
    processResponse(context, method, operation, null);

    // Process @SecurityRequirement annotations
    processSecurityRequirementAnnotation(resourceClass, method, operation);

    // Process @Callback annotations
    processCallback(context, method, operation);

    // Process @Server annotations
    processServerAnnotation(method, operation);

    // Process @Extension annotations
    processExtensions(context, method, operation);

    // Process Security Roles
    JavaSecurityProcessor.processSecurityRoles(method, operation);

    // Now set the operation on the PathItem as appropriate based on the Http method type
    setOperationOnPathItem(methodType, pathItem, operation);

    // Figure out the path for the operation.  This is a combination of the App, Resource, and Method @Path annotations
    String path = super.makePath(params.getOperationPath());

    // Get or create a PathItem to hold the operation
    PathItem existingPath = ModelUtil.paths(openApi).getPathItem(path);

    if (existingPath == null) {
        ModelUtil.paths(openApi).addPathItem(path, pathItem);
    } else {
        // Changes applied to 'existingPath', no need to re-assign or add to OAI.
        MergeUtil.mergeObjects(existingPath, pathItem);
    }
}
 
Example 27
Source Project: smallrye-open-api   Source File: PathItemImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.microprofile.openapi.models.PathItem#addServer(org.eclipse.microprofile.openapi.models.servers.Server)
 */
@Override
public PathItem addServer(Server server) {
    this.servers = ModelUtil.add(server, this.servers, ArrayList<Server>::new);
    return this;
}
 
Example 28
Source Project: smallrye-open-api   Source File: PathItemImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.microprofile.openapi.models.PathItem#addParameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)
 */
@Override
public PathItem addParameter(Parameter parameter) {
    this.parameters = ModelUtil.add(parameter, this.parameters, ArrayList<Parameter>::new);
    return this;
}
 
Example 29
Source Project: smallrye-open-api   Source File: CallbackImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.microprofile.openapi.models.callbacks.Callback#addPathItem(java.lang.String,
 *      org.eclipse.microprofile.openapi.models.PathItem)
 */
@Override
public Callback addPathItem(String name, PathItem item) {
    this.pathItems = ModelUtil.add(name, item, this.pathItems, LinkedHashMap<String, PathItem>::new);
    return this;
}
 
Example 30
Source Project: smallrye-open-api   Source File: CallbackImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see org.eclipse.microprofile.openapi.models.callbacks.Callback#getPathItems()
 */
@Override
public Map<String, PathItem> getPathItems() {
    return ModelUtil.unmodifiableMap(this.pathItems);
}