Postman and openAPI specs (#174)

This commit is contained in:
Dominic Wong
2021-06-29 15:50:06 +01:00
committed by GitHub
parent d212fd2f5c
commit 221ff019af
6 changed files with 46 additions and 61 deletions

View File

@@ -25,6 +25,7 @@ type PublicAPI struct {
OpenAPIJson string `json:"open_api_json"`
Pricing map[string]int64 `json:"pricing,omitempty"`
ExamplesJson string `json:"examples_json,omitempty"`
PostmanJson string `json:"postman_json,omitempty"`
}
func publishAPI(apiSpec *PublicAPI) error {
@@ -34,6 +35,7 @@ func publishAPI(apiSpec *PublicAPI) error {
postBody, _ := json.Marshal(map[string]interface{}{
"api": apiSpec,
})
rbody := bytes.NewBuffer(postBody)
//Leverage Go's HTTP Post function to make request
@@ -92,7 +94,18 @@ func main() {
fmt.Println("Failed to make api", string(outp))
os.Exit(1)
}
serviceName := f.Name()
// generate the Postman collection
postman := exec.Command("openapi2postmanv2", "-s", fmt.Sprintf("api-%s.json", serviceName), "-o", "postman.json")
postman.Dir = serviceDir
outp, err = postman.CombinedOutput()
if err != nil {
fmt.Printf("Failed to generate postman collection %s %s\n", string(outp), err)
os.Exit(1)
}
dat, err := ioutil.ReadFile(filepath.Join(serviceDir, "README.md"))
if err != nil {
fmt.Println("Failed to read readme", string(outp))
@@ -155,6 +168,13 @@ func main() {
}
}
// load the postman json
if postman, err := ioutil.ReadFile(filepath.Join(serviceDir, "postman.json")); err == nil {
if len(postman) > 0 {
publicApi.PostmanJson = string(postman)
}
}
// publish the api
if err := publishAPI(publicApi); err != nil {
fmt.Println("Failed to save data to publicapi service", err)