mirror of
https://github.com/datahub-project/datahub.git
synced 2025-06-27 05:03:31 +00:00
clean(openapi): remove unneeded schema (#12691)
This commit is contained in:
parent
9e18fa04ae
commit
0cf89d60f6
@ -113,9 +113,6 @@ public class OpenAPIV3Generator {
|
||||
.nullable(true));
|
||||
|
||||
// --> Aspect components
|
||||
components.addSchemas(
|
||||
ASPECTS + ASPECT_RESPONSE_SUFFIX,
|
||||
buildAspectsRefResponseSchema(entityRegistry, definitionNames));
|
||||
entityRegistry
|
||||
.getAspectSpecs()
|
||||
.values()
|
||||
@ -719,51 +716,6 @@ public class OpenAPIV3Generator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate schema for cross-entity scroll/list response
|
||||
*
|
||||
* @param entityRegistry entity registry
|
||||
* @return schema
|
||||
*/
|
||||
private static Schema buildAspectsRefResponseSchema(
|
||||
final EntityRegistry entityRegistry, final Set<String> definitionNames) {
|
||||
final Schema result =
|
||||
new Schema<>()
|
||||
.type(TYPE_OBJECT)
|
||||
.description(ASPECT_DESCRIPTION)
|
||||
.required(List.of(PROPERTY_VALUE));
|
||||
|
||||
// Create a list of reference schemas for each aspect
|
||||
List<Schema> aspectRefs =
|
||||
entityRegistry.getAspectSpecs().values().stream()
|
||||
.filter(a -> definitionNames.contains(a.getName()))
|
||||
.map(
|
||||
aspect ->
|
||||
new Schema<>()
|
||||
.$ref(PATH_DEFINITIONS + toUpperFirst(aspect.getPegasusSchema().getName())))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Add the value property with oneOf constraint
|
||||
result.addProperty(PROPERTY_VALUE, new Schema<>().oneOf(aspectRefs));
|
||||
|
||||
result.addProperty(
|
||||
NAME_SYSTEM_METADATA,
|
||||
new Schema<>()
|
||||
.type(TYPE_OBJECT)
|
||||
.anyOf(List.of(new Schema().$ref(PATH_DEFINITIONS + "SystemMetadata")))
|
||||
.description("System metadata for the aspect.")
|
||||
.nullable(true));
|
||||
result.addProperty(
|
||||
NAME_AUDIT_STAMP,
|
||||
new Schema<>()
|
||||
.type(TYPE_OBJECT)
|
||||
.anyOf(List.of(new Schema().$ref(PATH_DEFINITIONS + "AuditStamp")))
|
||||
.description("Audit stamp for the aspect.")
|
||||
.nullable(true));
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Schema buildAspectRefResponseSchema(final String aspectName) {
|
||||
final Schema result =
|
||||
new Schema<>()
|
||||
|
@ -105,41 +105,5 @@ public class OpenAPIV3GeneratorTest {
|
||||
entry ->
|
||||
assertEquals(
|
||||
"#/components/schemas/BatchGetRequestBody", entry.getValue().get$ref()));
|
||||
|
||||
// Assert aspect response schemas have value property with oneOf references
|
||||
Schema<?> aspectResponseSchema =
|
||||
openAPI.getComponents().getSchemas().get("AspectsAspectResponse_v3");
|
||||
Schema<?> valueProperty = aspectResponseSchema.getProperties().get("value");
|
||||
assertTrue(
|
||||
valueProperty.getOneOf() != null && !valueProperty.getOneOf().isEmpty(),
|
||||
"value property should use oneOf");
|
||||
|
||||
// Check each reference has proper format and capitalization
|
||||
valueProperty
|
||||
.getOneOf()
|
||||
.forEach(
|
||||
schema -> {
|
||||
String ref = schema.get$ref();
|
||||
assertTrue(
|
||||
ref != null && ref.startsWith("#/components/schemas/"),
|
||||
"reference should start with '#/components/schemas/': " + ref);
|
||||
|
||||
// Extract the last part after the last slash and check first character
|
||||
String refName = ref.substring(ref.lastIndexOf('/') + 1);
|
||||
assertTrue(
|
||||
Character.isUpperCase(refName.charAt(0)),
|
||||
"schema reference should start with capital letter: " + name);
|
||||
});
|
||||
|
||||
// Check for pegasus name example
|
||||
assertTrue(
|
||||
valueProperty.getOneOf().stream()
|
||||
.anyMatch(
|
||||
schema ->
|
||||
schema.get$ref().equals("#/components/schemas/StructuredPropertyDefinition")));
|
||||
assertTrue(
|
||||
valueProperty.getOneOf().stream()
|
||||
.noneMatch(
|
||||
schema -> schema.get$ref().equals("#/components/schemas/PropertyDefinition")));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user