Goa v1 と v3 の DSL の比較
前回の記事ではプリミティブ型の比較を行いましたが、今回は DSL の比較を行っていきます。各 DSL の詳細については随時追記していきます。
| v1 | v3 |
|---|---|
API |
API |
APIKeySecurity |
APIKeySecurity( APIKey)( APIKeyField) |
AccessCodeFlow |
- |
Action |
Method |
ApplicationFlow |
- |
ArrayOf |
ArrayOf |
Attribute |
Attribute |
Attributes |
Attributes |
BasePath |
Path |
BasicAuthSecurity |
BasicAuthSecurity( Password)( PasswordField)( Username)( UsernameField) |
CONNECT |
CONNECT |
CanonicalActionName |
CanonicalMethod |
CollectionOf |
CollectionOf |
Consumes |
Consumes |
Contact |
Contact |
ContentType |
ContentType |
Credentials |
- |
DELETE |
DELETE |
Default |
Default |
DefaultMedia |
- |
Description |
Description |
Docs |
Docs |
Email |
Email |
Enum |
Enum |
Example |
Example( Value) |
Expose |
- |
Files |
Files |
Format |
Format |
Function |
- |
GET |
GET |
HEAD |
HEAD |
HashOf |
MapOf |
Header |
Header |
Headers |
Headers |
Host |
HostServerURIVariable |
ImplicitFlow |
ImplicitFlow |
JWTSecurity |
JWTSecurity( Token)( TokenField) |
License |
License |
Link |
- |
Links |
- |
MaxAge |
- |
MaxLength |
MaxLength |
Maximum |
Maximum |
Media |
Result |
MediaType |
ResultType |
Member |
- |
Metadata |
Meta |
Methods |
- |
MinLength |
MinLength |
Minimum |
Minimum |
MultipartForm |
MultipartRequest |
Name |
Name |
NoExample |
- |
NoSecurity |
NoSecurity |
OAuth2Security |
OAuth2Security( AccessToken)( AccessTokenField) |
OPTIONS |
OPTIONS |
OptionalPayload |
- |
Origin |
- |
PATCH |
PATCH |
POST |
POST |
PUT |
PUT |
Package |
- |
Param |
Param |
Params |
Params |
Parent |
Parent |
PasswordFlow |
PasswordFlow |
Pattern |
Pattern |
Payload |
Payload |
Produces |
Produces |
Query |
- |
ReadOnly |
- |
Reference |
Reference |
Required |
Required |
Resource |
Service |
Response |
Response |
ResponseTemplate |
- |
Routing |
- |
Scheme |
- |
Scope |
Scope |
Security |
Security |
Status |
Code |
TRACE |
TRACE |
TermsOfService |
TermsOfService |
Title |
Title |
TokenURL |
- |
Trait |
- |
Type |
Type |
TypeName |
TypeName |
URL |
URL |
UseTrait |
- |
Version |
Version |
View |
View |
| - | AuthorizationCodeFlow |
| - | Body |
| - | ClientCredentialsFlow |
| - | ConvertTo |
| - | CreateFrom |
| - | Elem |
| - | Error |
| - | Extend |
| - | Fault |
| - | Field |
| - | GRPC |
| - | HTTP |
| - | Key |
| - | MapParams |
| - | Message |
| - | Metadata |
| - | Services |
| - | StreamingPayload |
| - | StreamingResult |
| - | Tag |
| - | Temporary |
| - | Timeout |
| - | Trailers |
BasePath
Pathに変更されました。HTTP内に記述します。
// v1 BasePath("/users")
// v3 HTTP(func() { Path("/users") })
Consumes, Produces
HTTP内に記述します。- これらの DSL 内で使用できた
FunctionとPackageは廃止されました。
// v1 Consumes("application/xml") Consumes("application/json") Produces("application/xml") Produces("application/json")
// v3 HTTP(func() { Consumes("application/xml") Consumes("application/json") Produces("application/xml") Produces("application/json") })
Format
- v1 では引数の型が
stringでしたが、 v3 ではexpr.ValidationFormatになりました。 - 使用可能な
expr.ValidationFormatはgoa.design/goa/exprにconstとして定義されています。
GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH
- v1 ではパスパラメータをコロン (
:) で記述しましたが、 v3 では中括弧 ({,}) を使います。
// v1 GET("/users/:id")
// v3 GET("/users/{id}")
HashOf
// v1 HashOf(String, Integer, func() { MinLength(1) MaxLength(16) }, func() { Minimum(1) Maximum(5) }, ) // v3 MapOf(String, Int, func() { Key(func() { MinLength(1) MaxLength(16) }) Elem(func () { Minimum(1) Maximum(5) }) })
Headers
リクエストヘッダ
Payload内にAttributeを、HTTP内にHeadersを記述します。
// v1 Action("show", func() { Headers(func() { Header("Authorization", String) }) })
// v3 Method("show", func() { Payload(func() { Attribute("Authorization", String) }) HTTP(func() { Headers(func() { Header("Authorization", String) }) }) })
Host, Scheme
- v1 では
HostとScheme(とBasePath) で記述しましたが、 v3 ではServerとHostとURIを使います。
// v1 Host("localhost:8080") Scheme("http") BasePath("/cellar")
// v3 Server("app", func() { Host("development", func() { URI("http://localhost:8080/cellar") }) })
NoExample
- 廃止されました。
Metaで同等の定義ができます。
Meta("swagger:example", "false")
Params
パスパラメータ
Payload内にAttributeを、HTTP内にParamsを記述します。Paramsは省略できます。省略した場合は暗黙的に定義されます。
// v1 Action("show", func() { Params(func() { Param("id", Integer) }) })
// v3 Method("show", func() { Payload(func() { Attribute("id", Int) }) HTTP(func() { Params(func() { // 省略可 Param("id", Int) // }) // }) })
クエリパラメータ
Payload内にAttributeを、HTTP内にParamsを記述します。Paramsは省略できません。
//v1 Action("list", func() { Params(func() { Param("name", String) }) })
// v3 Method("list", func() { Payload(func() { Attribute("name", String) }) HTTP(func() { Params(func() { // 省略不可 Param("name", String) // }) // }) })
Routing
// v1 Action("show", func() { Routing( GET("/:id"), ) })
// v3 Method("show", func() { HTTP(func() { GET("/{id}") }) })