![JAR search and dependency download from the Maven repository](/logo.png)
org.openmetadata.service.resources.services.apiservices.APIServiceResource Maven / Gradle / Ivy
/*
* Copyright 2021 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openmetadata.service.resources.services.apiservices;
import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.json.JsonPatch;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.PATCH;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;
import lombok.extern.slf4j.Slf4j;
import org.openmetadata.schema.api.data.RestoreEntity;
import org.openmetadata.schema.api.services.CreateAPIService;
import org.openmetadata.schema.entity.services.APIService;
import org.openmetadata.schema.entity.services.ServiceType;
import org.openmetadata.schema.entity.services.connections.TestConnectionResult;
import org.openmetadata.schema.type.APIServiceConnection;
import org.openmetadata.schema.type.EntityHistory;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.type.MetadataOperation;
import org.openmetadata.schema.utils.EntityInterfaceUtil;
import org.openmetadata.service.Entity;
import org.openmetadata.service.jdbi3.APIServiceRepository;
import org.openmetadata.service.limits.Limits;
import org.openmetadata.service.resources.Collection;
import org.openmetadata.service.resources.services.ServiceEntityResource;
import org.openmetadata.service.security.Authorizer;
import org.openmetadata.service.security.policyevaluator.OperationContext;
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.ResultList;
@Slf4j
@Path("/v1/services/apiServices")
@Tag(
name = "API Services",
description = "APIs related `API Service` entities, such as REST or MicroService.")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Collection(name = "apiServices")
public class APIServiceResource
extends ServiceEntityResource {
public static final String COLLECTION_PATH = "v1/services/apiServices/";
static final String FIELDS = "pipelines,owners,tags,domain";
@Override
public APIService addHref(UriInfo uriInfo, APIService service) {
super.addHref(uriInfo, service);
Entity.withHref(uriInfo, service.getPipelines());
return service;
}
public APIServiceResource(Authorizer authorizer, Limits limits) {
super(Entity.API_SERVICE, authorizer, limits, ServiceType.API);
}
@Override
protected List getEntitySpecificOperations() {
addViewOperation("pipelines", MetadataOperation.VIEW_BASIC);
return null;
}
public static class APIServiceList extends ResultList {
/* Required for serde */
}
@GET
@Operation(
operationId = "listAPIServices",
summary = "List API services",
description = "Get a list of API services.",
responses = {
@ApiResponse(
responseCode = "200",
description = "List of API service instances",
content =
@Content(
mediaType = "application/json",
schema =
@Schema(
implementation =
org.openmetadata.service.resources.services.apiservices
.APIServiceResource.APIServiceList.class)))
})
public ResultList list(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(
description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields")
String fieldsParam,
@Parameter(
description = "Filter services by domain",
schema = @Schema(type = "string", example = "Marketing"))
@QueryParam("domain")
String domain,
@DefaultValue("10") @Min(0) @Max(1000000) @QueryParam("limit") int limitParam,
@Parameter(
description = "Returns list of API services before this cursor",
schema = @Schema(type = "string"))
@QueryParam("before")
String before,
@Parameter(
description = "Returns list of API services after this cursor",
schema = @Schema(type = "string"))
@QueryParam("after")
String after,
@Parameter(
description = "Include all, deleted, or non-deleted entities.",
schema = @Schema(implementation = Include.class))
@QueryParam("include")
@DefaultValue("non-deleted")
Include include) {
return listInternal(
uriInfo, securityContext, fieldsParam, include, domain, limitParam, before, after);
}
@GET
@Path("/{id}")
@Operation(
operationId = "getAPIServiceByID",
summary = "Get an API service",
description = "Get an API service by `id`.",
responses = {
@ApiResponse(
responseCode = "200",
description = "API service instance",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = APIService.class))),
@ApiResponse(
responseCode = "404",
description = "API service for instance {id} is not found")
})
public APIService get(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@PathParam("id") UUID id,
@Parameter(
description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields")
String fieldsParam,
@Parameter(
description = "Include all, deleted, or non-deleted entities.",
schema = @Schema(implementation = Include.class))
@QueryParam("include")
@DefaultValue("non-deleted")
Include include) {
APIService apiService = getInternal(uriInfo, securityContext, id, fieldsParam, include);
return decryptOrNullify(securityContext, apiService);
}
@GET
@Path("/name/{name}")
@Operation(
operationId = "getAPIServiceByFQN",
summary = "Get API service by name",
description = "Get a API service by the service `name`.",
responses = {
@ApiResponse(
responseCode = "200",
description = "API service instance",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = APIService.class))),
@ApiResponse(
responseCode = "404",
description = "API service for instance {id} is not found")
})
public APIService getByName(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@PathParam("name") String name,
@Parameter(
description = "Fields requested in the returned resource",
schema = @Schema(type = "string", example = FIELDS))
@QueryParam("fields")
String fieldsParam,
@Parameter(
description = "Include all, deleted, or non-deleted entities.",
schema = @Schema(implementation = Include.class))
@QueryParam("include")
@DefaultValue("non-deleted")
Include include) {
APIService apiService =
getByNameInternal(
uriInfo, securityContext, EntityInterfaceUtil.quoteName(name), fieldsParam, include);
return decryptOrNullify(securityContext, apiService);
}
@PUT
@Path("/{id}/testConnectionResult")
@Operation(
operationId = "addTestConnectionResult",
summary = "Add test connection result",
description = "Add test connection result to the service.",
responses = {
@ApiResponse(
responseCode = "200",
description = "Successfully updated the service",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = APIService.class)))
})
public APIService addTestConnectionResult(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the service", schema = @Schema(type = "UUID"))
@PathParam("id")
UUID id,
@Valid TestConnectionResult testConnectionResult) {
OperationContext operationContext = new OperationContext(entityType, MetadataOperation.CREATE);
authorizer.authorize(securityContext, operationContext, getResourceContextById(id));
APIService service = repository.addTestConnectionResult(id, testConnectionResult);
return decryptOrNullify(securityContext, service);
}
@GET
@Path("/{id}/versions")
@Operation(
operationId = "listAllAPIServiceVersion",
summary = "List API service versions",
description = "Get a list of all the versions of an API service identified by `id`",
responses = {
@ApiResponse(
responseCode = "200",
description = "List of API service versions",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = EntityHistory.class)))
})
public EntityHistory listVersions(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "API service Id", schema = @Schema(type = "string")) @PathParam("id")
UUID id) {
EntityHistory entityHistory = super.listVersionsInternal(securityContext, id);
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy