mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-26 01:18:20 +00:00
fix(openapi-spec): fix openapi spec oneOf schema (#12561)
This commit is contained in:
parent
0ed3d7f4a4
commit
65376ee2d3
@ -731,13 +731,16 @@ public class OpenAPIV3Generator {
|
||||
.description(ASPECT_DESCRIPTION)
|
||||
.required(List.of(PROPERTY_VALUE));
|
||||
|
||||
entityRegistry
|
||||
.getAspectSpecs()
|
||||
.values()
|
||||
.forEach(
|
||||
aspect ->
|
||||
result.addProperty(
|
||||
PROPERTY_VALUE, new Schema<>().$ref(PATH_DEFINITIONS + aspect.getName())));
|
||||
// Create a list of reference schemas for each aspect
|
||||
List<Schema> aspectRefs =
|
||||
entityRegistry.getAspectSpecs().values().stream()
|
||||
.map(aspect -> new Schema<>().$ref(PATH_DEFINITIONS + toUpperFirst(aspect.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<>()
|
||||
|
||||
@ -105,5 +105,30 @@ 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user