Skip to content

Latest commit

 

History

History

entoas

entoas

Generate a fully compliant, extendable OpenAPI Specification document to enable you to make use of the Swagger Tooling to generate RESTful server stubs and clients.

To generate a ready-to-use server implementation of the OpenAPI Specification generated by entoas have a look at elk.

Quick Start

Download the module:

go get -u entgo.io/contrib/entoas

Setup code generation with entc package: and register the entoas extension:

  1. Create a new Go file named ent/entc.go and paste the following content:
// +build ignore

package main

import (
	"log"

	"entgo.io/ent/entc"
	"entgo.io/ent/entc/gen"
	"entgo.io/contrib/entoas"
)

func main() {
	ex, err := entoas.NewExtension()
	if err != nil {
		log.Fatalf("creating entoas extension: %v", err)
	}
	err = entc.Generate("./schema", &gen.Config{}, entc.Extensions(ex))
	if err != nil {
		log.Fatalf("running ent codegen: %v", err)
	}
}
  1. Edit the ent/generate.go file to execute the ent/entc.go file:
package ent

//go:generate go run -mod=mod entc.go
  1. Run the code generator:
go generate ./...

Observe, that in addition to the files Ent would normally generate, another file called openapi.json was generated.

For information about configuring the generator head over to the godoc or Ent documentation.

BC

This PR introduced a slight change in the API. entoas now uses ogens OAS struct definitions to create the OAS document. This change eases Specification mutations and also enables users to use ogen to generate both Go client and server implementations for the OAS.