Git Product home page Git Product logo

ardielle-go's People

Contributors

ben-tsai avatar boynton avatar dmitris avatar evantorrie avatar gotwarlost avatar joejoe321321 avatar jpeirson avatar sciolizer avatar xythian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ardielle-go's Issues

extending types across files panics

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

Annotating an alias type breaks it

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.

Is "use" statement functional?

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.

why POST with no payload is not allowed?

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:

  1. I want the resource to sync with some external source: POST /v1/projects/:projId/sync
  2. Or I want to kick off some lengthy action and the resource already have enough information to operation it, I could do POST /v1/projects/:projId/someAction

reference : http://stackoverflow.com/questions/4191593/is-it-considered-bad-practice-to-perform-http-post-without-entity-body

Do you think this restriction on RDL parser can be revised ?

thx,
Baiyi

Building the RDL command

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).

Unexpected error for valid-looking RDL (nil pointer panic)

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

Performance/Memory issues with rdl.Validate when FullValidation enabled

The current go implementation of rdl.Validate calls NewTypeRegistry(schema) on every invocation. For a complex schema, this is a costly operation.

checker.registry = NewTypeRegistry(schema)

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.

Cannot add constraints when subtyping a string

$ 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.

Code panic when using RDL files with case-sensitive base types

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())

Cannot add annotation on AliasTypeDef

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.

Cannot express constraints for struct attributes

$ 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.

Doesn't emit validation code for optional fields

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
}

RDL Generation step gives error when Bytes type is included

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.