go-oas / docs

Automatically generate RESTful API documentation for GO projects - aligned with Open API Specification standard

Home Page:https://t.me/go_oas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to generate example request and response payloads?

dcs3spp opened this issue · comments

Hi,

Is there any example code for how to use go-oas to generate request and response examples for swagger docs?
Do schemas have to be manually specified or is there a way to generate them from golang structs?

Hi @dcs3spp ,

The current examples can be found (here)[https://github.com/go-oas/docs/tree/main/examples/file_output]. You might want to take a look at the combination of these two:

  1. https://github.com/go-oas/docs/blob/6e09fa6b336d503d51191a0bc4ac75a923b6f89c/examples/file_output/users_example/post-user.go#LL7C33-L7C33
  2. func handleCreateUserRoute(oasPathIndex int, oas *docs.OAS) {

Schemas do not have to be manually specified. You have the freedom to either load via embedding or design one that might best fit your needs (as a wrapper around this library).

Also, you would be welcome to create an RFC or a PR to this codebase with what you would resolve your current needs - I am pretty open to any external input. 💪