Skip to content

Commit

Permalink
fix: JSON aliases can be any string, not just identifiers (#952)
Browse files Browse the repository at this point in the history
eg. "foo:bar:waz"
  • Loading branch information
alecthomas authored Feb 17, 2024
1 parent 7039d99 commit 2b54d58
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions backend/controller/ingress/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func TestTransformFromAliasedFields(t *testing.T) {
schemaText := `
module test {
data Inner {
waz String alias json foo
waz String alias json "foo"
}
data Test {
scalar String alias json bar
scalar String alias json "bar"
inner Inner
array [Inner]
map {String: Inner}
Expand Down Expand Up @@ -72,11 +72,11 @@ func TestTransformToAliasedFields(t *testing.T) {
schemaText := `
module test {
data Inner {
waz String alias json foo
waz String alias json "foo"
}
data Test {
scalar String alias json bar
scalar String alias json "bar"
inner Inner
array [Inner]
map {String: Inner}
Expand Down
4 changes: 2 additions & 2 deletions backend/schema/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Field struct {
Comments []string `parser:"@Comment*" protobuf:"3"`
Name string `parser:"@Ident" protobuf:"2"`
Type Type `parser:"@@" protobuf:"4"`
JSONAlias string `parser:"('alias' 'json' @Ident)?" protobuf:"5"`
JSONAlias string `parser:"('alias' 'json' @String)?" protobuf:"5"`
}

var _ Node = (*Field)(nil)
Expand All @@ -25,7 +25,7 @@ func (f *Field) schemaChildren() []Node { return []Node{f.Type} }
func (f *Field) String() string {
jsonAlias := ""
if f.JSONAlias != "" {
jsonAlias = fmt.Sprintf(" alias json %s", f.JSONAlias)
jsonAlias = fmt.Sprintf(" alias json %q", f.JSONAlias)
}
w := &strings.Builder{}
fmt.Fprint(w, encodeComments(f.Comments))
Expand Down
8 changes: 4 additions & 4 deletions backend/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func TestSchemaString(t *testing.T) {
// A comment
module todo {
data CreateRequest {
name {String: String}? alias json rqn
name {String: String}? alias json "rqn"
}
data CreateResponse {
name [String] alias json rsn
name [String] alias json "rsn"
}
data DestroyRequest {
Expand Down Expand Up @@ -340,10 +340,10 @@ func TestParseModule(t *testing.T) {
// A comment
module todo {
data CreateRequest {
name {String: String}? alias json rqn
name {String: String}? alias json "rqn"
}
data CreateResponse {
name [String] alias json rsn
name [String] alias json "rsn"
}
data DestroyRequest {
// A comment
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/compile/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestExtractModuleSchema(t *testing.T) {
nested one.Nested
optional one.Nested?
time Time
user two.User alias json u
user two.User alias json "u"
bytes Bytes
}
Expand Down

0 comments on commit 2b54d58

Please sign in to comment.