Skip to content

Commit

Permalink
Add flags for GET request parameters (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Oct 29, 2019
1 parent 88bf4e7 commit 931bfda
Show file tree
Hide file tree
Showing 3 changed files with 438 additions and 82 deletions.
37 changes: 28 additions & 9 deletions pkg/cmd/gen_resources_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"go/format"
"io/ioutil"
"net/http"
"strings"
"text/template"

Expand All @@ -29,8 +30,8 @@ type ResourceData struct {
}

type OperationData struct {
Path string
HTTPVerb string
Path string
HTTPVerb string
PropFlags map[string]string
}

Expand Down Expand Up @@ -133,23 +134,41 @@ func getTemplateData() (*TemplateData, error) {
properties := make(map[string]string)

specOp := stripeAPI.Paths[spec.Path(op.Path)][spec.HTTPVerb(httpString)]
requestContent := specOp.RequestBody.Content

if media, ok := requestContent["application/x-www-form-urlencoded"]; ok {
for propName, schema := range media.Schema.Properties {
if strings.ToUpper(httpString) == http.MethodPost {
requestContent := specOp.RequestBody.Content

if media, ok := requestContent["application/x-www-form-urlencoded"]; ok {
for propName, schema := range media.Schema.Properties {
// only deal with scalar types for now
if schema.Type != "string" && schema.Type != "integer" {
continue
}

properties[propName] = schema.Type
}
}
} else {
for _, param := range specOp.Parameters {
// Only create flags for query string parameters
if param.In != "query" {
continue
}

schema := param.Schema

// only deal with scalar types for now
if schema.Type != "string" && schema.Type != "integer" {
continue
}

properties[propName] = schema.Type

properties[param.Name] = schema.Type
}
}

data.Namespaces[nsName].Resources[resCmdName].Operations[op.MethodName] = &OperationData{
Path: op.Path,
HTTPVerb: httpString,
Path: op.Path,
HTTPVerb: httpString,
PropFlags: properties,
}
}
Expand Down

0 comments on commit 931bfda

Please sign in to comment.