Skip to content

A Go Lang SDK to help create OpenApi 3.0.3 Spec with go-lang

License

Notifications You must be signed in to change notification settings

hydronica/go-openapi

Repository files navigation

GoOpenAPI

A Go Lang SDK to help create OpenApi 3.0.3 Spec

OpenAPI spec

codecov

Getting Started

import (
    _ "embed"
    
    "github.com/hydronica/go-openapi"
)

// go:embed base.json 
var base string 
func main() {

    // create doc from base template
    doc, err := openapi.NewFromJson(base)
    if err != nil {
        log.Fatal(err) 
    }
    
    // create doc from scratch
    doc = openapi.New("title", "v1.0.0", "all about this API") 
   
    doc.AddRoute(
        openapi.NewRoute("/path/v1", "GET").
            AddResponse(
                openapi.Resp{Code: 200, Desc:"valid response"}.WithJSONString('{"status":"ok"}'
                ). 
            AddRequest(
                openapi.Req{MType: "application/json", Desc:"pull data"}.
                    WithParams(myStruct)
                )
    ) 
   
   // print generated json document
   fmt.Println(string(doc.JSON()))
}

Overview

About

A Go Lang SDK to help create OpenApi 3.0.3 Spec with go-lang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages