eclipse-esmf / esmf-semantic-aspect-meta-model

Formal and textual specification of the Semantic Aspect Meta Model (SAMM)
https://eclipse-esmf.github.io/samm-specification/snapshot/index.html
Mozilla Public License 2.0
45 stars 9 forks source link

[BUG] xsd:decimal in SAMM is converted to type=number in json-scheme? #262

Open miwamasa opened 8 months ago

miwamasa commented 8 months ago

Describe the bug data type with "xsd:decimal" is converted to type=number in json-scheme, where in the carbonfootprint in WBCSD context, it should be string with some constraint in json.

SAMM file=Pcf.ttl

A carbonfootprint example of eclipse-tractusx https://github.com/eclipse-tractusx/sldt-semantic-models/blob/main/io.catenax.pcf/4.0.1/Pcf.ttl

the Pcf.ttl supposed to be aligned with the WBCSD's specification:

Technical Specifications for PCF Data Exchange (Version 2.0.1-20230927)

in the specification, the "fossilGhgEmissions" is defined as "Decimal" with type=String.

in the Pcf.ttl, "fossilGhgEmissions" type is defined as "xsd:decimal" via (fossilGhgEmissions-> PositiveEmissionsTrait;->PositiveEmission)

image

Where

the json-schema converted by samm-cli indicates "fossilGhgEmissions"'s type is "number" which means float in json via (fossilGhgEmissions->PositiveEmissionsTrait)

image

Additional context As far as I know, xsd:decimal permits both string format "2.24" and numeric format 2.24.

But in json context, it should be string with some format constraints.

for example official json-schema from WBCSD (although v1) says:

https://github.com/wbcsd/pathfinder-use-case-001/blob/main/spec/rest-api/openapi-1.0.0-beta2.json

fossileGhgEmission is positivedecimal which is defined as string with regrex constraint.

image

miwamasa commented 8 months ago

Additional Information: current SAMM cli converts xs:decimal to AAS as INTEGER_MEASURE

image

miwamasa commented 8 months ago

The issue is summerized as follows:

Background:

FYI: OData v4 case

FYI: In the OData v4(which is database community standard), the precision-wise data type is Edm.Decimal which is converted to JSON String or number, depending on the option IEEE754Compatible=true or false.

image

chris-volk commented 7 months ago

Dear @miwamasa , apologies for the late reaction. Thanks for reporting this topic and giving all the context. Myself I knew PCF, but not the WBCSD specification.

I understand that you're working in the context of catena-x with product carbon footprint. First of all, the discussion of datatypes in json, particularly strings, is coming up repeatedly and we try to maintain the right balance between diversity in modeling capabilities and implementation friendliness. We shall capture it even better in a forum article or in a documentation section.

The current state of SAMM and serialization in SDK is according to https://eclipse-esmf.github.io/samm-specification/snapshot/payloads.html#data-type-mappings : hence, current status is that within ESMF XSD:decimal is always represented as a JSON number. This is consistent and allows a serialization, therefore what you are reporting is not a bug within ESMF. However, this does not help you yet.

Let me outline different paths that catena-x and ESMF can tackle your issue, which have to be discussed: