Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Params in documentation follows the order
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Oct 6, 2014
1 parent 80cc753 commit 367e08d
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 38 deletions.
26 changes: 19 additions & 7 deletions alpaca/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,27 @@ func PrntFunctionMaker(boolcap bool, tab, strbeg, strend, arrbeg, arrend, objbeg
return ""
}

return func(args map[string]DocParam, sep string, notLast bool) string {
str := ""
return func(api interface{}, doc map[string]DocParam, sep string, notLast bool) string {
str, typ := "", reflect.TypeOf(api).String()

if len(args) == 0 {
return str
}
if typ == "[]string" {
if len(api.([]string)) == 0 {
return str
}

for _, v := range api.([]string) {
str += vals(doc[v].Value) + sep
}
} else if typ == "[]alpaca.ApiParam" {
if len(api.([]ApiParam)) == 0 {
return str
}

for _, v := range args {
str += vals(v.Value) + sep
for _, v := range api.([]ApiParam) {
str += vals(doc[v.Name].Value) + sep
}
} else {
return str
}

if !notLast {
Expand Down
42 changes: 27 additions & 15 deletions alpaca/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ func TestPathFunctionMaker(t *testing.T) {
func TestPrntFunctionMaker(t *testing.T) {
terst.Terst(t)

f := PrntFunctionMaker(true, " ", "'", "'", "[", "]", "{", "}", ":", " => ").(func(map[string]DocParam, string, bool) string)
f := PrntFunctionMaker(true, " ", "'", "'", "[", "]", "{", "}", ":", " => ").(func(interface{}, map[string]DocParam, string, bool) string)

args := make(map[string]DocParam)
apis := []string{"id"}
apip := make([]ApiParam, 1)
docs := make(map[string]DocParam)
vals := make(map[string]interface{})
orgs := make([]interface{}, 3)
null := make(map[string]string)
Expand All @@ -66,29 +68,39 @@ func TestPrntFunctionMaker(t *testing.T) {
orgs[1] = "alpaca-api"
orgs[2] = 00

terst.Is(f(make(map[string]DocParam), ", ", true), "")
apip[0] = ApiParam{"id", true, false}

terst.Is(f([]string{}, make(map[string]DocParam), ", ", true), "")
terst.Is(f([]ApiParam{}, make(map[string]DocParam), ", ", true), "")
terst.Is(f([]int{}, make(map[string]DocParam), ", ", true), "")

vals["key"] = 3737
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", true), "{\n :key => 3737\n}, ")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", true), "{\n :key => 3737\n}, ")
terst.Is(f(apip, docs, ", ", true), "{\n :key => 3737\n}, ")

vals["key"] = 1.99
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", false), "{\n :key => 1.99\n}")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", false), "{\n :key => 1.99\n}")
terst.Is(f(apip, docs, ", ", false), "{\n :key => 1.99\n}")

vals["key"] = "pksunkara"
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", false), "{\n :key => 'pksunkara'\n}")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", false), "{\n :key => 'pksunkara'\n}")
terst.Is(f(apip, docs, ", ", false), "{\n :key => 'pksunkara'\n}")

vals["key"] = true
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", false), "{\n :key => True\n}")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", false), "{\n :key => True\n}")
terst.Is(f(apip, docs, ", ", false), "{\n :key => True\n}")

vals["key"] = orgs
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", false), "{\n :key => [\n False,\n 'alpaca-api',\n 0\n ]\n}")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", false), "{\n :key => [\n False,\n 'alpaca-api',\n 0\n ]\n}")
terst.Is(f(apip, docs, ", ", false), "{\n :key => [\n False,\n 'alpaca-api',\n 0\n ]\n}")

vals["key"] = null
args["id"] = DocParam{"", vals}
terst.Is(f(args, ", ", false), "{\n :key => \n}")
docs["id"] = DocParam{"", vals}
terst.Is(f(apis, docs, ", ", false), "{\n :key => \n}")
terst.Is(f(apip, docs, ", ", false), "{\n :key => \n}")
}
6 changes: 3 additions & 3 deletions examples/helpful/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"name": "accounts",
"functions": [
{
"name": "list",
"name": "all",
"path": "/accounts"
},
{
Expand Down Expand Up @@ -58,7 +58,7 @@
"name": "people",
"functions": [
{
"name": "list",
"name": "all",
"path": "/accounts/:account_id/people",
"params": [
{
Expand All @@ -74,7 +74,7 @@
"name": "conversations",
"functions": [
{
"name": "list",
"name": "all",
"path": "/accounts/:account_id/conversations",
"params": [
{
Expand Down
6 changes: 3 additions & 3 deletions examples/helpful/doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Accounts",
"desc": "These are like organizations which use Helpful.",
"functions": {
"list": {
"all": {
"title": "List all accounts",
"desc": "All the accounts the user has access to"
},
Expand Down Expand Up @@ -33,7 +33,7 @@
"title": "People",
"desc": "People who operate or interacted with the account",
"functions": {
"list": {
"all": {
"title": "List all people",
"desc": "List all people in the account the user has access to",
"params": {
Expand All @@ -49,7 +49,7 @@
"title": "Conversations",
"desc": "Conversations in an account",
"functions": {
"list": {
"all": {
"title": "List all conversations",
"desc": "List all conversations in an account the user has access to",
"params": {
Expand Down
4 changes: 2 additions & 2 deletions examples/helpful/pkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Helpful",
"package": "helpful",
"version": "0.1.0",
"package": "helpful-client",
"version": "1.0.0",
"url": "https://helpful.io",
"keywords": ["alpaca", "helpful", "assemblymade", "api", "client", "library"],
"official": true,
Expand Down
4 changes: 2 additions & 2 deletions templates/node/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ The following arguments are required:
* __{{.}}__: {{(index ((index $data.Doc $class.Name).Args) .).Desc}}{{end}}
```js
var {{call $data.Fnc.camelizeDownFirst $class.Name}} = client.{{call $data.Fnc.camelizeDownFirst $class.Name}}({{call $data.Fnc.prnt.node ((index $data.Doc $class.Name).Args) ", " false}});
var {{call $data.Fnc.camelizeDownFirst $class.Name}} = client.{{call $data.Fnc.camelizeDownFirst $class.Name}}({{call $data.Fnc.prnt.node .Args ((index $data.Doc $class.Name).Args) ", " false}});
```
{{range $class.Functions}}
##### {{(index ((index $data.Doc $class.Name).Functions) .Name).Title}} ({{call $data.Fnc.upper (or .Method "get")}} {{.Path}})
Expand All @@ -175,7 +175,7 @@ The following arguments are required:
* __{{.Name}}__: {{(index ((index ((index $data.Doc $class.Name).Functions) $method.Name).Params) .Name).Desc}}{{end}}{{end}}{{end}}
```js
{{call $data.Fnc.camelizeDownFirst $class.Name}}.{{call $data.Fnc.camelizeDownFirst .Name}}({{call $data.Fnc.prnt.node ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options, callback);
{{call $data.Fnc.camelizeDownFirst $class.Name}}.{{call $data.Fnc.camelizeDownFirst .Name}}({{call $data.Fnc.prnt.node .Params ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options, callback);
```
{{end}}{{end}}{{end}}{{end}}
## Contributors
Expand Down
4 changes: 2 additions & 2 deletions templates/php/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The following arguments are required:
* __{{.}}__: {{(index ((index $data.Doc $class.Name).Args) .).Desc}}{{end}}

```php
${{call $data.Fnc.camelizeDownFirst $class.Name}} = $client->{{call $data.Fnc.camelizeDownFirst $class.Name}}({{call $data.Fnc.prnt.php ((index $data.Doc $class.Name).Args) ", " false}});
${{call $data.Fnc.camelizeDownFirst $class.Name}} = $client->{{call $data.Fnc.camelizeDownFirst $class.Name}}({{call $data.Fnc.prnt.php .Args ((index $data.Doc $class.Name).Args) ", " false}});
```
{{range $class.Functions}}
##### {{(index ((index $data.Doc $class.Name).Functions) .Name).Title}} ({{call $data.Fnc.upper (or .Method "get")}} {{.Path}})
Expand All @@ -188,7 +188,7 @@ The following arguments are required:
* __{{.Name}}__: {{(index ((index ((index $data.Doc $class.Name).Functions) $method.Name).Params) .Name).Desc}}{{end}}{{end}}{{end}}

```php
$response = ${{call $data.Fnc.camelizeDownFirst $class.Name}}->{{call $data.Fnc.camelizeDownFirst .Name}}({{call $data.Fnc.prnt.php ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}$options);
$response = ${{call $data.Fnc.camelizeDownFirst $class.Name}}->{{call $data.Fnc.camelizeDownFirst .Name}}({{call $data.Fnc.prnt.php .Params ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}$options);
```
{{end}}{{end}}{{end}}{{end}}
## Contributors
Expand Down
4 changes: 2 additions & 2 deletions templates/python/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The following arguments are required:
* __{{.}}__: {{(index ((index $data.Doc $class.Name).Args) .).Desc}}{{end}}

```python
{{call $data.Fnc.underscore $class.Name}} = client.{{call $data.Fnc.underscore $class.Name}}({{call $data.Fnc.prnt.python ((index $data.Doc $class.Name).Args) ", " false}})
{{call $data.Fnc.underscore $class.Name}} = client.{{call $data.Fnc.underscore $class.Name}}({{call $data.Fnc.prnt.python .Args ((index $data.Doc $class.Name).Args) ", " false}})
```
{{range $class.Functions}}
##### {{(index ((index $data.Doc $class.Name).Functions) .Name).Title}} ({{call $data.Fnc.upper (or .Method "get")}} {{.Path}})
Expand All @@ -171,7 +171,7 @@ The following arguments are required:
* __{{.Name}}__: {{(index ((index ((index $data.Doc $class.Name).Functions) $method.Name).Params) .Name).Desc}}{{end}}{{end}}{{end}}

```python
response = {{call $data.Fnc.underscore $class.Name}}.{{call $data.Fnc.underscore .Name}}({{call $data.Fnc.prnt.python ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options)
response = {{call $data.Fnc.underscore $class.Name}}.{{call $data.Fnc.underscore .Name}}({{call $data.Fnc.prnt.python .Params ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options)
```
{{end}}{{end}}{{end}}{{end}}
## Contributors
Expand Down
4 changes: 2 additions & 2 deletions templates/ruby/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The following arguments are required:
* __{{.}}__: {{(index ((index $data.Doc $class.Name).Args) .).Desc}}{{end}}

```ruby
{{call $data.Fnc.underscore $class.Name}} = client.{{call $data.Fnc.underscore $class.Name}}({{call $data.Fnc.prnt.ruby ((index $data.Doc $class.Name).Args) ", " false}})
{{call $data.Fnc.underscore $class.Name}} = client.{{call $data.Fnc.underscore $class.Name}}({{call $data.Fnc.prnt.ruby .Args ((index $data.Doc $class.Name).Args) ", " false}})
```
{{range $class.Functions}}
##### {{(index ((index $data.Doc $class.Name).Functions) .Name).Title}} ({{call $data.Fnc.upper (or .Method "get")}} {{.Path}})
Expand All @@ -171,7 +171,7 @@ The following arguments are required:
* __{{.Name}}__: {{(index ((index ((index $data.Doc $class.Name).Functions) $method.Name).Params) .Name).Desc}}{{end}}{{end}}{{end}}

```ruby
response = {{call $data.Fnc.underscore $class.Name}}.{{call $data.Fnc.underscore .Name}}({{call $data.Fnc.prnt.ruby ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options)
response = {{call $data.Fnc.underscore $class.Name}}.{{call $data.Fnc.underscore .Name}}({{call $data.Fnc.prnt.ruby .Params ((index ((index $data.Doc $class.Name).Functions) .Name).Params) ", " true}}options)
```
{{end}}{{end}}{{end}}{{end}}
## Contributors
Expand Down

0 comments on commit 367e08d

Please sign in to comment.