disneystreaming / smithy4s

https://disneystreaming.github.io/smithy4s/
Other
348 stars 70 forks source link

Dynamic: unknown discriminator apply #421

Open kubukoz opened 2 years ago

kubukoz commented 2 years ago
$version: "2"

namespace demo

@mixin
structure B {
  id: String
}

structure A with [B] {}

apply A$id @documentation("foo")

Running dump-model on this results in the following shape being generated (among others):

{
  "type": "apply",
  "traits": {
    "smithy.api#documentation": "foo"
  }
}

Decoding it fails with:

Unknown discriminator: apply (path: .shapes.demo#A$id)

I think that shape should not be generated, but instead the target field should have a trait added to it. Currently it's impossible to load a dynamic model that was dumped from anything with an apply in it.

Baccata commented 2 years ago

wut, I wasn't aware apply was a possibility in the json syntax. You are correct in what needs to happen though. Mind PR-ing it in ?

kubukoz commented 2 years ago

If nobody beats me to it :) I'll assign myself here if I pick it up

kubukoz commented 2 years ago

Looks like #463 resolves this for my purpose (apply simply doesn't get generated, it seems), but since it's an actual decoding failure (and not simply an ignored field) I'd say we should still do something about this, so that Dynamic can read models serialized by plain Smithy tooling without flattening.

Baccata commented 2 years ago

We need a pre-processing step, that would inline the apply. We also need a pre-processing step that would inline the mixins. It's really doable, just a bit tedious.

kubukoz commented 2 years ago

Just to be clear, this would be part of the dynamic model compiler? Essentially replicating what we're now doing in the part that serializes the jvm smithy model?

Baccata commented 2 years ago

Yes. But as isolated function Model => Model function that could be run in isolation.