johnstonskj / rust-atelier

Rust native core model for the AWS Smithy IDL
MIT License
76 stars 10 forks source link

[BUG] JSON parser does not accept absolute shape IDs for members (as required by AST spec) #28

Closed stevelr closed 3 years ago

stevelr commented 3 years ago

Describe the bug A model converted from smithy to json fails validation and can't be converted back to smity

To Reproduce Create a simple model and save as model.smithy

namespace org.example.foo

structure Baz {
  method: String,
}

Then convert to json with `cargo-atelier convert -r smithy -w json -i model.smithy > /tmp/model.json

Validation fails: cargo-atelier validate -r json -i /tmp/model.json

Error: Error(InvalidShapeID("org.example.foo#Baz$method"), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })

Converting back to smithy fails: cargo-atelier convert -r json -w smithy -i /tmp/model.json

Error: Error(InvalidShapeID("org.example.foo#Baz$method"), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })

stevelr commented 3 years ago

For reference, here's the json file generated from cargo-atelier convert

{
  "shapes": {
    "org.example.foo#Baz": {
      "members": {
        "org.example.foo#Baz$method": {
          "target": "smithy.api#String"
        }
      },
      "type": "structure"
    }
  },
  "smithy": "1.0"
}
stevelr commented 3 years ago

For clarification, the bug is that the json parser does not accept absolute paths (with namespace) for members. The JSON AST spec says

All shape IDs in the JSON AST MUST be absolute shape IDs that contain a namespace

There were a handful of json models in the test suites that needed to be corrected as well: atelier-json/tests/good/aws*.json These json files, and this bug, are fixed in PR #30

johnstonskj commented 3 years ago

Actually the referenced line in the specification refers to shape identifiers, not members. Members are always referred to using the identifier production:

Structure and union member names MUST be case-insensitively unique across the entire set of members. Each member name MUST adhere to the identifier ABNF grammar.

The error is that the JSON writer should never have produced the example you included.