ardielle / ardielle-go Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
i.e. 3 files, the first includes the 2nd and 3rd, the 3rd includes the 2nd, and the 3rd also defines a type that extends a type in the 2nd file. The parser fails with a nil pointer panic
This works:
type MyBase Struct { String message; }
type MySubtype1 MyBase;
But if the subtype has extended annotations added to it:
type MySubtype2 MyBase (x_y);
Then the result of parsing is:
{
"type": "forward_reference",
"name": "MySubtype2"
}
which is a state that should never leak out.
I'm attempting to 'use' the types from one RDL file in another one. An example of what I'm doing follows:
File: .../example/used/used.rdl
name used
type AStruct struct {
int64 AValue
}
File: .../example/user/user.rdl
name user
use "../used/used.rdl"
resource used.AStruct GET "/example" {
expected OK;
exceptions {
ResourceError NOT_FOUND; // No entry found
}
}
When I attempt to generate any Go code for the user.rdl file I receive a warning and the Go code generated does not build. When I attempt to generate Markdown I get an error from the rdl tool. Issuing an rdl parse command on the user.rdl file returns no errors. Am I doing something wrong or is this a bug? If I replace the use keyword in the user.rdl file with the include keyword and remove the used. prefix from AStruct, generation succeeds in all cases. However a completely new type is then generated in the user package that is no longer the same as used.AStruct.
hi ,
question on https://github.com/ardielle/ardielle-go/blob/master/rdl/parser.go#L2053
the parser doesn't allow empty body with POST. however sometimes it is required.
for example:
Do you think this restriction on RDL parser can be revised ?
thx,
Baiyi
Not being a go expert, can you add a few lines on the steps to build the rdl command and the plug-ins on different platforms (e.g. macos and linux).
Defined a test in this branch https://github.com/xythian/ardielle-go/tree/maptype_breaking_test
$ go test ./... -run TestMapDefinition -v
=== RUN TestMapDefinition
--- FAIL: TestMapDefinition (0.00s)
panic: assignment to entry in nil map [recovered]
panic: assignment to entry in nil map
goroutine 5 [running]:
testing.tRunner.func1(0xc420074d00)
/usr/local/go/src/testing/testing.go:622 +0x29d
panic(0x139a760, 0xc420107090)
/usr/local/go/src/runtime/panic.go:489 +0x2cf
github.com/ardielle/ardielle-go/rdl.(*parser).addTypeAnnotation(0xc42008ee00, 0xc4201149c0, 0x13fe452, 0xf, 0xc4200f1761, 0x11)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:486 +0xd7
github.com/ardielle/ardielle-go/rdl.(*parser).parseInclude(0xc42008ee00)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:389 +0x2be
github.com/ardielle/ardielle-go/rdl.(*parser).parseSchema(0xc42008ee00)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:207 +0x743
github.com/ardielle/ardielle-go/rdl.parseRDL(0x0, 0xc4200f16e0, 0x17, 0x158e940, 0xc420073c80, 0x10000, 0xc4200f16ec, 0x13fcaf5, 0xb)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:85 +0x39d
github.com/ardielle/ardielle-go/rdl.parseRDLFile(0xc4200f16e0, 0x17, 0x0, 0x10000, 0x0, 0x0, 0x0)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:55 +0x156
github.com/ardielle/ardielle-go/rdl.ParseRDLFile(0xc4200f16e0, 0x17, 0x10000, 0x13fcaf5, 0xb, 0xc4200f16e0)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser.go:45 +0x59
github.com/ardielle/ardielle-go/rdl.loadTestSchema(0xc420074d00, 0x13fcaf5, 0xb, 0xc4070f6672)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser_test.go:15 +0x8f
github.com/ardielle/ardielle-go/rdl.TestMapDefinition(0xc420074d00)
/Users/kenf/src/troy/src/github.com/ardielle/ardielle-go/rdl/parser_test.go:50 +0x40
testing.tRunner(0xc420074d00, 0x14128c8)
/usr/local/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:697 +0x2ca
FAIL github.com/ardielle/ardielle-go/rdl 0.027s
The current go implementation of rdl.Validate
calls NewTypeRegistry(schema)
on every invocation. For a complex schema, this is a costly operation.
Line 46 in 0e40fcc
This becomes apparent in go when unmarshalling large objects with nested structs containing a lot of "derived-from-String" types.
In tests, I've found that code which would just cache the TypeRegistry per schema when calling schema.Build()
and then use that in a rdl.Validate2()
style call which can accept a preconstructed TypeRegistry gives a close to 10x improvement on JSON unmarshalling speed.
$ cat bad.rdl
type Foo String (pattern="[a-z]*")
type Bar Foo (maxSize=32);
$ rdl generate json bad.rdl
*** Error(bad.rdl:2): unexpected token
I expected Bar
to be a string that matches the pattern and has a length limitation.
This change af82e72#diff-c47cfc4879d59b2c3268af73178decfb added a number of string comparisons for base types that rely on the base type having a specific capitalization.
However, RDL types are defined to be case-insensitive see Note: all type names in RDL are case-insensitive. Capitalized types are used in this document. from https://ardielle.github.io/
The net result is that some of our older RDL generated schema.go code now panics when trying to build the schema, e.g.
sb := rdl.NewSchemaBuilder("model")
tEvent := rdl.NewStructTypeBuilder("struct", "Event")
tEvent.Field("type", "EventType", false, nil, "")
tEvent.Field("level", "Int32", false, nil, "")
sb.AddType(tEvent.Build())
Hi, the newest rdl cannot generate json correctly when adding annotation after alias type definition.
example rdl:
namespace com.yahoo.apex.parsec;
name apex;
version 1;type DateTime string (x_date_time)
type Response struct {
DateTime dateTime;
}
If we generate json with the newest rdl, we will get:
*** Error(error.rdl:8): Recursively typed fields must be optional: field 'dateTime' in struct Response
Furthermore, if we put (optional)
after field dateTime
, the generated json seems not correct, either.
example:
"AliasTypeDef": { "type": "___forward_reference___", "name": "DateTime" }
Is an annotation on alias type still a legal format?
Thank you.
For expressing non-standard information at a schema level. Right now it's only possible to do this for types and resources.
$ cat bad.rdl
type Foo Struct {
String bar (maxSize=512);
}
$ rdl generate json bad.rdl
*** Error(bad.rdl:2): unsupported Struct field option: maxSize
This means for modeling a single-use struct on which I want to place size limits on every field, I have to create types for every string variation.
https://ardielle.github.io/syntax.xhtml#Identifier
Now Identifier of Enum in RDL is defined as Name.
Is it possible to support ExtendedOption in Identifier?
We want to construct alias for each Enum element.
It seems ExtendedOption can solve our problem.
example:
type Enum Animal {
CAT (x_intValue="0"),
DOG (x_intValue="1"),
BIRD (x_intValue="2")
}
Thank you.
Take for example this RDL fragment:
type SimpleName String (pattern="[a-zA-Z_][a-zA-Z_0-9]*");
type StringTest Struct {
SimpleName name;
SimpleName opt (optional);
}
Running rdl generate go-model
for this RDL produces the validation func as:
func (self *StringTest) Validate() error {
if self.Name == "" {
return fmt.Errorf("StringTest.name is missing but is a required field")
} else {
val := rdl.Validate(TestSchema(), "SimpleName", self.Name)
if !val.Valid {
return fmt.Errorf("StringTest.name does not contain a valid SimpleName (%v)", val.Error)
}
}
return nil
}
Although opt
is an optional field, it is contrained by a regex pattern that should be validated inside Validate()
. I'd expect the validation func to instead be:
func (self *StringTest) Validate() error {
if self.Name == "" {
return fmt.Errorf("StringTest.name is missing but is a required field")
} else {
val := rdl.Validate(TestSchema(), "SimpleName", self.Name)
if !val.Valid {
return fmt.Errorf("StringTest.name does not contain a valid SimpleName (%v)", val.Error)
}
}
// --- additional expected code ---
if self.Opt != "" {
val := rdl.Validate(TestSchema(), "SimpleName", self.Opt)
if !val.Valid {
return fmt.Errorf("StringTest.opt does not contain a valid SimpleName (%v)", val.Error)
}
}
// ---------------------
return nil
}
Hi,
I am trying to generate schema using rdl generate
with the following structure
type RuleData Struct {
String v;
Bytes byt;
}
I am getting error saying expected 'field name', found ';'
Is this expected or am I doing something wrong?
And...that leads to code generator panic.
rdl.rdl doesn't define "annotations" for resources or resource input/outputs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.