这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/docs/features/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,19 @@ cli.Root().AddCommand(&cobra.Command{
Use: "openapi",
Short: "Print the OpenAPI spec",
Run: func(cmd *cobra.Command, args []string) {
b, _ := yaml.Marshal(api.OpenAPI())
b, err := api.OpenAPI().YAML()
if err != nil {
panic(err)
}
fmt.Println(string(b))
},
})
```

!!! info "Note"

You can use `api.OpenAPI().DowngradeYAML()` to output OpenAPI 3.0 instead of 3.1 for tools that don't support 3.1 yet.

Now you can run your service and use the new command: `go run . openapi`. Notice that it never starts the server; it just runs your command handler code. Some ideas for custom commands:

- Print the OpenAPI spec
Expand Down
Loading