Altinn / altinn-cdn

Static assets used by Altinn solutions and apps.
https://altinncdn.no
1 stars 30 forks source link

Syncing json schema with definitions in app-frontend #106

Closed olemartinorg closed 2 years ago

olemartinorg commented 2 years ago

Description

In the linked pull request I combed through the layout component type definitions in the frontend app, and in the process I noticed a few inconsistencies with the json schema. This PR aims to clean those up.

Related Issue(s)

Verification

Documentation

ivarne commented 2 years ago

Have you looked into syncing these automatically? (Designate one as master, and generate the other).

I'm currently hoping to make it possible to dynamically modify the layout files in C#, and for that to work, we would need to have similar typings as C# classes as well (but obviously I got pushback because they would need to be maintained).

I have spent some time looking into this, but have not yet found a perfect solution.

olemartinorg commented 2 years ago

I've generated TypeScript types from JsonSchema before, and it can work sometimes, but I didn't look into doing that this time (one step at a time, I guess). Having separate repositories makes these things a bit worse, I guess.

I remember that part from your presentation, but it just occurred to me now; don't we already generate some data model classes from JsonSchema? Maybe that code can be adapted to generate C# classes from this schema layout? It's been a while since I looked at that code (and I never dove deep into it), but the use-cases might not overlap much.

ivarne commented 2 years ago

I do generate C# classes from json-schema in altinn2-convert see GenerateAltinn3ClassesFromJsonSchema, but I wasn’t very impressed with the results in translating a tagged union to a class hierarchy. I had to use partial classes to make it possible to fix the missing parts manually in separate files.

Maybe better tools exist than what I found. I also use the classes for building and serializing the layouts.

olemartinorg commented 2 years ago

Right, my experience is that as soon as the tool doesn't perform the way you want it to, cleaning up after the tool quickly becomes harder than just writing a highly tailored solution yourself (and/or adjusting the JsonSchema to fit)... The code I was thinking about is in Studio: JsonSchemaToInstanceModelGenerator.cs

ivarne commented 2 years ago

Yea, it’s a tough call. Generating is hard, but when you have many people in the loop with tight deadlines, it’s very likely that we will fail to sync changes manually too.