diff --git a/packages/td-tools/src/util/asset-interface-description.ts b/packages/td-tools/src/util/asset-interface-description.ts index 7d0c39880..946e37000 100644 --- a/packages/td-tools/src/util/asset-interface-description.ts +++ b/packages/td-tools/src/util/asset-interface-description.ts @@ -28,13 +28,12 @@ const logInfo = debug(`${namespace}:info`); /** Utilities around Asset Interface Description * https://github.com/admin-shell-io/submodel-templates/tree/main/development/Asset%20Interface%20Description/1/0 * - * e.g, transform to TD + * e.g, transform AAS (or AID submodel) to TD or vicerversa transform TD to AAS (or AID submodel) * */ /* * TODOs - * - Support desription(s) and title(s) * - transformToTD without any binding prefix (Idea: collect first all possible bindings) * - what is the desired input/output? string, object, ... ? * - what are options that would be desired? (context version, id, security, ...) -> template mechanism fine? @@ -679,7 +678,13 @@ export class AssetInterfaceDescriptionUtil { // semanticId needed? // embeddedDataSpecifications needed? value: [ - // support + { + idShort: "title", + valueType: "xs:string", + value: td.title, + modelType: "Property", + }, + // support and other? this.createEndpointMetadata(td), // EndpointMetadata like base, security and securityDefinitions this.createInterfaceMetadata(td, protocol), // InterfaceMetadata like properties, actions and events // externalDescriptor ? @@ -870,9 +875,28 @@ export class AssetInterfaceDescriptionUtil { }); } + let description; + if (propertyValue.descriptions) { + description = []; + for (const langKey in propertyValue.descriptions) { + const langValue = propertyValue.descriptions[langKey]; + description.push({ + language: langKey, + text: langValue, + }); + } + } else if (propertyValue.description) { + // fallback + description = []; + description.push({ + language: "en", // TODO where to get language identifier + text: propertyValue.description, + }); + } + properties.push({ idShort: propertyKey, - // TODO description + description: description, value: propertyValues, modelType: "SubmodelElementCollection", }); diff --git a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts index 3673526e6..048f8be26 100644 --- a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts +++ b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts @@ -181,6 +181,10 @@ class AssetInterfaceDescriptionUtilTest { status: { type: "string", observable: true, + descriptions: { + en: "Statistic", + de: "Statistik", + }, forms: [ { href: "stat", @@ -201,9 +205,13 @@ class AssetInterfaceDescriptionUtilTest { expect(smObj).to.have.property("submodelElements").to.be.an("array").to.have.lengthOf.greaterThan(0); const smInterface = smObj.submodelElements[0]; expect(smInterface).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0); + let hasThingTitle = false; let hasEndpointMetadata = false; for (const smValue of smInterface.value) { - if (smValue.idShort === "EndpointMetadata") { + if (smValue.idShort === "title") { + hasThingTitle = true; + expect(smValue).to.have.property("value").to.equal("testTD"); + } else if (smValue.idShort === "EndpointMetadata") { hasEndpointMetadata = true; const endpointMetadata = smValue; expect(endpointMetadata).to.have.property("value").to.be.an("array").to.have.lengthOf.greaterThan(0); @@ -257,6 +265,7 @@ class AssetInterfaceDescriptionUtilTest { expect(hasSecurityDefinitions).to.equal(true); } } + expect(hasThingTitle, "No thing title").to.equal(true); expect(hasEndpointMetadata, "No EndpointMetadata").to.equal(true); // InterfaceMetadata with properties etc @@ -274,6 +283,7 @@ class AssetInterfaceDescriptionUtilTest { .to.be.an("array") .to.have.lengthOf.greaterThan(0); let hasPropertyStatus = false; + let hasPropertyStatusDescription = false; for (const propertyValue of interactionValues.value) { if (propertyValue.idShort === "status") { hasPropertyStatus = true; @@ -333,8 +343,24 @@ class AssetInterfaceDescriptionUtilTest { expect(hasObservable).to.equal(true); expect(hasForms).to.equal(true); } + if (propertyValue.description) { + hasPropertyStatusDescription = true; + expect(propertyValue) + .to.have.property("description") + .to.eql([ + { + language: "en", + text: "Statistic", + }, + { + language: "de", + text: "Statistik", + }, + ]); + } } expect(hasPropertyStatus).to.equal(true); + expect(hasPropertyStatusDescription).to.equal(true); } } expect(hasProperties).to.equal(true);