microsoft / dtdl-model-generator

A library used for generating C# classes from DTDL interfaces.
MIT License
13 stars 16 forks source link

[Bug]: Should generated models be usable with ADT Client? #36

Closed Sefriol closed 10 months ago

Sefriol commented 11 months ago

Describe the bug

It seems that model validation will fail with JsonIgnore-fields.

Which version of the tool was used?

Latest ADT client and Model Generator

Options

No response

Steps To Reproduce

  1. Generate a model with JsonIgnore fields that are not part of the ADT model schema or are different type (relationship instead of property)
  2. Use the C# class to create a new twin with ADT client

ADT will report back with Model Valition Error which complains that specific field inside the class is either wrong type or not part of the model.

For Relationships, this can be circumvented by making Relationships into functions:

[JsonIgnore]
RelationshipCollection Rel_contains {get; set;} = new RelationshipCollection();

//Into

RelationshipCollection Rel_contains() {
  return new RelationshipCollection();
}

This requires a small change in the querybuilder where you need to call for the function, which isn't a big deal, but it kinda ins't the same thing. I am wondering if I am just doing something wrong.

jarz commented 10 months ago

Hi @Sefriol, could you provide example code? The first step isn't clear to me, a gist or small repo to look at would be helpful.

Sefriol commented 10 months ago

I'll check tomorrow when I get back to work ;)

Sefriol commented 10 months ago

This might be an issue on our end. I tried Generator.V2.City and it seemed to work properly.

It seems that ADT client does not respect [JsonIgnore] attribute in our case. Need to investigate why that is.

Sefriol commented 10 months ago

Found the issue in our Json Serializer which happened to discard [JsonIgnore]-attributes.