feature: refactor api parse to g4 (#365)

* feature: refactor api parse to g4

* new g4 parser

* add CHANGE_LOG.MD

* refactor

* fix byte bug

* refactor

* optimized

* optimized

* revert

* update readme.md

* update readme.md

* update readme.md

* update readme.md

* remove no need

* fix java gen

* add upgrade

* resolve confilits

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
kingxt
2021-01-11 15:10:51 +08:00
committed by GitHub
parent b0ccfb8eb4
commit ee19fb736b
88 changed files with 13641 additions and 2458 deletions

View File

@@ -0,0 +1,72 @@
// syntax: specify the api syntax version,
// through this version can be a good control
// api syntax upgrade incompatibility issues
syntax = "v1"
// Info block is a key-value pair description body,
// you can add some descriptions of the current api
// file through this description body, you can add
// any key-value pair, which does not participate in the api generation
info(
title: sample of api
desc: "you can add a newline
description by quotes"
author: songmeizi
anyAnotherKey: anyTnotherValue
)
// The structure in the api evolved from the structure of golang,
// and it is also reserved to support the structure of golang.
// a golang structure
type Foo struct{
Foo int
}
// api structure
type Bar {
Bar int
}
// structure group
type (
FooBar {
Foo int
Bar bool
}
)
// Like the info block, @server can define any key-value pair.
// The difference is that @server is a description of the service
// block or route, which will participate in the api file generation.
// There are several important keys that need to be understood,
// which have special meanings. The jwt key is to declare that code
// generation needs to include jwt authentication logic. The group key
// is to declare that the files generated by the code need to be grouped
// according to the value corresponding to the group. The handler key
// determines the handler in golang. Layer file logic generation
@server(
jwt: Auth
group: foo
anyAnotherKey: anyTnotherValue
)
// service block is the description of the api service,
// including @doc block, @handler and api routing information
service foo-api {
// shortening doc declaration
@doc("foo")
// shortening handler declaration
@handler foo
// route
get /foo (Foo) returns (Bar)
@doc(
summary: foo
)
@server(
handler: bar
)
post /bar (Foo)
}

View File

@@ -0,0 +1,6 @@
info(
author: songmeizi
desc: "the sample of
info"
date: "2020-01-06"
)

View File

@@ -0,0 +1,29 @@
type Foo {}
@server(
foo: foo
bar: "bar"
fooBar: "foo
bar"
)
service foo-api {
@doc("foo")
@handler foo
get /foo (Foo) returns (Foo)
@handler bar
post /foo (Foo)
@handler fooBar
post /foo/bar
@server(
handler: getFoo
)
post /foo/:id returns(Foo)
}
service foo-api {
@doc(
summary:"post foo"
)
@handler postFoo
post /foo/bar/post (Foo)
}

View File

@@ -0,0 +1 @@
syntax = "v1"

View File

@@ -0,0 +1,111 @@
// syntax doc
syntax = "v1" // syntax comment
// import doc
import "foo.api" // import comment
import(
// import group doc
"bar.api" // import group comment
)
// info doc
info(// info comment
// author doc
author: "songmeizi" // author comment
// date doc
date: 2020-01-04 // date comment
// desc doc
desc: "break line
desc" // desc comment
)
type (
FooBar struct{
Foo int
}
// remove struct
Bar {
// vString
VString string `json:"vString"`
// vBool
VBool bool `json:"vBool"`
// vInt8
VInt8 int8 `json:"vInt8"`
// vInt16
VInt16 int16 `json:"vInt16"`
// vInt32
VInt32 int32 `json:"vInt32"`
// vInt64
VInt64 int64 `json:"vInt64"`
// vInt
VInt int `json:"vInt"`
// vUInt8
VUInt8 uint8 `json:"vUInt8"`
// vUInt16
VUInt16 uint16 `json:"vUInt16"`
// vUInt32
VUInt32 uint32 `json:"vUInt32"`
// vUInt64
VUInt64 uint64 `json:"vUInt64"`
// vFloat32
VFloat32 float32 `json:"vFloat32"`
// vFloat64
VFloat64 float64 `json:"vFloat64"`
// vByte
VByte byte `json:"vByte"`
// vRune
VRune rune `json:"vRune"`
// vMap
VMap map[string]int `json:"vMap"`
// vArray
VArray []int `json:"vArray"`
// vStruct
VStruct FooBar `json:"vStruct"`
// vStructPointer
VStructPointer *FooBar `json:"vStructPointer"`
// vInterface
VInterface interface{} `json:"vInterface"`
// inline
FooBar
}
)
@server(
host: 0.0.0.0
port: 8080
annotation: "break line
desc"
)
service foo-api{
@doc("foo")
@handler postFoo
// foo
post /foo (FooBar) returns (FooBar)
@doc(
summary: bar
)
@server(
handler: postBar
)
post /bar (FooBar)
@doc("foobar")
@handler postFooBar
/**
* httpmethod: post
* path: /foo/bar
* reply: FooBar
*/
post /foo/bar returns (FooBar)
@doc("barfoo")
@handler postBarFoo
post /bar/foo // post:/bar/foo
@doc("barfoo")
@handler getBarFoo
get /bar/foo returns (FooBar)
}

View File

@@ -0,0 +1,23 @@
type Foo{
}
type Bar struct{
}
type FooBar {
Foo int
Bar bool
Map map[string]int
Map1 map[string]Bar
Map2 map[string]*Bar
Map3 map[string][]int
Map4 map[string][]Bar
Map5 map[string][]*Bar
Map6 map[string]map[string]int
Array []int
Array1 []*Bar
Array2 []Bar
Pointer *Bar
Bar
}