diff --git a/CHANGELOG.md b/CHANGELOG.md index 50abd0da..c9072866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/csdl2openapi.js b/lib/csdl2openapi.js index 72e1da0f..10081494 100644 --- a/lib/csdl2openapi.js +++ b/lib/csdl2openapi.js @@ -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 = @@ -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) ) { diff --git a/test/keep.test.js b/test/keep.test.js index f91d25fc..45e13c36 100644 --- a/test/keep.test.js +++ b/test/keep.test.js @@ -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", @@ -107,6 +112,10 @@ describe("Keep", function () { foo: {}, }, TD: { $Kind: "TypeDefinition", $UnderlyingType: "Edm.DateTimeOffset" }, + CET: { + $Kind: "EntityType", + data: {}, + }, ET2: { $Kind: "EntityType", $Key: ["id"], @@ -130,6 +139,7 @@ describe("Keep", function () { paths: { "/Set": { get: {}, post: {} }, "/Set/{id}": { get: {}, patch: {}, delete: {} }, + "/Set/{id}/contained": { get: {}, patch: {} }, }, components: { schemas: { @@ -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", @@ -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"], @@ -175,6 +187,9 @@ describe("Keep", function () { "this.CT-create": {}, "this.CT-update": {}, "this.TD": {}, + "this.CET": {}, + "this.CET-create": {}, + "this.CET-update": {}, }, }, };