Skip to content

Commit ef3585b

Browse files
authored
feat(docs): update documentation generation and examples (#212)
1 parent 82d9778 commit ef3585b

19 files changed

Lines changed: 294 additions & 52 deletions

File tree

docs/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,41 @@ Enabling the plugin changes the behavior of the `gen` command of the `goa` tool.
113113
The command generates an additional `docs.json` at the top level containing the
114114
documentation.
115115

116+
### Respecting openapi:generate metadata
117+
118+
The docs plugin respects Goa's `Meta("openapi:generate", "false")` (and legacy `"swagger:generate"`) to control documentation generation:
119+
120+
- Service-level: adding `Meta("openapi:generate", "false")` to a `Service` excludes that service from `docs.json`.
121+
- Method-level: adding `Meta("openapi:generate", "false")` to a `Method` excludes that method from `docs.json`.
122+
- HTTP-level: the same meta can be set inside `HTTP(...)` blocks for services or methods and will be honored.
123+
124+
This mirrors Goa's OpenAPI generation semantics.
125+
126+
### Disabling docs.json per service or method
127+
128+
To disable inclusion in `docs.json` without affecting OpenAPI generation, use the docs DSL `DisableDocs()` inside a service or method DSL:
129+
130+
```go
131+
import (
132+
. "goa.design/plugins/v3/docs/dsl"
133+
. "goa.design/goa/v3/dsl"
134+
)
135+
136+
var _ = Service("front", func() {
137+
DisableDocs() // service omitted from docs.json, OpenAPI still generated
138+
Method("about", func() { /* ... */ })
139+
})
140+
141+
var _ = Service("S", func() {
142+
Method("M1", func() {
143+
DisableDocs() // method omitted from docs.json, OpenAPI still generated
144+
/* ... */
145+
})
146+
})
147+
```
148+
149+
Under the hood, `DisableDocs()` sets `Meta("docs:generate", "false")`; the plugin filters those out when building docs.json.
150+
116151
## Known Limitations
117152

118153
If `goa gen` is invoked with a custom output path (i.e. with the `-o` argument)

docs/dsl/docs.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dsl
22

33
import (
4+
"goa.design/goa/v3/eval"
5+
goaexpr "goa.design/goa/v3/expr"
46
"goa.design/plugins/v3/docs"
57
"goa.design/plugins/v3/docs/expr"
68
)
@@ -16,3 +18,25 @@ func UseJSONTags() { expr.Root.UseJSONTags = true }
1618
// InlineRefs configures the docs plugin to inline referenced schemas in JSON
1719
// Schema output where possible. Cycles are preserved by keeping $ref.
1820
func InlineRefs() { expr.Root.InlineRefs = true }
21+
22+
// DisableDocs disables docs.json generation for the current service only.
23+
// It does not affect OpenAPI generation. Invoke inside a Service DSL.
24+
//
25+
// Service("front", func() {
26+
// DisableDocs()
27+
// // ... methods ...
28+
// })
29+
func DisableDocs() {
30+
switch cur := eval.Current().(type) {
31+
case *goaexpr.ServiceExpr:
32+
if cur.Meta == nil {
33+
cur.Meta = make(goaexpr.MetaExpr)
34+
}
35+
cur.Meta["docs:generate"] = []string{"false"}
36+
case *goaexpr.MethodExpr:
37+
if cur.Meta == nil {
38+
cur.Meta = make(goaexpr.MetaExpr)
39+
}
40+
cur.Meta["docs:generate"] = []string{"false"}
41+
}
42+
}

docs/examples/calc/gen/calc/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/calc/endpoints.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/calc/service.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/http/calc/client/cli.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/http/calc/client/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/http/calc/client/encode_decode.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/http/calc/client/paths.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/calc/gen/http/calc/client/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)