Skip to content

Commit

Permalink
function allowedValuesList
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Apr 9, 2024
1 parent 59cf667 commit 4b41e65
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
33 changes: 20 additions & 13 deletions lib/csdl2markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
const depr = deprecated(modelElement);
const text = modelElement[voc.Core.Description];
const long = modelElement[voc.Core.LongDescription];
let allowedValues = "";
const values = modelElement[voc.Validation.AllowedValues];
if (values)
values.forEach((v) => {
v.$$name = v.Value;
v.$$parent = "nofragment";
allowedValues += "<br>- " + sourceLink(v) + experimentalOrDeprecated(v);
const allowedValue = descriptionInTable(v);
if (allowedValue) allowedValues += ": " + allowedValue;
});

const example = modelElement[voc.Core.Example];
if (example) {
Expand All @@ -607,9 +597,7 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
: escape(text) +
(example ? " (" + sourceLink(example) + ")" : "") +
(long ? "<br>" + escape(long) : "") +
(allowedValues
? "<br>*Allowed values:*" + escape(allowedValues)
: "") +
allowedValuesList(modelElement[voc.Validation.AllowedValues] || []) +
applicableTermsList(
modelElement[voc.Validation.ApplicableTerms] || [],
) +
Expand Down Expand Up @@ -644,6 +632,25 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
return text.join("");
}

/**
* List of allowed values
* @param {array} allowedValues Array of allowed values
* @return {string} Text
*/
function allowedValuesList(allowedValues) {
const text = [];
if (allowedValues.length > 0) text.push("<br>Allowed values:");
allowedValues.forEach((v) => {
v.$$name = v.Value;
v.$$parent = "nofragment";
let allowedValue = "<br>- " + sourceLink(v) + experimentalOrDeprecated(v);
const description = descriptionInTable(v);
if (description) allowedValue += ": " + description;
text.push(allowedValue);
});
return text.join("");
}

/**
* Escape text for use in Markdown
* @param {string} text Text to escape
Expand Down
2 changes: 1 addition & 1 deletion test/csdl2markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ describe("Edge cases", function () {
"",
"Property|Type|Description",
":-------|:---|:----------",
"Status|String|The status<br>*Allowed values:*<br>- Open: open<br>- Closed *(Deprecated)*: Nothing is ever closed",
"Status|String|The status<br>Allowed values:<br>- Open: open<br>- Closed *(Deprecated)*: Nothing is ever closed",
"",
];
const markdown = lib.csdl2markdown(filename, vocabulary);
Expand Down
2 changes: 1 addition & 1 deletion vocabularies/Org.OData.Capabilities.V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Property|Type|Description
[ReferencesAcrossChangeSetsSupported](./Org.OData.Capabilities.V1.xml#L397:~:text=<ComplexType%20Name="-,BatchSupportType,-")|Boolean|Service supports Content-ID referencing across change sets
[EtagReferencesSupported](./Org.OData.Capabilities.V1.xml#L400:~:text=<ComplexType%20Name="-,BatchSupportType,-")|Boolean|Service supports referencing Etags from previous requests
[RequestDependencyConditionsSupported](./Org.OData.Capabilities.V1.xml#L403:~:text=<ComplexType%20Name="-,BatchSupportType,-")|Boolean|Service supports the `if` member in JSON batch requests
[SupportedFormats](./Org.OData.Capabilities.V1.xml#L406:~:text=<ComplexType%20Name="-,BatchSupportType,-")|\[MediaType\]|Media types of supported formats for $batch<br>*Allowed values:*<ul><li>[multipart/mixed](./Org.OData.Capabilities.V1.xml#L411): [Multipart Batch Format](http://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html#sec_MultipartBatchFormat)</li><li>[application/json](./Org.OData.Capabilities.V1.xml#L415): [JSON Batch Format](http://docs.oasis-open.org/odata/odata-json-format/v4.01/cs01/odata-json-format-v4.01-cs01.html#sec_BatchRequestsandResponses)</li></ul>
[SupportedFormats](./Org.OData.Capabilities.V1.xml#L406:~:text=<ComplexType%20Name="-,BatchSupportType,-")|\[MediaType\]|Media types of supported formats for $batch<br>Allowed values:<br>- [multipart/mixed](./Org.OData.Capabilities.V1.xml#L411): [Multipart Batch Format](http://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html#sec_MultipartBatchFormat)<br>- [application/json](./Org.OData.Capabilities.V1.xml#L415): [JSON Batch Format](http://docs.oasis-open.org/odata/odata-json-format/v4.01/cs01/odata-json-format-v4.01-cs01.html#sec_BatchRequestsandResponses)

**Applicable Annotation Terms:**

Expand Down

0 comments on commit 4b41e65

Please sign in to comment.