Skip to content

Commit

Permalink
Added annotations to the schema object itself, and parse them. (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
boynton authored Jul 8, 2017
1 parent b4f5d0c commit 83c5c40
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rdl/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ func (p *parser) parseSchema() {
p.registerResource(r)
}
default:
p.error("Unrecognized keyword in schema: '" + txt + "'")
if strings.HasPrefix(txt, "x_") {
p.schema.Annotations = p.parseExtendedOption(p.schema.Annotations, ExtendedAnnotation(txt))
} else {
p.error("Unrecognized keyword in schema: '" + txt + "'")
}
}
case ';':
p.warning("stray ';' character")
Expand Down
20 changes: 20 additions & 0 deletions rdl/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,23 @@ type TestEnum Enum {
test.Errorf("Enum type parsed incorrectly: %v", s1)
}
}

func TestSchemaAnnotations(test *testing.T) {
var err error
s1, err := parseRDLString(`
//this is a schema annotation test
name foo;
version 1
x_something="23"
x_blah = "blah"
type Foo Struct {
String text
}
`)
if err != nil {
test.Errorf("cannot parse valid RDL: %v", err)
return
}
fmt.Println("schema:", s1)
}
1 change: 1 addition & 0 deletions rdl/rdl_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func init() {
tSchema.ArrayField("types", "Type", true, "The types this schema defines.")
tSchema.ArrayField("resources", "Resource", true, "The resources for a service this schema defines")
tSchema.Field("base", "String", true, nil, "the base path for resources in the schema.")
tSchema.MapField("annotations", "ExtendedAnnotation", "String", true, "additional annotations starting with \"x_\"")
sb.AddType(tSchema.Build())

schema = sb.Build()
Expand Down
5 changes: 5 additions & 0 deletions rdl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,11 @@ type Schema struct {
// the base path for resources in the schema.
//
Base string `json:"base,omitempty" rdl:"optional"`

//
// additional annotations starting with "x_"
//
Annotations map[ExtendedAnnotation]string `json:"annotations,omitempty" rdl:"optional"`
}

//
Expand Down
1 change: 1 addition & 0 deletions testdata/rdl.rdl
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,5 @@ type Schema Struct {
Array<Type> types (optional); // The types this schema defines.
Array<Resource> resources (optional); // The resources for a service this schema defines
String base (optional); //the base path for resources in the schema.
Map<ExtendedAnnotation,String> annotations (optional); //additional annotations starting with "x_"
}

0 comments on commit 83c5c40

Please sign in to comment.