-
-
Notifications
You must be signed in to change notification settings - Fork 583
Expand file tree
/
Copy pathopenapi.go
More file actions
35 lines (30 loc) · 760 Bytes
/
openapi.go
File metadata and controls
35 lines (30 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package codegen
import (
"goa.design/goa/codegen"
"goa.design/goa/expr"
openapiv2 "goa.design/goa/http/codegen/openapi/v2"
openapiv3 "goa.design/goa/http/codegen/openapi/v3"
)
// OpenAPIFiles returns the files for the OpenAPIFile spec of the given HTTP API.
func OpenAPIFiles(root *expr.RootExpr) ([]*codegen.File, error) {
// Only create a OpenAPI specification if there are HTTP services.
if len(root.API.HTTP.Services) == 0 {
return nil, nil
}
var files []*codegen.File
{
// OpenAPI v2
fs, err := openapiv2.Files(root)
if err != nil {
return nil, err
}
files = append(files, fs...)
// OpenAPI v3
fs, err = openapiv3.Files(root)
if err != nil {
return nil, err
}
files = append(files, fs...)
}
return files, nil
}