New returns the OpenAPI v3 specification for the given API. It returns nil if the design does not define HTTP endpoints.
(root *expr.RootExpr)
| 26 | // New returns the OpenAPI v3 specification for the given API. |
| 27 | // It returns nil if the design does not define HTTP endpoints. |
| 28 | func New(root *expr.RootExpr) *OpenAPI { |
| 29 | if root == nil || root.API == nil || root.API.HTTP == nil || len(root.API.HTTP.Services) == 0 { |
| 30 | // No HTTP transport |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | m, ok := root.API.Meta.Last("openapi:example") |
| 35 | if !ok { |
| 36 | m, ok = root.API.Meta.Last("swagger:example") |
| 37 | } |
| 38 | if ok && m == "false" { |
| 39 | root.API.ExampleGenerator.Randomizer = nil |
| 40 | } |
| 41 | |
| 42 | var ( |
| 43 | bodies, types = buildBodyTypes(root.API, root.Types, root.ResultTypes) |
| 44 | |
| 45 | info = buildInfo(root.API) |
| 46 | comps = buildComponents(root, types) |
| 47 | servers = buildServers(root.API.Servers) |
| 48 | paths = buildPaths(root.API.HTTP, bodies, root.API) |
| 49 | security = buildSecurityRequirements(root.API.Requirements) |
| 50 | tags = buildTags(root.API) |
| 51 | ) |
| 52 | |
| 53 | return &OpenAPI{ |
| 54 | OpenAPI: OpenAPIVersion, |
| 55 | Info: info, |
| 56 | Components: comps, |
| 57 | Paths: paths, |
| 58 | Servers: servers, |
| 59 | Security: security, |
| 60 | Tags: tags, |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // buildInfo builds the OpenAPI Info object. |
| 65 | func buildInfo(api *expr.APIExpr) *Info { |