Java Code Examples for org.eclipse.microprofile.openapi.models.Operation#setRequestBody()

The following examples show how to use org.eclipse.microprofile.openapi.models.Operation#setRequestBody() . 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 File: OperationReader.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a {@link Operation} OpenAPI node.
 * 
 * @param node json object
 * @return Operation model
 */
public static Operation readOperation(final JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    IoLogging.log.singleJsonObject("Operation");
    Operation model = new OperationImpl();
    model.setTags(JsonUtil.readStringArray(node.get(OperationConstant.PROP_TAGS)).orElse(null));
    model.setSummary(JsonUtil.stringProperty(node, OperationConstant.PROP_SUMMARY));
    model.setDescription(JsonUtil.stringProperty(node, OperationConstant.PROP_DESCRIPTION));
    model.setExternalDocs(ExternalDocsReader.readExternalDocs(node.get(ExternalDocsConstant.PROP_EXTERNAL_DOCS)));
    model.setOperationId(JsonUtil.stringProperty(node, OperationConstant.PROP_OPERATION_ID));
    model.setParameters(ParameterReader.readParameterList(node.get(OperationConstant.PROP_PARAMETERS)).orElse(null));
    model.setRequestBody(RequestBodyReader.readRequestBody(node.get(OperationConstant.PROP_REQUEST_BODY)));
    model.setResponses(ResponseReader.readResponses(node.get(OperationConstant.PROP_RESPONSES)));
    model.setCallbacks(CallbackReader.readCallbacks(node.get(OperationConstant.PROP_CALLBACKS)));
    model.setDeprecated(JsonUtil.booleanProperty(node, OperationConstant.PROP_DEPRECATED).orElse(null));
    model.setSecurity(
            SecurityRequirementReader.readSecurityRequirements(node.get(OperationConstant.PROP_SECURITY)).orElse(null));
    model.setServers(ServerReader.readServers(node.get(OperationConstant.PROP_SERVERS)).orElse(null));
    ExtensionReader.readExtensions(node, model);
    return model;
}
 
Example 2
Source File: FilterUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Filters the given model.
 * 
 * @param filter
 * @param model
 */
private static void filterOperation(OASFilter filter, Operation model) {
    if (model != null) {
        filterCallbacks(filter, model.getCallbacks());
        model.setParameters(filterParameterList(filter, model.getParameters()));
        filterRequestBody(filter, model.getRequestBody());
        if (model.getRequestBody() != null && filter.filterRequestBody(model.getRequestBody()) == null) {
            model.setRequestBody(null);
        }
        if (model.getResponses() != null) {
            filterAPIResponses(filter, model.getResponses().getAPIResponses());
        }
        filterServers(filter, model.getServers());
    }
}
 
Example 3
Source File: OperationReader.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a single Operation annotation.
 * 
 * @param context the scanning context
 * @param annotationInstance {@literal @}CallbackOperation annotation
 * @return Operation model
 */
public static Operation readOperation(final AnnotationScannerContext context,
        final AnnotationInstance annotationInstance) {
    if (annotationInstance == null) {
        return null;
    }
    IoLogging.log.singleAnnotation("@Operation");
    Operation operation = new OperationImpl();
    operation.setSummary(JandexUtil.stringValue(annotationInstance, OperationConstant.PROP_SUMMARY));
    operation.setDescription(JandexUtil.stringValue(annotationInstance, OperationConstant.PROP_DESCRIPTION));
    operation.setExternalDocs(
            ExternalDocsReader.readExternalDocs(annotationInstance.value(ExternalDocsConstant.PROP_EXTERNAL_DOCS)));
    operation.setParameters(ParameterReader.readParametersList(context,
            annotationInstance.value(OperationConstant.PROP_PARAMETERS)).orElse(null));
    operation.setRequestBody(RequestBodyReader.readRequestBody(context,
            annotationInstance.value(OperationConstant.PROP_REQUEST_BODY)));
    operation.setResponses(ResponseReader.readResponses(context,
            annotationInstance.value(OperationConstant.PROP_RESPONSES)));
    operation.setSecurity(SecurityRequirementReader
            .readSecurityRequirements(annotationInstance.value(OperationConstant.PROP_SECURITY)).orElse(null));
    operation.setExtensions(
            ExtensionReader.readExtensions(context,
                    annotationInstance.value(OperationConstant.PROP_EXTENSIONS)));

    // Below is only used in Jax-rs ??
    // Operation Id ??
    operation.setOperationId(JandexUtil.stringValue(annotationInstance, OperationConstant.PROP_OPERATION_ID));
    // Deprecated ??
    operation.setDeprecated(JandexUtil.booleanValue(annotationInstance, OperationConstant.PROP_DEPRECATED).orElse(null));

    // Below is not used ?
    // Tags ?
    // Callbacks
    // Servers
    return operation;
}
 
Example 4
Source File: JaxRsAnnotationScanner.java    From smallrye-open-api with 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 5
Source File: SpringAnnotationScanner.java    From smallrye-open-api with 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);
    }
}