Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require type (class) declaration of the root json object for proper json-ld interpretation. #9

Open
Fak3 opened this issue Dec 4, 2019 · 3 comments

Comments

@Fak3
Copy link

Fak3 commented Dec 4, 2019

In our models, there are some (semantically distinct) properties with generic names, prone to be clashed with each other. In the json-ld vocabulary we will make sure they will have distinct fully-qualified identifiers, for ex statusCode of the TransportRoute class and statusCode of the TransportMovement class should probably be represented as edi3:routeStatusCode and edi3:movementStatusCode in the vocabulary, each property will have different domain and range.

The problem is that in the plain json, they currently share the same key statusCode, and if a property appears at the root json object, the @context magic of json-ld will not have a way to tell which one of these two properties is used, unless that root object have its type (class) specified. (if it appears at non-root sub-object, @context is able to distinct them by the full path of that sub-object inside the root)

There is also a broader problem of potential clash of our vocab properties with other vocabs which client may want to use - it will not be possible to tell which one is used if it appears at the root.

So I would suggest that our json schema serialization rules mandate adding the type for the classes which instances will appear at the root (in REST responses or requests)

If the class already have the type property in our model - no change required. If it does not - the JSON schema should be augmented with type property with a static value equal to the class name, for ex: type: TransportMovement

@Fak3 Fak3 changed the title Require type (class) declaration of the root json object for proper json-ld interpreation. Require type (class) declaration of the root json object for proper json-ld interpretation. Dec 16, 2019
@onthebreeze
Copy link
Contributor

I think this sounds fine - but would like to see an example or two.

@Fak3
Copy link
Author

Fak3 commented Dec 20, 2019

For ex vessels response and request would look like this:

{
  "@context": "https://edi3.org/context.json",
  "identification": "http://maersk.com/vessels/01",
  "type": "Vessel",  # The type (class) of this object
  "owner": { 
       "identification": "http://maersk.com", 
       "name": "Maersk"
  }
}

@Fak3
Copy link
Author

Fak3 commented Dec 20, 2019

So the rule for generating json schema would be:
When generating schema for the root object of the interface, and the class which this interface implements does not have top-level property named "type", then add a property named "type" with fixed string value, equal to this class name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants