smithy4s icon indicating copy to clipboard operation
smithy4s copied to clipboard

Dynamic: unknown discriminator apply

Open kubukoz opened this issue 3 years ago • 6 comments

$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.

kubukoz avatar Aug 31 '22 15:08 kubukoz

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 ?

Baccata avatar Aug 31 '22 16:08 Baccata

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

kubukoz avatar Sep 01 '22 08:09 kubukoz

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.

kubukoz avatar Oct 06 '22 19:10 kubukoz

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.

Baccata avatar Oct 07 '22 07:10 Baccata

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?

kubukoz avatar Oct 09 '22 02:10 kubukoz

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

Baccata avatar Oct 09 '22 08:10 Baccata