Skip to content

Commit

Permalink
Merge branch 'v3' into dependabot/go_modules/google.golang.org/grpc-1…
Browse files Browse the repository at this point in the history
….59.0
  • Loading branch information
raphael authored Nov 3, 2023
2 parents 4902f9f + 86ae5d5 commit dc0eb73
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 4 deletions.
6 changes: 5 additions & 1 deletion dsl/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ import (
// - "swagger:generate" DEPRECATED, use "openapi:generate" instead.
//
// - "openapi:generate" specifies whether OpenAPI specification should be
// generated. Defaults to true. Applicable to services, methods and file
// generated. Defaults to true. Applicable to Server, Host, services, methods and file
// servers.
//
// var _ = Service("MyService", func() {
Expand Down Expand Up @@ -234,6 +234,10 @@ func Meta(name string, value ...string) {
switch e := eval.Current().(type) {
case *expr.APIExpr:
e.Meta = appendMeta(e.Meta, name, value...)
case *expr.ServerExpr:
e.Meta = appendMeta(e.Meta, name, value...)
case *expr.HostExpr:
e.Meta = appendMeta(e.Meta, name, value...)
case *expr.AttributeExpr:
e.Meta = appendMeta(e.Meta, name, value...)
case *expr.ResultTypeExpr:
Expand Down
4 changes: 4 additions & 0 deletions expr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type (
Services []string
// Hosts list the server hosts.
Hosts []*HostExpr
// Meta is a set of key/value pairs.
Meta MetaExpr
}

// HostExpr describes a server host.
Expand All @@ -40,6 +42,8 @@ type (
URIs []URIExpr
// Variables defines the URI variables if any.
Variables *AttributeExpr
// Meta is a set of key/value pairs.
Meta MetaExpr
}

// URIExpr represents a parameterized URI.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598
github.com/getkin/kin-openapi v0.120.0
github.com/go-chi/chi/v5 v5.0.10
github.com/google/uuid v1.3.1
github.com/google/uuid v1.4.0
github.com/gorilla/websocket v1.5.0
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
Expand Down
3 changes: 3 additions & 0 deletions http/codegen/openapi/v2/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func NewV2(root *expr.RootExpr, h *expr.HostExpr) (*V2, error) {
return nil, fmt.Errorf("failed to parse server URL: %s", err)
}
host := u.Host
if !mustGenerate(root.API.Servers[0].Meta) || !mustGenerate(h.Meta) {
host = ""
}

basePath := root.API.HTTP.Path
if hasAbsoluteRoutes(root) {
Expand Down
2 changes: 2 additions & 0 deletions http/codegen/openapi/v2/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func TestSections(t *testing.T) {
{"with-spaces", testdata.WithSpacesDSL},
{"with-map", testdata.WithMapDSL},
{"path-with-wildcards", testdata.PathWithWildcardDSL},
{"not-generate-server", testdata.NotGenerateServerDSL},
{"not-generate-host", testdata.NotGenerateHostDSL},
}
for _, c := range cases {
t.Run(c.Name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"","version":""},"consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","responses":{"200":{"description":"OK response.","schema":{"type":"string"}}},"schemes":["https"]}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
swagger: "2.0"
info:
title: ""
version: ""
consumes:
- application/json
- application/xml
- application/gob
produces:
- application/json
- application/xml
- application/gob
paths:
/:
get:
tags:
- testService
summary: testEndpoint testService
operationId: testService#testEndpoint
responses:
"200":
description: OK response.
schema:
type: string
schemes:
- https
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"swagger":"2.0","info":{"title":"","version":""},"consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","responses":{"200":{"description":"OK response.","schema":{"type":"string"}}},"schemes":["https"]}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
swagger: "2.0"
info:
title: ""
version: ""
consumes:
- application/json
- application/xml
- application/gob
produces:
- application/json
- application/xml
- application/gob
paths:
/:
get:
tags:
- testService
summary: testEndpoint testService
operationId: testService#testEndpoint
responses:
"200":
description: OK response.
schema:
type: string
schemes:
- https
7 changes: 7 additions & 0 deletions http/codegen/openapi/v3/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,15 @@ func parseOperationIDTemplate(template, service, method string, routeIndex int)
func buildServers(servers []*expr.ServerExpr) []*Server {
var svrs []*Server
for _, svr := range servers {
if !mustGenerate(svr.Meta) {
continue
}
var server *Server
for _, host := range svr.Hosts {
if !mustGenerate(host.Meta) {
continue
}

var (
serverVariable = make(map[string]*ServerVariable)
defaultValue any
Expand Down
2 changes: 2 additions & 0 deletions http/codegen/openapi/v3/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func TestFiles(t *testing.T) {
{"with-tags", testdata.WithTagsDSL},
{"with-tags-swagger", testdata.WithTagsSwaggerDSL},
{"typename", testdata.TypenameDSL},
{"not-generate-server", testdata.NotGenerateServerDSL},
{"not-generate-host", testdata.NotGenerateHostDSL},
// TestEndpoints
{"endpoint", testdata.ExtensionDSL},
{"endpoint-swagger", testdata.ExtensionSwaggerDSL},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"openapi":"3.0.3","info":{"title":"Goa API","version":"1.0"},"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Beatae non id consequatur."},"example":"Aut sed ducimus repudiandae sit explicabo asperiores."}}}}}}},"components":{},"tags":[{"name":"testService"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.3
info:
title: Goa API
version: "1.0"
paths:
/:
get:
tags:
- testService
summary: testEndpoint testService
operationId: testService#testEndpoint
responses:
"200":
description: OK response.
content:
application/json:
schema:
type: string
example: Beatae non id consequatur.
example: Aut sed ducimus repudiandae sit explicabo asperiores.
components: {}
tags:
- name: testService
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"openapi":"3.0.3","info":{"title":"Goa API","version":"1.0"},"paths":{"/":{"get":{"tags":["testService"],"summary":"testEndpoint testService","operationId":"testService#testEndpoint","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Beatae non id consequatur."},"example":"Aut sed ducimus repudiandae sit explicabo asperiores."}}}}}}},"components":{},"tags":[{"name":"testService"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
openapi: 3.0.3
info:
title: Goa API
version: "1.0"
paths:
/:
get:
tags:
- testService
summary: testEndpoint testService
operationId: testService#testEndpoint
responses:
"200":
description: OK response.
content:
application/json:
schema:
type: string
example: Beatae non id consequatur.
example: Aut sed ducimus repudiandae sit explicabo asperiores.
components: {}
tags:
- name: testService
38 changes: 38 additions & 0 deletions http/codegen/testdata/openapi_dsls.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,41 @@ var SkipResponseBodyEncodeDecodeDSL = func() {
})
})
}

var NotGenerateServerDSL = func() {
var _ = API("test", func() {
Server("test", func() {
Host("localhost", func() {
URI("https://goa.design")
})
Meta("openapi:generate", "false")
})
})
Service("testService", func() {
Method("testEndpoint", func() {
Result(String)
HTTP(func() {
GET("/")
})
})
})
}

var NotGenerateHostDSL = func() {
var _ = API("test", func() {
Server("test", func() {
Host("localhost", func() {
URI("https://goa.design")
Meta("openapi:generate", "false")
})
})
})
Service("testService", func() {
Method("testEndpoint", func() {
Result(String)
HTTP(func() {
GET("/")
})
})
})
}

0 comments on commit dc0eb73

Please sign in to comment.