mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-15 04:24:44 +00:00
Postman and openAPI specs (#174)
This commit is contained in:
@@ -47,11 +47,11 @@ var cases = []tspec{
|
||||
}`,
|
||||
key: "QueryRequest",
|
||||
tsresult: `export interface QueryRequest {
|
||||
id?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
slug?: number;
|
||||
tag?: number;
|
||||
id?: number;
|
||||
slug?: string;
|
||||
tag?: string;
|
||||
}`,
|
||||
},
|
||||
{
|
||||
@@ -120,18 +120,18 @@ var cases = []tspec{
|
||||
tsresult: `
|
||||
export interface QueryResponse {
|
||||
posts?: {
|
||||
metadata?: {
|
||||
value?: string;
|
||||
key?: string;
|
||||
}[];
|
||||
slug?: string;
|
||||
title?: string;
|
||||
author?: string;
|
||||
content?: string;
|
||||
created?: number;
|
||||
id?: string;
|
||||
image?: string;
|
||||
author?: string;
|
||||
metadata?: {
|
||||
key?: string;
|
||||
value?: string;
|
||||
}[];
|
||||
slug?: string;
|
||||
tags?: string[];
|
||||
title?: string;
|
||||
updated?: number;
|
||||
}[];
|
||||
}`,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
@@ -181,7 +182,13 @@ func schemaToTs(title string, spec *openapi3.SchemaRef) string {
|
||||
ret := ""
|
||||
|
||||
i := 0
|
||||
for k, v := range props {
|
||||
var keys []string
|
||||
for k := range props {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range keys {
|
||||
v := props[k]
|
||||
ret += strings.Repeat(" ", level)
|
||||
k = strcase.SnakeCase(k)
|
||||
//v.Value.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user