zswagger

package module
v0.0.0-...-e6b4aba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

README

ZSwagger

Generate Swagger 2.0 OpenAPI Documentation

Usage

package main

import (
	"encoding/json"
	"io/ioutil"

	"github.com/go-zing/gozz-kit/zapi/zswagger"
	"github.com/go-zing/gozz-kit/zdoc"
)

func main() {
	swagger := zswagger.Parse(
		// Apis in zzgen.api.go 
		types.Apis{},
		// Docs in zzgen.doc.go
		zswagger.WithDocFunc(zdoc.TypesDoc(types.ZZ_types_doc).TypeFieldDoc),
		
		// binding rules
		zswagger.WithBindings(map[string]zswagger.Binding{
			"GET": {
				Path:   "uri",
				Query:  "form",
				Header: "",
				Body:   false,
			},
			"POST": {
				Path:   "uri",
				Header: "",
				Body:   true,
			},
		}),
	)
	b, err := json.MarshalIndent(swagger, "", "    ")
	if err != nil {
		t.Fatal(err)
	}
	_ = ioutil.WriteFile("example.json", b, 0o664)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(iterator zapi.Iterator, option ...func(*Option)) (swagger *spec.Swagger)

func RegisterSchemaType

func RegisterSchemaType(typ reflect.Type, fn func(*spec.Schema))

func WithBindings

func WithBindings(v map[string]Binding) func(*Option)

func WithDocFunc

func WithDocFunc(v func(reflect.Type, string) string) func(*Option)

func WithHttpCast

func WithHttpCast(v func(api zapi.Api) zapi.HttpApi) func(*Option)

Types

type Binding

type Binding struct {
	Path   string
	Query  string
	Header string
	Body   bool
}

type Option

type Option struct {
	HttpCast func(api zapi.Api) zapi.HttpApi
	Bindings map[string]Binding
	DocFunc  func(reflect.Type, string) string
}

+zz:option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL