Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
main
.idea/
example/restapi
example/models
example/client
testdata/restapi
testdata/models
testdata/client
**/RCS/*
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
all: clean example test
all: clean testdata test

image = go-swagger:strato

swagger = docker run --rm \
-e GOPATH=$(GOPATH):/go \
-v $(PWD):$(PWD) \
-w $(PWD)/example \
-w $(PWD)/testdata \
-u $(shell id -u):$(shell id -g) \
$(image)

build:
docker build . -t $(image)

test:
go build ./example/main.go
go test ./...
cd testdata && go build ./main.go
cd testdata && go test ./...

example: build clean
cd example ; \
testdata: build clean
cd testdata ; \
$(swagger) generate server ; \
$(swagger) generate client ; \
go generate ./...

clean:
rm -rf example/restapi example/models example/client
rm -rf testdata/restapi testdata/models testdata/client
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ We re-wrote some of go-swagger's templates, and now we have:

### The `restapi` returns an `http.Handler`

The `restapi.Handler` (see [example](./example/restapi/configure_swagger_petstore.go)) function returns
The `restapi.Handler` (see [example](./testdata/restapi/configure_swagger_petstore.go)) function returns
a standard `http.Handler`

* Given objects that implements the business logic, we can create a simple http handler.
Expand Down Expand Up @@ -65,16 +65,16 @@ swagger version

# Example Walk-Through

In the [example package](./example) you'll find generated code and usage of the pet-store
[swagger file](./example/swagger.yaml).
In the [example package](./testdata) you'll find generated code and usage of the pet-store
[swagger file](./testdata/swagger.yaml).

* The `restapi`, `models` and `client` are auto-generated by the stratoscale/swagger docker file.
* The `internal` package was manually added and contains the server's business logic.
* The `main.go` file is the entrypoint and contains initializations and dependency injections of the project.

## Server

### [restapi](./example/restapi)
### [restapi](./testdata/restapi)

This package is autogenerated and contains the server routing and parameters parsing.

Expand Down Expand Up @@ -132,7 +132,7 @@ func Handler(c Config) (http.Handler, error) {

Let's look how we use this generated code to build our server.

### [internal](./example/internal)
### [internal](./testdata/internal)

The `internal` package is **not** auto generated and contains the business logic of our server.
We can see two structs that implements the `restapi.PetAPI` and `restapi.StoreAPI` interfaces,
Expand All @@ -141,7 +141,7 @@ needed to make our server work.
When adding or removing functions from our REST API, we can just add or remove functions to those
business logic units. We can also create new logical units when they are added to our REST API.

### [main.go](./example/main.go)
### [main.go](./testdata/main.go)

The main function is pretty straight forward. We initiate our business logic units.
Then create a config for our rest API. We then create a standard `http.Handler` which we can
Expand Down Expand Up @@ -175,7 +175,7 @@ func main() {

## Client

The client code is in the [client package](./example/client) and is autogenerated.
The client code is in the [client package](./testdata/client) and is autogenerated.

To create a new client we use the `client.Config` struct:

Expand Down Expand Up @@ -208,8 +208,8 @@ type SwaggerPetstore {
}
```

Thos fields are objects, which implements interfaces declared in the [pet](./example/client/pet) and
[store](./example/client/store) packages:
Thos fields are objects, which implements interfaces declared in the [pet](./testdata/client/pet) and
[store](./testdata/client/store) packages:

For example:

Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/Stratoscale/swagger

go 1.12

require (
github.com/fatih/structs v1.1.0
github.com/go-openapi/runtime v0.19.6 // indirect
github.com/jinzhu/gorm v1.9.10
github.com/stretchr/testify v1.4.0
)
251 changes: 251 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/auth/auth.go → testdata/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"net/http"

"github.com/Stratoscale/swagger/example/restapi"
"github.com/Stratoscale/swagger/testdata/restapi"
"github.com/go-openapi/runtime/middleware"
)

Expand Down
23 changes: 23 additions & 0 deletions testdata/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module github.com/Stratoscale/swagger/testdata

go 1.12

replace github.com/Stratoscale/swagger/models => /home/ronnie/wgo1/src/github.com/Stratoscale/swagger/testdata/models

replace github.com/Stratoscale/swagger/testdat/auth => /home/ronnie/wgo1/src/github.com/Stratoscale/swagger/testdata/auth

replace github.com/Stratoscale/swagger => /home/ronnie/wgo1/src/github.com/Stratoscale/swagger

require (
github.com/Stratoscale/swagger v1.0.27
github.com/go-openapi/errors v0.19.2
github.com/go-openapi/loads v0.19.3
github.com/go-openapi/runtime v0.19.6
github.com/go-openapi/spec v0.19.3
github.com/go-openapi/strfmt v0.19.3
github.com/go-openapi/swag v0.19.5
github.com/go-openapi/validate v0.19.3
github.com/jinzhu/gorm v1.9.11 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0
)
Loading