Skip to content

eiixy/swagger-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swagger-api

Install

protoc-gen-openapi

go install github.com/google/gnostic/cmd/protoc-gen-openapi

statik

go get github.com/rakyll/statik
go install github.com/rakyll/statik

QuickStart

examples/apis/Makefile

protoc --proto_path=./api/ \
    --proto_path=./third_party \
    --openapi_out=output_mode=source_relative:./api/ \
    $(API_PROTO_FILES)

examples/main.go

package main

import (
	"github.com/eiixy/swagger-api"
	"github.com/eiixy/swagger-api/examples/apis/api"
	"net/http"
)

func main() {
	mux := http.NewServeMux()
	mux.Handle("/swagger/", swagger.Handler(http.FS(api.FS), []swagger.OpenapiURL{
		{"Account Interface", "/account-interface/v1/account.openapi.yaml"},
		{"Auth Interface", "/auth-interface/v1/auth.openapi.yaml"},
	},
		swagger.SetPrefix("/swagger"),
		swagger.SetSwaggerUIPath("ui"),
		swagger.SetOpenapiPath("apis"),
	))
	err := http.ListenAndServe(":8088", mux)
	if err != nil {
		panic(err)
	}
}

SwaggerUI: http://127.0.0.1:8088/swagger/ui