Skip to content

Commit

Permalink
small doc update
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Mar 1, 2015
1 parent 2a4880a commit bf15c1b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 49 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ To generate a server for a swagger spec document:

swagger generate all -f ./swagger.json -A [application-name] [--principal [principal-name]] --include-main --include-ui

There are several other sub commands available for the generate command

Sub command | Description
------------|----------------------------------------------------------------------------------
operation | generates one or more models specified in the swagger definition
model | generates model files for one or more models specified in the swagger definition
support | generates the api builder and the main method
server | generates an entire server application

Design
------
Expand Down
2 changes: 1 addition & 1 deletion cmd/swagger/commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type Generate struct {
Model *generate.Model `command:"model"`
Operation *generate.Operation `command:"operation"`
Support *generate.Support `command:"support"`
All *generate.All `command:"all"`
Server *generate.All `command:"server"`
}
4 changes: 2 additions & 2 deletions design.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The goals are to be as unintrusive as possible. The swagger spec is the source o
The reference framework will make use of a swagger API that is based on the denco router.

The general idea is that it is a middleware which you provide with the swagger spec.
This document can be either JSON or YAML as both are required.
This document can be either JSON or YAML as both are supported.

In addition to the middleware there are some generator commands that will use the swagger spec to generate models, parameter models, operation interfaces and a mux.

Expand All @@ -17,7 +17,7 @@ The middleware performs validation, data binding and security as defined in the
It also uses the API to match request paths to functions of `func(paramsObject) (responseModel, error)`
The middleware does this by building up a series of rules for each operation. When the spec.Document is first created it analyzes the swagger spec and builds a routing, validation and binding rules for each operation in the specification. Before doing that it expands all the $ref fields in the swagger document. After expanding all the rules it validates the registrations made in the API and will take an configurable action for missing operations.

When a request comes in that doesn't match the /api-docs endpoint it will look for it in the swagger spec routes. It doesn't need to create a plan for anything anymore it did that at startup time but it will then execute the plan with the request and route params.
When a request comes in that doesn't match the /swagger.json endpoint it will look for it in the swagger spec routes. It doesn't need to create a plan for anything anymore it did that at startup time but it will then execute the plan with the request and route params.
These are provided in the API. There is a tool to generate a statically typed API, based on operation names and operation interfaces

### The API
Expand Down
25 changes: 20 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,35 @@ And it's 100% open source software.
Install:
go get -u github.com/casualjim/go-swagger/cmd/swagger
go get -u github.com/casualjim/go-swagger/cmd/swagger
The implementation also provides a number of command line tools to help working with swagger.
Currently there is a spec validator tool:
There is a spec validator tool:
swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json
swagger validate https://raw.githubusercontent.com/swagger-api/swagger-spec/master/examples/v2.0/json/petstore-expanded.json
You can also serve a swagger document with the swagger UI
swagger ui ./swagger.json
swagger ui ./swagger.json
Generating code
You're free to add files to the directories the generated code lands in, but the files generated by the generator itself
will be regenerated on following generation runs so any changes to those files will be lost.
However extra files you create won't be lost so they are safe to use for customizing the application to your needs.
To generate a server for a swagger spec document:
swagger generate all -f ./swagger.json -A [application-name] [--principal [principal-name]] --include-main --include-ui
swagger generate all -f ./swagger.json -A [application-name] [--principal [principal-name]] --include-main --include-ui
There are several other sub commands available for the generate command
operation: generates one or more models specified in the swagger definition
model: generates model files for one or more models specified in the swagger definition
support: generates the api builder and the main method
server: generates an entire server application
*/
package swagger
41 changes: 0 additions & 41 deletions middleware/complete.go

This file was deleted.

49 changes: 49 additions & 0 deletions middleware/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package middleware

/*
import (
"net/http"
"github.com/casualjim/go-swagger/errors"
"github.com/gorilla/context"
)
func newCompleteMiddleware(ctx *Context) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
defer context.Clear(r)
// use context to lookup routes
if matched, ok := ctx.RouteInfo(r); ok {
if len(matched.Authenticators) > 0 {
if _, err := ctx.Authorize(r, matched); err != nil {
ctx.Respond(rw, r, matched.Produces, matched, err)
return
}
}
bound, validation := ctx.BindAndValidate(r, matched)
if validation != nil {
ctx.Respond(rw, r, matched.Produces, matched, validation)
return
}
result, err := matched.Handler.Handle(bound)
if err != nil {
ctx.Respond(rw, r, matched.Produces, matched, err)
return
}
ctx.Respond(rw, r, matched.Produces, matched, result)
return
}
// Not found, check if it exists in the other methods first
if others := ctx.AllowedMethods(r); len(others) > 0 {
ctx.Respond(rw, r, ctx.spec.RequiredProduces(), nil, errors.MethodNotAllowed(r.Method, others))
return
}
ctx.Respond(rw, r, ctx.spec.RequiredProduces(), nil, errors.NotFound("path %s was not found", r.URL.Path))
})
}
*/

0 comments on commit bf15c1b

Please sign in to comment.