# OpenAPI3

Link to repository (opens new window)

An automated OpenAPI 3 (opens new window) specification generator for the Goyave (opens new window) REST API framework, using kin-openapi/openapi3 (opens new window) in the background.

Just from reading your code, this generator is able to fill an OpenAPI 3 specification with:

  • Paths and operations
  • Path parameters (with patterns)
  • Body and query parameters
  • Full support for validation
  • File upload support
  • Handler documentation (uses comments on Handler function)
  • Server (uses config for domain name / host / port)
  • SwaggerUI

Note: this generator doesn't create responses because it doesn't have any way to know what your handlers will return.

# Usage

go get -u goyave.dev/openapi3

Add the following at the end of your main route registrer:

spec := openapi3.NewGenerator().Generate(router)
json, err := spec.MarshalJSON()
if err != nil {
    panic(err)
}
fmt.Println(string(json))

You can alter the resulting openapi3.T (opens new window) after generation. Like so, you can add responses details to your operations, top-level info, and more.

# SwaggerUI

You can serve a SwaggerUI (opens new window) for your spec directly from your server using the built-in handler:

spec := openapi3.NewGenerator().Generate(router)
opts := openapi3.NewUIOptions(spec)
openapi3.Serve(router, "/openapi", opts)

Then navigate to http://localhost:8080/openapi (provided you use the default port).