Skip to content

Commit

Permalink
docs: fix YAML command example
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Oct 23, 2024
1 parent ee574f8 commit f070a77
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit f070a77

Please sign in to comment.