Skip to content

Commit

Permalink
Keep entity types contained in kept entity types
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Dec 14, 2023
1 parent 6ad41b4 commit 124d123
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
16 changes: 14 additions & 2 deletions lib/edm.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,23 @@ module.exports.EDM = class {
*/
referencedEntityTypes(rootResources) {
const entityTypes = [];

for (const name of rootResources) {
const child = this.entityContainer[name];
if (child?.$Type) entityTypes.push(child.$Type);
if (child?.$Type && !entityTypes.includes(child.$Type))
entityTypes.push(child.$Type);
}

// collect contained entity types
for (const name of entityTypes) {
//TODO: contained entity types
const containedTypes = this.propertiesOfStructuredType(this.element(name))
.filter((pair) => pair[1].$ContainsTarget)
.map((pair) => pair[1].$Type);
for (const ct of containedTypes)
if (!entityTypes.includes(ct)) entityTypes.push(ct);
}
//TODO: contained entity types

//TODO: action/function import return type
return entityTypes;
}
Expand Down
55 changes: 47 additions & 8 deletions test/keep.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const assert = require("assert");

//TODO:
// association to contained entity "bestContained": preserve type
// keep action import and function import: keep parameter and response types

const { paths, operations, schemas } = require("./utilities");
Expand Down Expand Up @@ -258,7 +257,22 @@ describe("Keep", function () {
$Kind: "EntityType",
$Key: ["id"],
id: {},
data: {},
bestOfContained: {
$Kind: "NavigationProperty",
$Type: "this.CET2",
$Nullable: true,
},
contained: {
$Kind: "NavigationProperty",
$Type: "this.CET2",
$Collection: true,
$ContainsTarget: true,
},
},
CET2: {
$Kind: "EntityType",
$Key: ["id"],
id: {},
},
Container: {
"@Capabilities.KeyAsSegmentSupported": true,
Expand All @@ -273,6 +287,13 @@ describe("Keep", function () {
"/Set/{id}/bestOfContained": { get: {} },
"/Set/{id}/contained": { get: {}, post: {} },
"/Set/{id}/contained/{id_1}": { get: {}, patch: {}, delete: {} },
"/Set/{id}/contained/{id_1}/bestOfContained": { get: {} },
"/Set/{id}/contained/{id_1}/contained": { get: {}, post: {} },
"/Set/{id}/contained/{id_1}/contained/{id_2}": {
get: {},
patch: {},
delete: {},
},
},
components: {
schemas: {
Expand Down Expand Up @@ -308,9 +329,27 @@ describe("Keep", function () {
title: "ET (for update)",
type: "object",
},
"this.CET": {},
"this.CET": {
title: "CET",
type: "object",
properties: {
id: { type: "string" },
bestOfContained: {
allOf: [{ $ref: "#/components/schemas/this.CET2" }],
nullable: true,
},
contained: {
type: "array",
items: { $ref: "#/components/schemas/this.CET2" },
},
"contained@count": { $ref: "#/components/schemas/count" },
},
},
"this.CET-create": {},
"this.CET-update": {},
"this.CET2": {},
"this.CET2-create": {},
"this.CET2-update": {},
},
},
};
Expand All @@ -322,11 +361,6 @@ describe("Keep", function () {
"Operations",
);
assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas");
assert.deepStrictEqual(
actual.components.schemas.stub,
{ title: "Stub object", type: "object" },
"Stub object",
);
assert.deepStrictEqual(
actual.components.schemas["this.ET"],
expected.components.schemas["this.ET"],
Expand All @@ -342,5 +376,10 @@ describe("Keep", function () {
expected.components.schemas["this.ET-update"],
"update structure",
);
assert.deepStrictEqual(
actual.components.schemas["this.CET"],
expected.components.schemas["this.CET"],
"read structure of component entity type",
);
});
});

0 comments on commit 124d123

Please sign in to comment.