Skip to content

Commit

Permalink
Also keep contained entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfhandl committed Nov 21, 2023
1 parent cb6ead3 commit 5e9195c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Added

- Command-line option `--keep` (short `-k`) to specify which root resources (entity sets, singletons, action imports, function imports) to keep.
- Paths for the root resources are kept, as are paths to contained entities and bound functions.
- Paths for the root resources are kept, as are paths to contained entities and bound actions and functions.
- Types referenced by the (return) type of root resources via structural properties or containment navigation properties are also kept.
- Non-containment navigation properties to entity types not kept are changed to use a generic stub object type without properties.
- Deep paths to stubbed entity types are omitted.
Expand Down
7 changes: 6 additions & 1 deletion lib/csdl2openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,11 @@ module.exports.csdl2openapi = function (

const properties = navigationPathMap(type);
for (const [name, property] of Object.entries(properties)) {
if (entityTypesToKeep && !entityTypesToKeep.includes(property.$Type))
if (
!property.$ContainsTarget &&
entityTypesToKeep &&
!entityTypesToKeep.includes(property.$Type)
)
continue;

const navigationPath =
Expand Down Expand Up @@ -2166,6 +2170,7 @@ module.exports.csdl2openapi = function (
for (let [name, property] of model.propertiesOfStructuredType(type)) {
if (
property.$Kind === "NavigationProperty" &&
!property.$ContainsTarget &&
entityTypesToKeep &&
!entityTypesToKeep.includes(property?.$Type)
) {
Expand Down
15 changes: 15 additions & 0 deletions test/keep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ describe("Keep", function () {
id: {},
complex: { $Type: "this.CT" },
simple: { $Type: "this.TD" },
contained: {
$Kind: "NavigationProperty",
$Type: "this.CET",
$ContainsTarget: true,
},
two: { $Kind: "NavigationProperty", $Type: "this.ET2" },
twoMany: {
$Kind: "NavigationProperty",
Expand All @@ -107,6 +112,10 @@ describe("Keep", function () {
foo: {},
},
TD: { $Kind: "TypeDefinition", $UnderlyingType: "Edm.DateTimeOffset" },
CET: {
$Kind: "EntityType",
data: {},
},
ET2: {
$Kind: "EntityType",
$Key: ["id"],
Expand All @@ -130,6 +139,7 @@ describe("Keep", function () {
paths: {
"/Set": { get: {}, post: {} },
"/Set/{id}": { get: {}, patch: {}, delete: {} },
"/Set/{id}/contained": { get: {}, patch: {} },
},
components: {
schemas: {
Expand All @@ -140,6 +150,7 @@ describe("Keep", function () {
id: { type: "string" },
complex: { $ref: "#/components/schemas/this.CT" },
simple: { $ref: "#/components/schemas/this.TD" },
contained: { $ref: "#/components/schemas/this.CET" },
two: { $ref: "#/components/schemas/stub" },
twoMany: {
type: "array",
Expand All @@ -159,6 +170,7 @@ describe("Keep", function () {
id: { type: "string" },
complex: { $ref: "#/components/schemas/this.CT-create" },
simple: { $ref: "#/components/schemas/this.TD" },
contained: { $ref: "#/components/schemas/this.CET-create" },
two: { $ref: "#/components/schemas/entityReference" },
},
required: ["id"],
Expand All @@ -175,6 +187,9 @@ describe("Keep", function () {
"this.CT-create": {},
"this.CT-update": {},
"this.TD": {},
"this.CET": {},
"this.CET-create": {},
"this.CET-update": {},
},
},
};
Expand Down

0 comments on commit 5e9195c

Please sign in to comment.