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

Commit ac338ee

Browse files
committed
Only print required params in documentation
1 parent 9581f91 commit ac338ee

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# alpaca [![Build Status](https://drone.io/github.com/pksunkara/alpaca/status.png)](https://drone.io/github.com/pksunkara/alpaca/latest) [![Gitter chat](https://badges.gitter.im/pksunkara/alpaca.png)](https://gitter.im/pksunkara/alpaca)
1+
# alpaca [![Build Status](https://travis-ci.org/pksunkara/alpaca.svg?branch=master)](https://travis-ci.org/pksunkara/alpaca) [![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pksunkara/alpaca)
22

33
Api Libraries Powered And Created by Alpaca
44

alpaca/utils.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,20 @@ func PrntFunctionMaker(boolcap bool, tab, strbeg, strend, arrbeg, arrend, objbeg
144144
str, typ := "", reflect.TypeOf(api).String()
145145

146146
if typ == "[]string" {
147-
if len(api.([]string)) == 0 {
148-
return str
149-
}
150-
151147
for _, v := range api.([]string) {
152148
str += vals(doc[v].Value) + sep
153149
}
154150
} else if typ == "[]alpaca.ApiParam" {
155-
if len(api.([]ApiParam)) == 0 {
156-
return str
157-
}
158-
159151
for _, v := range api.([]ApiParam) {
160-
str += vals(doc[v.Name].Value) + sep
152+
if v.Required {
153+
str += vals(doc[v.Name].Value) + sep
154+
}
161155
}
162156
} else {
163157
return str
164158
}
165159

166-
if !notLast {
160+
if str != "" && !notLast {
167161
return str[0 : len(str)-len(sep)]
168162
}
169163

alpaca/utils_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestPrntFunctionMaker(t *testing.T) {
5858
f := PrntFunctionMaker(true, " ", "'", "'", "[", "]", "{", "}", ":", " => ").(func(interface{}, map[string]DocParam, string, bool) string)
5959

6060
apis := []string{"id"}
61-
apip := make([]ApiParam, 1)
61+
apip := make([]ApiParam, 2)
6262
docs := make(map[string]DocParam)
6363
vals := make(map[string]interface{})
6464
orgs := make([]interface{}, 3)
@@ -69,6 +69,9 @@ func TestPrntFunctionMaker(t *testing.T) {
6969
orgs[2] = 00
7070

7171
apip[0] = ApiParam{"id", true, false}
72+
apip[1] = ApiParam{"flag", false, false}
73+
74+
docs["flag"] = DocParam{"", false}
7275

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

0 commit comments

Comments
 (0)