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

SmithyIdlSerializer always renders idRefs unquoted #2494

Open
kubukoz opened this issue Dec 27, 2024 · 0 comments
Open

SmithyIdlSerializer always renders idRefs unquoted #2494

kubukoz opened this issue Dec 27, 2024 · 0 comments

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Dec 27, 2024

When serializing a model with an @idRef String shape, the SmithyIdlSerializer will always render the ShapeId unquoted.

This causes problems when loading the serialized model, because the shape may or may not exist (if failWhenMissing isn't used, this isn't a problem beforehand).

For example:

$version: "2"

namespace test

@trait structure myTrait { @idRef @required s: String }

@myTrait(s: "foo.bar#Baz") string Demo

Becomes:

namespace test

use foo.bar#Baz

@trait
structure myTrait {
    @idRef
    @required
    s: String
}

@myTrait(
    s: Baz
)
string Demo

which gets rejected when loading:

software.amazon.smithy.model.validation.ValidatedResultException: Result contained ERROR severity validation events: 
[DANGER] -: Syntactic shape ID `Baz` does not resolve to a valid shape ID: `foo.bar#Baz`. Did you mean to quote this string? Are you missing a model file? | SyntacticShapeIdTarget test.smithy:15:8

Full reproduction in scala-cli:

//> using scala 3.5.2
//> using dep software.amazon.smithy:smithy-model:1.53.0
//> using option -Wunused:all
import software.amazon.smithy.model.Model
import scala.jdk.CollectionConverters._
import software.amazon.smithy.model.shapes.SmithyIdlModelSerializer

val r = Model
  .assembler()
  .addUnparsedModel(
    "test.smithy",
    """$version: "2"
      |namespace test
      |
      |@trait structure myTrait { @idRef @required s: String }
      |
      |@myTrait(s: "foo.bar#Baz") string Demo
      |""".stripMargin,
  )
  .assemble()

r.getValidationEvents().asScala.toList

val m = r.unwrap()

val srcAgain = SmithyIdlModelSerializer.builder().build().serialize(m).asScala.toList.head._2

Model
  .assembler()
  .addUnparsedModel(
    "test.smithy",
    srcAgain,
  )
  .assemble()
  .unwrap()
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

1 participant