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

Schema to class hierarchy and deserialization #429

Open
yvdh opened this issue Apr 28, 2022 · 3 comments
Open

Schema to class hierarchy and deserialization #429

yvdh opened this issue Apr 28, 2022 · 3 comments

Comments

@yvdh
Copy link

yvdh commented Apr 28, 2022

Hello,

Disregard if this is not the right forum ...
I am trying to create an EPCIS repo and API from the artefacts here.
I currently have an EPCIS 1.1 environment, but I really want to move to a JSON-REST based one as soon as possible, away from SOAP (I also feel a clear shift in emphasis to JSON).
I want to use a very pragmatic storage model in MS SQL server: just split up any incoming EPCIS documents in a table 'Document' with the json string without the events in it, and a related table 'Event' with the EPCIS events as json strings. Performance should be handled by creating the necessary indexes on certain json paths, mainly the EPC uri's.
I work in .net - c#, and have generated an EPCIS server from the swagger website. This resulted in a series of serializable models, but their inheritance does not seem to reflect the JSON schema at all.
E.g. all the events (ObjectEvent, ...) inherit from a generated 'ModelEvent' (which has appropriate base properties), while the 'EventList' property in the EPCISDocumentBody is a List of EPCISEvent which is an mostly empty class which is not related to 'ModelEvent' in any way.
Consequenlty, any attempt at deserialization (e.g. from the sample documents) results in mostly empty objects.
This is not much of a problem when adding EPCISDocuments during capture, these can easily be parsed and split in a typeless manner.
It's much more of a problem when querying and assembling QueryDocuments in the Query interface or deserializing objects client-side.
I could move away from the standard Query interfaces, and just basically return EPCIS events for what I think will be mainly EPC uri based queries, but even these much simpler objects do not seem to deserialize properly in the swagger generated models ...

I feel I am doing something very wrong here, but what? At the same time there seems to be a fundamental discrepancy between the JSON or XML schema and the models hierarchies that are generated from them by any current tooling ... (I have also tried NSwag and Visual Studio itself, they all lead to different and seemingly inconsistent models).

Any help is much appreciated ...
Yves

@jmcanterafonseca-iota
Copy link
Collaborator

jmcanterafonseca-iota commented Apr 29, 2022 via email

@yvdh
Copy link
Author

yvdh commented May 2, 2022

Hello,

I used NSwagStudio to generate models from the openAPI.json and got the same ambiguity:

Events inherit from a base Event class (public partial class AggregationEvent : Event)

Event base class has the correct base properties: EventTime, RecordTime, LDContext, ...

But EpcisDocumentBody has a reference to EventList which derives from ... nothing!

public partial class EventList : System.Collections.ObjectModel.Collection, which is even missing as a type ...

So it seems NSwagStudio is missing a beat here ...

I manually adjusted this to be a collection of 'Event'.
After that there are still some issues with GS1EPCISVersionand similar classes deriving from string (which is not possible), but that's not a biggy => solved by using statements.
I seem to be generating proper hierarchies now. I will test them and get back to you ...

@yvdh
Copy link
Author

yvdh commented May 3, 2022

Nswag generated models from openAPI.json or openAPI.yaml, after manually tweaking the inheritance still has problems in that the ObjectEvent is missing. I have no idea why this class in not created ...

When I use the json schema with NSwag to generate only the classes the ObjectEvent is included. Tweaking to get proper inheritance is quite easy but so far deserialization is not working (empty properties). I'll keep working on that

The swagger generated models (using the swagger website provided in this repository) has fundamentally incorrect inheritance (see first post) and keeps failing in deserialization, with most properties not filled in.

I have not tried starting from the xsd schema's, I will give that a go too.

Whatever the outcome, I think that having a clear manner in which to generate a set of classes for deserialization (and possible the API boilerplate code) in standard languages would constitute a major plus for implementers, and the current tooling does not work well enough ...

Cheers
Yves

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