more swagger wiring

This commit is contained in:
Michael Quigley 2022-07-22 11:45:37 -04:00
parent ad8000c369
commit 3c19094b32
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
8 changed files with 25 additions and 36 deletions

View File

@ -14,14 +14,6 @@ zrokDir=$(realpath "$scriptDir/..")
zrokSpec=$(realpath "$zrokDir/specs/zrok.yml") zrokSpec=$(realpath "$zrokDir/specs/zrok.yml")
zrokServerPath=$(realpath "$zrokDir/rest_server_zrok")
echo "...removing any existing server from $zrokServerPath"
rm -rf "$zrokServerPath"
zrokClientPath=$(realpath "$zrokDir/rest_client_zrok")
echo "...removing any existing client from $zrokClientPath"
rm -rf "$zrokClientPath"
echo "...generating zrok server" echo "...generating zrok server"
swagger generate server -f "$zrokSpec" -s rest_zrok_server -t "$zrokDir" -m "rest_model" swagger generate server -f "$zrokSpec" -s rest_zrok_server -t "$zrokDir" -m "rest_model"

View File

@ -2,8 +2,11 @@ package controller
import ( import (
"github.com/go-openapi/loads" "github.com/go-openapi/loads"
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/rest_model"
"github.com/openziti-test-kitchen/zrok/rest_zrok_server" "github.com/openziti-test-kitchen/zrok/rest_zrok_server"
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations" "github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations"
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -14,6 +17,10 @@ func Run(cfg *Config) error {
} }
api := operations.NewZrokAPI(swaggerSpec) api := operations.NewZrokAPI(swaggerSpec)
api.MetadataGetHandler = metadata.GetHandlerFunc(func(params metadata.GetParams) middleware.Responder {
return metadata.NewGetOK().WithPayload(&rest_model.Version{Version: "oh, wow!"})
})
server := rest_zrok_server.NewServer(api) server := rest_zrok_server.NewServer(api)
defer func() { _ = server.Shutdown() }() defer func() { _ = server.Shutdown() }()
server.Host = cfg.Host server.Host = cfg.Host

View File

@ -47,8 +47,8 @@ func (a *Client) Get(params *GetParams, opts ...ClientOption) (*GetOK, error) {
ID: "Get", ID: "Get",
Method: "GET", Method: "GET",
PathPattern: "/", PathPattern: "/",
ProducesMediaTypes: []string{"application/zrok.client.v1+json"}, ProducesMediaTypes: []string{"application/zrok.v1+json"},
ConsumesMediaTypes: []string{"application/zrok.client.v1+json"}, ConsumesMediaTypes: []string{"application/zrok.v1+json"},
Schemes: []string{"http"}, Schemes: []string{"http"},
Params: params, Params: params,
Reader: &GetReader{formats: a.formats}, Reader: &GetReader{formats: a.formats},

View File

@ -4,6 +4,7 @@ package rest_zrok_server
import ( import (
"crypto/tls" "crypto/tls"
"github.com/sirupsen/logrus"
"net/http" "net/http"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
@ -21,21 +22,10 @@ func configureFlags(api *operations.ZrokAPI) {
} }
func configureAPI(api *operations.ZrokAPI) http.Handler { func configureAPI(api *operations.ZrokAPI) http.Handler {
// configure the api here
api.ServeError = errors.ServeError api.ServeError = errors.ServeError
api.Logger = logrus.Printf
// Set your custom logger if needed. Default one is log.Printf
// Expected interface func(string, ...interface{})
//
// Example:
// api.Logger = log.Printf
api.UseSwaggerUI() api.UseSwaggerUI()
// To continue using redoc as your UI, uncomment the following line
// api.UseRedoc()
api.JSONConsumer = runtime.JSONConsumer() api.JSONConsumer = runtime.JSONConsumer()
api.JSONProducer = runtime.JSONProducer() api.JSONProducer = runtime.JSONProducer()
if api.MetadataGetHandler == nil { if api.MetadataGetHandler == nil {

View File

@ -10,10 +10,10 @@
// Version: 1.0.0 // Version: 1.0.0
// //
// Consumes: // Consumes:
// - application/zrok.client.v1+json // - application/zrok.v1+json
// //
// Produces: // Produces:
// - application/zrok.client.v1+json // - application/zrok.v1+json
// //
// swagger:meta // swagger:meta
package rest_zrok_server package rest_zrok_server

View File

@ -19,10 +19,10 @@ var (
func init() { func init() {
SwaggerJSON = json.RawMessage([]byte(`{ SwaggerJSON = json.RawMessage([]byte(`{
"consumes": [ "consumes": [
"application/zrok.client.v1+json" "application/zrok.v1+json"
], ],
"produces": [ "produces": [
"application/zrok.client.v1+json" "application/zrok.v1+json"
], ],
"schemes": [ "schemes": [
"http" "http"
@ -64,10 +64,10 @@ func init() {
}`)) }`))
FlatSwaggerJSON = json.RawMessage([]byte(`{ FlatSwaggerJSON = json.RawMessage([]byte(`{
"consumes": [ "consumes": [
"application/zrok.client.v1+json" "application/zrok.v1+json"
], ],
"produces": [ "produces": [
"application/zrok.client.v1+json" "application/zrok.v1+json"
], ],
"schemes": [ "schemes": [
"http" "http"

View File

@ -76,11 +76,11 @@ type ZrokAPI struct {
BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
// JSONConsumer registers a consumer for the following mime types: // JSONConsumer registers a consumer for the following mime types:
// - application/zrok.client.v1+json // - application/zrok.v1+json
JSONConsumer runtime.Consumer JSONConsumer runtime.Consumer
// JSONProducer registers a producer for the following mime types: // JSONProducer registers a producer for the following mime types:
// - application/zrok.client.v1+json // - application/zrok.v1+json
JSONProducer runtime.Producer JSONProducer runtime.Producer
// MetadataGetHandler sets the operation handler for the get operation // MetadataGetHandler sets the operation handler for the get operation
@ -194,8 +194,8 @@ func (o *ZrokAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer
result := make(map[string]runtime.Consumer, len(mediaTypes)) result := make(map[string]runtime.Consumer, len(mediaTypes))
for _, mt := range mediaTypes { for _, mt := range mediaTypes {
switch mt { switch mt {
case "application/zrok.client.v1+json": case "application/zrok.v1+json":
result["application/zrok.client.v1+json"] = o.JSONConsumer result["application/zrok.v1+json"] = o.JSONConsumer
} }
if c, ok := o.customConsumers[mt]; ok { if c, ok := o.customConsumers[mt]; ok {
@ -211,8 +211,8 @@ func (o *ZrokAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer
result := make(map[string]runtime.Producer, len(mediaTypes)) result := make(map[string]runtime.Producer, len(mediaTypes))
for _, mt := range mediaTypes { for _, mt := range mediaTypes {
switch mt { switch mt {
case "application/zrok.client.v1+json": case "application/zrok.v1+json":
result["application/zrok.client.v1+json"] = o.JSONProducer result["application/zrok.v1+json"] = o.JSONProducer
} }
if p, ok := o.customProducers[mt]; ok { if p, ok := o.customProducers[mt]; ok {

View File

@ -20,9 +20,9 @@ definitions:
type: string type: string
minLength: 1 minLength: 1
produces: produces:
- application/zrok.client.v1+json - application/zrok.v1+json
consumes: consumes:
- application/zrok.client.v1+json - application/zrok.v1+json
schemes: schemes:
- http - http
swagger: "2.0" swagger: "2.0"