Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Add an API to list all the properties and custom properties for a given entity type #18248

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openmetadata-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
<groupId>io.dropwizard.modules</groupId>
<artifactId>dropwizard-web</artifactId>
</dependency>
<dependency>
<groupId>com.github.erosb</groupId>
<artifactId>everit-json-schema</artifactId>
</dependency>

<!-- Dependencies for cloudwatch monitoring -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.json.JsonPatch;
import javax.validation.Valid;
Expand Down Expand Up @@ -68,6 +70,7 @@
import org.openmetadata.service.util.JsonUtils;
import org.openmetadata.service.util.RestUtil.PutResponse;
import org.openmetadata.service.util.ResultList;
import org.openmetadata.service.util.SchemaFieldExtractor;

@Path("/v1/metadata/types")
@Tag(
Expand Down Expand Up @@ -466,6 +469,57 @@ public Response addOrUpdateProperty(
return response.toResponse();
}

@GET
@Path("/fields/{entityType}")
@Produces(MediaType.APPLICATION_JSON)
public Response getEntityTypeFields(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@PathParam("entityType") String entityType,
@QueryParam("include") @DefaultValue("non-deleted") Include include) {

try {
Fields fieldsParam = new Fields(Set.of("customProperties"));
Type typeEntity = repository.getByName(uriInfo, entityType, fieldsParam, include, false);
SchemaFieldExtractor extractor = new SchemaFieldExtractor();
List<SchemaFieldExtractor.FieldDefinition> fieldsList =
extractor.extractFields(typeEntity, entityType);
return Response.ok(fieldsList).type(MediaType.APPLICATION_JSON).build();

} catch (Exception e) {
LOG.error("Error processing schema for entity type: " + entityType, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(
"Error processing schema for entity type: "
+ entityType
+ ". Exception: "
+ e.getMessage())
.build();
}
}

@GET
@Path("/customProperties")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllCustomPropertiesByEntityType(
@Context UriInfo uriInfo, @Context SecurityContext securityContext) {
try {
SchemaFieldExtractor extractor = new SchemaFieldExtractor();
Map<String, List<SchemaFieldExtractor.FieldDefinition>> customPropertiesMap =
extractor.extractAllCustomProperties(uriInfo, repository);
return Response.ok(customPropertiesMap).build();
} catch (Exception e) {
LOG.error("Error fetching custom properties: {}", e.getMessage(), e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(
"Error processing schema for entity type: "
+ entityType
+ ". Exception: "
+ e.getMessage())
.build();
}
}

private Type getType(CreateType create, String user) {
return repository
.copy(new Type(), create, user)
Expand Down
Loading
Loading