diff --git a/rdl/parser.go b/rdl/parser.go index 380bc2e..7214afe 100644 --- a/rdl/parser.go +++ b/rdl/parser.go @@ -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") diff --git a/rdl/parser_test.go b/rdl/parser_test.go index 83e8458..696558a 100644 --- a/rdl/parser_test.go +++ b/rdl/parser_test.go @@ -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) +} diff --git a/rdl/rdl_schema.go b/rdl/rdl_schema.go index 06874ce..20b8c58 100644 --- a/rdl/rdl_schema.go +++ b/rdl/rdl_schema.go @@ -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() diff --git a/rdl/schema.go b/rdl/schema.go index 7111c8a..94114dc 100644 --- a/rdl/schema.go +++ b/rdl/schema.go @@ -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"` } // diff --git a/testdata/rdl.rdl b/testdata/rdl.rdl index 1a62e15..ba172e3 100644 --- a/testdata/rdl.rdl +++ b/testdata/rdl.rdl @@ -257,4 +257,5 @@ type Schema Struct { Array types (optional); // The types this schema defines. Array resources (optional); // The resources for a service this schema defines String base (optional); //the base path for resources in the schema. + Map annotations (optional); //additional annotations starting with "x_" }