diff --git a/lib/csdl2openapi.js b/lib/csdl2openapi.js index cd82d6f8..0b70aec1 100644 --- a/lib/csdl2openapi.js +++ b/lib/csdl2openapi.js @@ -68,7 +68,6 @@ module.exports.csdl2openapi = function ( list: [], used: {}, entityReferenceNeeded: false, - stubObjectNeeded: false, }; const model = new EDM(); @@ -2091,8 +2090,6 @@ module.exports.csdl2openapi = function ( if (requiredSchemas.entityReferenceNeeded) ordered.entityReference = entityReference(); ordered.error = error(); - if (requiredSchemas.stubObjectNeeded) - ordered.stub = { title: "Stub object", type: "object" }; } return ordered; @@ -2273,14 +2270,14 @@ module.exports.csdl2openapi = function ( } /** - * Return object if it references a kept type, otherwise clone it and reference the stub type + * Return element if it references a kept type, otherwise clone it and reference the stub type + * @param {object} element typed model element * @return {object} original element or clone referencing stub type */ function stubIfNotKept(element) { if (entityTypesToKeep && !entityTypesToKeep.includes(element?.$Type)) { const clone = { ...element }; - clone.$Type = "stub"; - requiredSchemas.stubObjectNeeded = true; + clone.$Type = `stub-${element.$Type}`; return clone; } else return element; } @@ -2641,7 +2638,12 @@ module.exports.csdl2openapi = function ( }; break; default: - if (element.$Type.startsWith("Edm.")) { + if (element.$Type.startsWith("stub-")) { + s = { + type: "object", + description: `Stub for ${element.$Type.substring(5)}`, + }; + } else if (element.$Type.startsWith("Edm.")) { messages.push("Unknown type: " + element.$Type); } else { let type = model.element(element.$Type); diff --git a/test/keep.test.js b/test/keep.test.js index d4e3a381..04fa5c2e 100644 --- a/test/keep.test.js +++ b/test/keep.test.js @@ -162,15 +162,16 @@ describe("Keep", function () { complex: { $ref: "#/components/schemas/this.CT" }, simple: { $ref: "#/components/schemas/this.TD" }, contained: { $ref: "#/components/schemas/this.CET" }, - two: { $ref: "#/components/schemas/stub" }, + two: { type: "object", description: "Stub for this.ET2" }, twoMany: { type: "array", - items: { $ref: "#/components/schemas/stub" }, + items: { type: "object", description: "Stub for this.ET2" }, }, "twoMany@count": { $ref: "#/components/schemas/count" }, twoOptional: { nullable: true, - allOf: [{ $ref: "#/components/schemas/stub" }], + type: "object", + description: "Stub for this.ET2", }, }, }, @@ -215,11 +216,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"], @@ -748,12 +744,21 @@ describe("Keep", function () { operations(expected), "Operations", ); - assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas"); assert.deepStrictEqual( - actual.components.schemas.stub, - { title: "Stub object", type: "object" }, - "Stub object", + actual.paths["/Set/{id}/this.act"].post.responses["200"].content[ + "application/json" + ].schema, + { type: "object", description: "Stub for this.ET2" }, + "stubbed action return type", ); + assert.deepStrictEqual( + actual.paths["/Set/{id}/this.fun()"].get.responses["200"].content[ + "application/json" + ].schema, + { type: "object", description: "Stub for this.ET2" }, + "stubbed function return type", + ); + assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas"); assert.deepStrictEqual( actual.components.schemas["this.ET"], expected.components.schemas["this.ET"],