Search in sources :

Example 6 with Operation

use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.

the class PathsBuilderTest method setupBaseDocument.

@Override
protected void setupBaseDocument(OpenAPI document) {
    Operation operation = createOperation().summary("summary").description("description").responses(createAPIResponses().addAPIResponse("200", createAPIResponse().ref("ref")));
    document.paths(createPaths().addExtension("x-ext", "ext-value").addPathItem("/item1/", createPathItem().summary("summary").description("description").GET(operation).DELETE(operation).HEAD(operation).OPTIONS(operation).PATCH(operation).POST(operation).PUT(operation).TRACE(operation).addExtension("x-ext", "ext-value").addServer(createServer().url("url1")).addServer(createServer().url("url2")).addParameter(createParameter().name("name1").in(In.QUERY)).addParameter(createParameter().name("name2").in(In.COOKIE))));
}
Also used : OASFactory.createOperation(org.eclipse.microprofile.openapi.OASFactory.createOperation) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 7 with Operation

use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.

the class ApplicationProcessor method mapException.

/**
 * When an exception mapper is encountered, register the mapped response and
 * find any operations already parsed that this exception mapper is applicable
 * to
 */
private void mapException(ApiContext context, String exceptionType, APIResponseImpl exceptionResponse) {
    // Don't allow null responses
    if (exceptionResponse.getDescription() == null || exceptionResponse.getDescription().isEmpty()) {
        exceptionResponse.setDescription(ModelUtils.getSimpleName(exceptionType));
    }
    context.addMappedExceptionResponse(exceptionType, exceptionResponse);
    final String exceptionStatus = exceptionResponse.getResponseCode();
    if (exceptionStatus != null) {
        for (PathItem path : context.getApi().getPaths().getPathItems().values()) {
            for (Operation operation : path.getOperations().values()) {
                if (((OperationImpl) operation).getExceptionTypes().contains(exceptionType)) {
                    operation.getResponses().addAPIResponse(exceptionStatus, exceptionResponse);
                }
            }
        }
    } else {
        LOGGER.fine("Failed to add mapped response as no response code was provided");
    }
}
Also used : PathItem(org.eclipse.microprofile.openapi.models.PathItem) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 8 with Operation

use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.

the class ApplicationProcessor method visitAPIResponse.

@Override
public void visitAPIResponse(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
    APIResponseImpl apiResponse = APIResponseImpl.createInstance(annotation, context);
    Operation workingOperation = context.getWorkingOperation();
    // Handle exception mappers
    if (workingOperation == null) {
        if (element instanceof MethodModel && "toResponse".equals(element.getName())) {
            final MethodModel methodModel = (MethodModel) element;
            final String exceptionType = methodModel.getParameter(0).getTypeName();
            mapException(context, exceptionType, apiResponse);
        } else {
            LOGGER.warning("Unrecognised annotation position at: " + element.shortDesc());
        }
        return;
    }
    APIResponsesImpl.merge(apiResponse, workingOperation.getResponses(), true, context);
    // If an APIResponse has been processed that isn't the default
    String responseCode = apiResponse.getResponseCode();
    if (responseCode != null && !responseCode.isEmpty() && !responseCode.equals(APIResponses.DEFAULT)) {
        // If the element doesn't also contain a response mapping to the default
        AnnotationModel apiResponsesParent = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.responses.APIResponses.class.getName());
        if (apiResponsesParent != null) {
            List<AnnotationModel> apiResponses = apiResponsesParent.getValue("value", List.class);
            if (apiResponses.stream().map(a -> a.getValue("responseCode", String.class)).noneMatch(code -> code == null || code.isEmpty() || code.equals(APIResponses.DEFAULT))) {
                // Then remove the default response
                workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
            }
        } else {
            workingOperation.getResponses().removeAPIResponse(APIResponses.DEFAULT);
        }
    }
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Arrays(java.util.Arrays) ExtensibleImpl(fish.payara.microprofile.openapi.impl.model.ExtensibleImpl) ModelUtils.isVoid(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid) PathItem(org.eclipse.microprofile.openapi.models.PathItem) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) DefaultValue(javax.ws.rs.DefaultValue) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Method(java.lang.reflect.Method) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Collection(java.util.Collection) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) Set(java.util.Set) WARNING(java.util.logging.Level.WARNING) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) ApiVisitor(fish.payara.microprofile.openapi.api.visitor.ApiVisitor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) List(java.util.List) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Entry(java.util.Map.Entry) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) OASProcessor(fish.payara.microprofile.openapi.api.processor.OASProcessor) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ModelUtils(fish.payara.microprofile.openapi.impl.model.util.ModelUtils) HttpMethod(javax.ws.rs.HttpMethod) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) Schema(org.eclipse.microprofile.openapi.models.media.Schema) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Status(javax.ws.rs.core.Response.Status) FINE(java.util.logging.Level.FINE) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Types(org.glassfish.hk2.classmodel.reflect.Types) FormParam(javax.ws.rs.FormParam) OpenApiWalker(fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) EnumType(org.glassfish.hk2.classmodel.reflect.EnumType) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Reference(org.eclipse.microprofile.openapi.models.Reference) ApiContext(fish.payara.microprofile.openapi.api.visitor.ApiContext) Collections(java.util.Collections) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Type(org.glassfish.hk2.classmodel.reflect.Type) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) Operation(org.eclipse.microprofile.openapi.models.Operation)

Example 9 with Operation

use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.

the class ApplicationProcessor method findOperationParameterFor.

private static Parameter findOperationParameterFor(Parameter parameter, MethodModel annotated, ApiContext context) {
    String name = parameter.getName();
    // If the parameter reference is valid
    if (name != null && !name.isEmpty()) {
        // Get all parameters with the same name
        List<org.glassfish.hk2.classmodel.reflect.Parameter> matchingMethodParameters = annotated.getParameters().stream().filter(x -> name.equals(ModelUtils.getParameterName(context, x))).collect(Collectors.toList());
        // If there is more than one match, filter it further
        In in = parameter.getIn();
        if (matchingMethodParameters.size() > 1 && in != null) {
            // Remove all parameters of the wrong input type
            matchingMethodParameters.removeIf(x -> ModelUtils.getParameterType(context, x) != In.valueOf(in.name()));
        }
        if (matchingMethodParameters.isEmpty()) {
            return null;
        }
        // If there's only one matching parameter, handle it immediately
        String matchingMethodParamName = ModelUtils.getParameterName(context, matchingMethodParameters.get(0));
        // Find the matching operation parameter
        for (Parameter operationParam : context.getWorkingOperation().getParameters()) {
            if (operationParam.getName().equals(matchingMethodParamName)) {
                return operationParam;
            }
        }
    }
    return null;
}
Also used : RequestBodyImpl(fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl) Components(org.eclipse.microprofile.openapi.models.Components) Arrays(java.util.Arrays) ExtensibleImpl(fish.payara.microprofile.openapi.impl.model.ExtensibleImpl) ModelUtils.isVoid(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isVoid) PathItem(org.eclipse.microprofile.openapi.models.PathItem) ExtensibleType(org.glassfish.hk2.classmodel.reflect.ExtensibleType) Tag(org.eclipse.microprofile.openapi.models.tags.Tag) ParameterizedType(org.glassfish.hk2.classmodel.reflect.ParameterizedType) DefaultValue(javax.ws.rs.DefaultValue) MediaTypeImpl(fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl) Method(java.lang.reflect.Method) RequestBody(org.eclipse.microprofile.openapi.models.parameters.RequestBody) SecurityScheme(org.eclipse.microprofile.openapi.models.security.SecurityScheme) Collection(java.util.Collection) AnnotatedElement(org.glassfish.hk2.classmodel.reflect.AnnotatedElement) Set(java.util.Set) WARNING(java.util.logging.Level.WARNING) OpenAPIImpl(fish.payara.microprofile.openapi.impl.model.OpenAPIImpl) ApiVisitor(fish.payara.microprofile.openapi.api.visitor.ApiVisitor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) List(java.util.List) ServerImpl(fish.payara.microprofile.openapi.impl.model.servers.ServerImpl) TagImpl(fish.payara.microprofile.openapi.impl.model.tags.TagImpl) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) APIResponseImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl) ExternalDocumentation(org.eclipse.microprofile.openapi.models.ExternalDocumentation) Entry(java.util.Map.Entry) SchemaImpl(fish.payara.microprofile.openapi.impl.model.media.SchemaImpl) Server(org.eclipse.microprofile.openapi.models.servers.Server) OASProcessor(fish.payara.microprofile.openapi.api.processor.OASProcessor) OpenApiConfiguration(fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration) ContentImpl(fish.payara.microprofile.openapi.impl.model.media.ContentImpl) SecuritySchemeImpl(fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement) APIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponse) MediaType(org.eclipse.microprofile.openapi.models.media.MediaType) FieldModel(org.glassfish.hk2.classmodel.reflect.FieldModel) ModelUtils(fish.payara.microprofile.openapi.impl.model.util.ModelUtils) HttpMethod(javax.ws.rs.HttpMethod) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) SEVERE(java.util.logging.Level.SEVERE) SecurityRequirementImpl(fish.payara.microprofile.openapi.impl.model.security.SecurityRequirementImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ParameterizedInterfaceModel(org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel) Schema(org.eclipse.microprofile.openapi.models.media.Schema) OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Status(javax.ws.rs.core.Response.Status) FINE(java.util.logging.Level.FINE) Callback(org.eclipse.microprofile.openapi.models.callbacks.Callback) Types(org.glassfish.hk2.classmodel.reflect.Types) FormParam(javax.ws.rs.FormParam) OpenApiWalker(fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker) PathItemImpl(fish.payara.microprofile.openapi.impl.model.PathItemImpl) MethodModel(org.glassfish.hk2.classmodel.reflect.MethodModel) CallbackImpl(fish.payara.microprofile.openapi.impl.model.callbacks.CallbackImpl) APIResponsesImpl(fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter) EnumType(org.glassfish.hk2.classmodel.reflect.EnumType) ParameterImpl(fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl) APIResponses(org.eclipse.microprofile.openapi.models.responses.APIResponses) ExternalDocumentationImpl(fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl) Reference(org.eclipse.microprofile.openapi.models.Reference) ApiContext(fish.payara.microprofile.openapi.api.visitor.ApiContext) Collections(java.util.Collections) AnnotationModel(org.glassfish.hk2.classmodel.reflect.AnnotationModel) ClassModel(org.glassfish.hk2.classmodel.reflect.ClassModel) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Type(org.glassfish.hk2.classmodel.reflect.Type) In(org.eclipse.microprofile.openapi.models.parameters.Parameter.In) Parameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)

Example 10 with Operation

use of org.eclipse.microprofile.openapi.models.Operation in project Payara by payara.

the class CallbackImpl method applyCallbackOperationAnnotation.

private static void applyCallbackOperationAnnotation(PathItem pathItem, Operation callbackOperation, boolean override, ApiContext context) {
    if (callbackOperation instanceof OperationImpl) {
        OperationImpl callbackOperationImpl = (OperationImpl) callbackOperation;
        if (callbackOperationImpl.getMethod() != null) {
            HttpMethod method = getHttpMethod(callbackOperationImpl.getMethod());
            if (method != null) {
                Operation operation = getOrCreateOperation(pathItem, method);
                OperationImpl.merge(callbackOperation, operation, override, context);
            }
        }
    }
}
Also used : OperationImpl(fish.payara.microprofile.openapi.impl.model.OperationImpl) Operation(org.eclipse.microprofile.openapi.models.Operation) ModelUtils.getOrCreateOperation(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getOrCreateOperation) HttpMethod(org.eclipse.microprofile.openapi.models.PathItem.HttpMethod) ModelUtils.getHttpMethod(fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getHttpMethod)

Aggregations

Operation (org.eclipse.microprofile.openapi.models.Operation)14 PathItem (org.eclipse.microprofile.openapi.models.PathItem)8 Parameter (org.eclipse.microprofile.openapi.models.parameters.Parameter)7 SchemaImpl (fish.payara.microprofile.openapi.impl.model.media.SchemaImpl)5 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)5 Schema (org.eclipse.microprofile.openapi.models.media.Schema)5 PathItemImpl (fish.payara.microprofile.openapi.impl.model.PathItemImpl)4 ContentImpl (fish.payara.microprofile.openapi.impl.model.media.ContentImpl)4 MediaTypeImpl (fish.payara.microprofile.openapi.impl.model.media.MediaTypeImpl)4 ParameterImpl (fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl)4 RequestBodyImpl (fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl)4 ServerImpl (fish.payara.microprofile.openapi.impl.model.servers.ServerImpl)4 Callback (org.eclipse.microprofile.openapi.models.callbacks.Callback)4 RequestBody (org.eclipse.microprofile.openapi.models.parameters.RequestBody)4 APIResponse (org.eclipse.microprofile.openapi.models.responses.APIResponse)4 APIResponses (org.eclipse.microprofile.openapi.models.responses.APIResponses)4 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)4 Server (org.eclipse.microprofile.openapi.models.servers.Server)4 Tag (org.eclipse.microprofile.openapi.models.tags.Tag)4 OperationImpl (fish.payara.microprofile.openapi.impl.model.OperationImpl)3