Skip to content

Commit

Permalink
removes option to set where the apib doc file will be written to
Browse files Browse the repository at this point in the history
  • Loading branch information
s-mang committed Dec 7, 2015
1 parent fe83cf2 commit 64d4102
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 8 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ func TestMain(m *testing.M) {
// the raw httptest.Server, so that test2doc can listen to and
// record requests & responses.
//
// NewServer takes 2 arguments:
// - your HTTP handler
// - the path to where you would like the apib doc file
server, err := test.NewServer(router, ".")
// NewServer takes your HTTP handler as an argument
server, err := test.NewServer(router)
if err != nil {
panic(err.Error())
}
Expand Down
65 changes: 65 additions & 0 deletions example/foos/foos.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

# Group Foos

## /foos/{key}

+ Parameters
+ key: `ABeeSee` (string)

### Get Foo [GET]
retrieves a single Foo


+ Response 200 (application/json)



+ Body

{
"B": "A",
"A": "Bee",
"R": "See"
}



## /foos{?n}

+ Parameters
+ n: `10` (number)

### Get Foos [GET]
retrieves the collection of Foos


+ Response 200 (application/json)



+ Body

{
"2": {
"B": "",
"A": "",
"R": "2"
},
"ABeeSee": {
"B": "A",
"A": "Bee",
"R": "See"
},
"OneTwoThree": {
"B": "One",
"A": "Two",
"R": "Three"
},
"SomethingFunForYou": {
"B": "Something",
"A": "Fun",
"R": "ForYou"
}
}


2 changes: 1 addition & 1 deletion example/foos/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRunner(t *testing.T) {

test.RegisterURLVarExtractor(mux.Vars)

server, err = test.NewServer(router, ".")
server, err = test.NewServer(router)
if err != nil {
panic(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion example/widgets/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRunner(t *testing.T) {

test.RegisterURLVarExtractor(mux.Vars)

server, err = test.NewServer(router, ".")
server, err = test.NewServer(router)
if err != nil {
panic(err.Error())
}
Expand Down
111 changes: 111 additions & 0 deletions example/widgets/widgets.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

# Group Widgets

## /widgets/{id}

+ Parameters
+ id: `2` (number)

### Get Widget [GET]
retrieves a single Widget


+ Response 200 (application/json)



+ Body

{
"Id": 2,
"Name": "Pencil",
"Role": "Utensil"
}



## /widgets

### Get Widgets [GET]
retrieves the collection of Wisdget


+ Response 200 (application/json)



+ Body

[
{
"Id": 0,
"Name": "Nothing",
"Role": "N/A"
},
{
"Id": 1,
"Name": "Jibjab",
"Role": "Instrument"
},
{
"Id": 2,
"Name": "Pencil",
"Role": "Utensil"
},
{
"Id": 3,
"Name": "Fork",
"Role": "Utensil"
},
{
"Id": 4,
"Name": "Password",
"Role": "Credential"
},
{
"Id": 5,
"Name": "SpanFrankisco",
"Role": "Home"
},
{
"Id": 6,
"Name": "Doc",
"Role": "Villain"
},
{
"Id": 7,
"Name": "Coff3e",
"Role": "Hack"
}
]


### Post Widget [POST]
adds a Widget to the collection


+ Request (application/json)



+ Body

{
"Id": 0,
"Name": "anotherwidget",
"Role": "controller"
}

+ Response 201 (application/json)



+ Body

{
"Id": 8,
"Name": "anotherwidget",
"Role": "controller"
}


4 changes: 2 additions & 2 deletions test/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ type Server struct {
}

// TODO: filter out 404 responses
func NewServer(handler http.Handler, pkgDir string) (s *Server, err error) {
func NewServer(handler http.Handler) (s *Server, err error) {
// check if url var extractor func is set
if parse.Extractor == nil {
panic("please set a URLVarExtractor.")
}

outDoc, err := doc.NewDoc(pkgDir)
outDoc, err := doc.NewDoc(".")
if err != nil {
return s, err
}
Expand Down

0 comments on commit 64d4102

Please sign in to comment.