Skip to content

Commit

Permalink
Recognize sap:label and sap:quickinfo (#101)
Browse files Browse the repository at this point in the history
* sap:label and sap:quickinfo

* Update CHANGELOG.md

* 0.11.0

* Bump dependencies

* bump ajv
  • Loading branch information
ralfhandl authored Aug 6, 2024
1 parent eabdafe commit fe15e6f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 39 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Changelog

## 0.11.0 - 2024-08-06

### Added

- `xml2json`: accept [V2 annotations](https://github.com/SAP/odata-vocabularies/blob/main/docs/v2-annotations.md) `label` and `quickinfo` and turn them into `Core.Description`, `quickinfo` wins if both are present

## 0.10.1 - 2024-07-04

### Fixed

- `xml2json`: ignore V2 annotation `display-format="Date"` and preserve original type
- `xml2json`: ignore [V2 annotation](https://github.com/SAP/odata-vocabularies/blob/main/docs/v2-annotations.md) `display-format="Date"` and preserve original type

## 0.10.0 - 2024-03-01

Expand All @@ -28,7 +34,7 @@

### Fixed

- `xml2json`: OData V2 EntitySet element may contain Documentation element
- `xml2json`: OData V2 `EntitySet` element may contain `Documentation` element

## 0.8.2 - 2023-06-15

Expand Down
9 changes: 9 additions & 0 deletions lib/xml2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,15 @@ module.exports.xml2json = function (
for (const attribute of Object.values(node.attributes)) {
if (attribute.uri !== SAP_V2_URI) continue;
switch (attribute.local) {
case "label": {
const term = `@${alias[VOCABULARIES.Core.Namespace]}.Description`;
if (target[term] === undefined) target[term] = attribute.value;
break;
}
case "quickinfo":
target[`@${alias[VOCABULARIES.Core.Namespace]}.Description`] =
attribute.value;
break;
case "creatable":
creatable = attribute.value === "true";
break;
Expand Down
65 changes: 36 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "odata-csdl",
"version": "0.10.1",
"version": "0.11.0",
"description": "Convert CSDL XML to CSDL JSON",
"homepage": "https://github.com/oasis-tcs/odata-csdl-schemas/blob/master/lib/README.md",
"bugs": "https://github.com/oasis-tcs/odata-csdl-schemas/issues",
Expand All @@ -22,10 +22,10 @@
"sax": "^1.4.1"
},
"devDependencies": {
"ajv": "^8.16.0",
"ajv": "^8.17.1",
"c8": "^10.1.2",
"eslint": "^9.6.0",
"mocha": "^10.6.0"
"eslint": "^9.8.0",
"mocha": "^10.7.0"
},
"scripts": {
"build": "npm run build-js && npm run build-xsd",
Expand Down
5 changes: 4 additions & 1 deletion test/v2-annotations.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,17 @@
"id"
],
"id": {
"@OASIS_Core.Computed": true
"@OASIS_Core.Computed": true,
"@OASIS_Core.Description": "Identifier"
},
"pattern": {
"$Nullable": true,
"@OASIS_Core.Description": "Quick Info",
"@Validation.Pattern": "^(foo)+$"
},
"readonly": {
"$Nullable": true,
"@OASIS_Core.Description": "Quick Info",
"@OASIS_Core.Computed": true
},
"immutable": {
Expand Down
8 changes: 5 additions & 3 deletions test/v2-annotations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
<PropertyRef Name="id" />
</Key>
<Property Name="id" Type="Edm.String" Nullable="false" sap:creatable="false"
sap:updatable="false" />
<Property Name="pattern" Type="Edm.String" sap:validation-regexp="^(foo)+$" />
<Property Name="readonly" Type="Edm.String" sap:creatable="false" sap:updatable="false" />
sap:updatable="false" sap:label="Identifier" />
<Property Name="pattern" Type="Edm.String" sap:validation-regexp="^(foo)+$"
sap:label="Label" sap:quickinfo="Quick Info" />
<Property Name="readonly" Type="Edm.String" sap:creatable="false" sap:updatable="false"
sap:quickinfo="Quick Info" sap:label="Label" />
<Property Name="immutable" Type="Edm.String" sap:updatable="false" />
<Property Name="date" Type="Edm.DateTime" sap:display-format="Date" />
<Property Name="time" Type="Edm.Time" Precision="3" />
Expand Down

0 comments on commit fe15e6f

Please sign in to comment.