8000 GitHub - b1tray3r/go-openapi3: This repository contains an almost minimal setup for developing a REST service using Echo, OpenAPI and Swagger-UI integration.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

This repository contains an almost minimal setup for developing a REST service using Echo, OpenAPI and Swagger-UI integration.

Notifications You must be signed in to change notification settings

b1tray3r/go-openapi3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPI Restservice with Swagger-UI

This repository contains an almost minimal setup for developing a REST service using Echo, OpenAPI and Swagger-UI integration.

The generation and build process is using air for easy setup.

The OpenAPI defintion is defined with code using go in the internal/openapi/definition.go file.

During the build steps air is going to generate the openapi3.json file in the cmd/swagger directory. Additionally, the according server interfaces are generated with oapi-codegen into the pkg/api/ folder.

The application will serve the Swagger-UI at swagger/ endpoint.

The backend is implemented in the internal/server/server.gofile.

Setup

  1. Clone the project
git clone https://github.com/b1tray3r/go-openapi3.git
  1. Change the directory
cd go-openapi3
  1. Install openapi-gen
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
  1. Install air
go install github.com/air-verse/air@latest
  1. Launch
air

Details

Many things are hardcoded on purpose to keep the repository as barebone as possible.

index.html

This contains the swagger-ui code and requires access to unpkg servers.

The file is requesting the generated /swagger/openapi3.json file to build the GUI.

.air.toml

Using air the complete build pipeline is executed on the fly. When building the final application you have to execute all pre_cmd entries in the .air.toml configuration.

Please note that all *.gen.go files are ignored by air. It is important for air to exclude this files, because generating these file(s) will cause air to loop indefinetly.

oapi-codegen.yml

This configuration is responsible to generate the api interfaces and types for echo. I am not sure whether this is an optimal configuration, but it seems to work.

Sources

About

This repository contains an almost minimal setup for developing a REST service using Echo, OpenAPI and Swagger-UI integration.

Topics

Resources

Stars

Watchers

Forks

0