Open
Description
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()