diff --git a/lib/csdl2markdown.js b/lib/csdl2markdown.js
index a3e08842..d67640a9 100644
--- a/lib/csdl2markdown.js
+++ b/lib/csdl2markdown.js
@@ -314,7 +314,9 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
}
if (type.$Kind == "TypeDefinition") {
- lines.push("**Type:** " + typeLink({ $Type: type.$UnderlyingType }));
+ lines.push(
+ "**Type:** " + typeLink({ ...type, $Type: type.$UnderlyingType }),
+ );
lines.push("");
}
@@ -610,13 +612,9 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
* @return {string} Text
*/
function applicableTermsList(applicableTerms) {
- const text = [];
- if (applicableTerms.length > 0) text.push("
Applicable Annotation Terms:
");
- applicableTerms.forEach((term) => {
- text.push(`- ${typeLink({ $Type: term })}
`);
- });
- if (applicableTerms.length > 0) text.push("
");
- return text.join("");
+ return applicableTerms.length > 0
+ ? "
Applicable Annotation Terms:" + linkList(applicableTerms)
+ : "";
}
/**
@@ -625,13 +623,9 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
* @return {string} Text
*/
function allowedTermsList(allowedTerms) {
- const text = [];
- if (allowedTerms.length > 0) text.push("
Allowed terms:");
- allowedTerms.forEach((term) => {
- text.push(`- ${typeLink({ $Type: term })}
`);
- });
- if (allowedTerms.length > 0) text.push("
");
- return text.join("");
+ return allowedTerms.length > 0
+ ? "
Allowed Terms:" + linkList(allowedTerms)
+ : "";
}
/**
@@ -729,7 +723,7 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
if (modelElement.$Type == "com.sap.vocabularies.Common.v1.Experimental")
customFile = "Common.md";
- return (
+ let type =
(modelElement.$Collection ? "\\[" : "") +
(customType ? "[" : "") +
(customType
@@ -741,8 +735,31 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
: np.name) +
(modelElement.$Nullable ? "?" : "") +
(customType ? "](" + customFile + "#" + np.name + ")" : "") +
- (modelElement.$Collection ? "\\]" : "")
- );
+ (modelElement.$Collection ? "\\]" : "");
+ if (modelElement[voc.Validation.DerivedTypeConstraint])
+ type +=
+ "
Allowed Derived Types:" +
+ linkList(modelElement[voc.Validation.DerivedTypeConstraint]);
+ return type;
+ }
+
+ /**
+ * a qualified name consists of a namespace or alias, a dot, and a simple name
+ * @param {object} list of model element names
+ * @return {string} list of links to these model elements
+ */
+ function linkList(list) {
+ let text = "";
+ for (let t of list) {
+ let link;
+ if (t.startsWith("Collection(")) {
+ t = t.substring(11, t.length - 1);
+ link = "[.]";
+ } else link = ".";
+ text += `- ${link.replace(".", typeLink({ $Type: t }))}
`;
+ }
+ text += "
";
+ return text;
}
/**
@@ -789,6 +806,7 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
"AllowedValues",
"ApplicableTerms",
"AllowedTerms",
+ "DerivedTypeConstraint",
"Exclusive",
"Maximum",
"Minimum",
diff --git a/test/csdl2markdown.test.js b/test/csdl2markdown.test.js
index d1ff2385..1e7eca0d 100644
--- a/test/csdl2markdown.test.js
+++ b/test/csdl2markdown.test.js
@@ -263,7 +263,7 @@ describe("Non-OASIS Vocabularies", function () {
"",
"Term|Type|Description",
":---|:---|:----------",
- 'Reference|AnnotationPath|Reference to a description
Allowed terms:- [Description](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md#Description)
- [WithoutReference](#WithoutReference)
',
+ 'Reference|AnnotationPath|Reference to a description
Allowed Terms:- [Description](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md#Description)
- [WithoutReference](#WithoutReference)
',
"",
];
const markdown = lib.csdl2markdown(filename, vocabulary);
@@ -557,6 +557,69 @@ describe("Edge cases", function () {
const markdown = lib.csdl2markdown(filename, vocabulary);
assert.deepStrictEqual(markdown, expectedMarkdown);
});
+
+ it("Allowed derived types", function () {
+ const filename = "allowedDerivedTypes.xml";
+ const type = {
+ "@Org.OData.Core.V1.Description": "Tag or duration",
+ "@Org.OData.Validation.V1.DerivedTypeConstraint": [
+ "Org.OData.Core.V1.Tag",
+ "Edm.Duration",
+ ],
+ };
+ const mdtype =
+ "PrimitiveType
Allowed Derived Types:- [Tag](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Core.V1.md#Tag)
- Duration
";
+ const vocabulary = {
+ $Version: "4.01",
+ $Reference: {
+ "https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.json":
+ {
+ $Include: [
+ {
+ $Namespace: "Org.OData.Core.V1",
+ },
+ ],
+ },
+ },
+ "Allowed.v1": {
+ Duration: {
+ $Kind: "TypeDefinition",
+ $UnderlyingType: "Edm.PrimitiveType",
+ ...type,
+ },
+ Event: {
+ $Kind: "ComplexType",
+ Duration: {
+ $Type: "Edm.PrimitiveType",
+ ...type,
+ },
+ },
+ },
+ };
+ const expectedMarkdown = [
+ "# Allowed Vocabulary",
+ "**Namespace: [Allowed.v1](allowedDerivedTypes.xml)**",
+ "",
+ "",
+ "",
+ '',
+ "## Duration",
+ "**Type:** " + mdtype,
+ "",
+ "Tag or duration",
+ "",
+ '',
+ "## Event",
+ "",
+ "",
+ "Property|Type|Description",
+ ":-------|:---|:----------",
+ "Duration|" + mdtype + "|Tag or duration",
+ "",
+ ];
+ const markdown = lib.csdl2markdown(filename, vocabulary);
+ assert.deepStrictEqual(markdown, expectedMarkdown);
+ });
});
function check(actual, expected) {