mirror of
https://github.com/openziti/zrok.git
synced 2024-12-25 08:09:09 +01:00
more swagger wiring
This commit is contained in:
parent
ad8000c369
commit
3c19094b32
@ -14,14 +14,6 @@ zrokDir=$(realpath "$scriptDir/..")
|
||||
|
||||
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"
|
||||
swagger generate server -f "$zrokSpec" -s rest_zrok_server -t "$zrokDir" -m "rest_model"
|
||||
|
||||
|
@ -2,8 +2,11 @@ package controller
|
||||
|
||||
import (
|
||||
"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/operations"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_zrok_server/operations/metadata"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -14,6 +17,10 @@ func Run(cfg *Config) error {
|
||||
}
|
||||
|
||||
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)
|
||||
defer func() { _ = server.Shutdown() }()
|
||||
server.Host = cfg.Host
|
||||
|
@ -47,8 +47,8 @@ func (a *Client) Get(params *GetParams, opts ...ClientOption) (*GetOK, error) {
|
||||
ID: "Get",
|
||||
Method: "GET",
|
||||
PathPattern: "/",
|
||||
ProducesMediaTypes: []string{"application/zrok.client.v1+json"},
|
||||
ConsumesMediaTypes: []string{"application/zrok.client.v1+json"},
|
||||
ProducesMediaTypes: []string{"application/zrok.v1+json"},
|
||||
ConsumesMediaTypes: []string{"application/zrok.v1+json"},
|
||||
Schemes: []string{"http"},
|
||||
Params: params,
|
||||
Reader: &GetReader{formats: a.formats},
|
||||
|
@ -4,6 +4,7 @@ package rest_zrok_server
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
@ -21,21 +22,10 @@ func configureFlags(api *operations.ZrokAPI) {
|
||||
}
|
||||
|
||||
func configureAPI(api *operations.ZrokAPI) http.Handler {
|
||||
// configure the api here
|
||||
api.ServeError = errors.ServeError
|
||||
|
||||
// Set your custom logger if needed. Default one is log.Printf
|
||||
// Expected interface func(string, ...interface{})
|
||||
//
|
||||
// Example:
|
||||
// api.Logger = log.Printf
|
||||
|
||||
api.Logger = logrus.Printf
|
||||
api.UseSwaggerUI()
|
||||
// To continue using redoc as your UI, uncomment the following line
|
||||
// api.UseRedoc()
|
||||
|
||||
api.JSONConsumer = runtime.JSONConsumer()
|
||||
|
||||
api.JSONProducer = runtime.JSONProducer()
|
||||
|
||||
if api.MetadataGetHandler == nil {
|
||||
|
@ -10,10 +10,10 @@
|
||||
// Version: 1.0.0
|
||||
//
|
||||
// Consumes:
|
||||
// - application/zrok.client.v1+json
|
||||
// - application/zrok.v1+json
|
||||
//
|
||||
// Produces:
|
||||
// - application/zrok.client.v1+json
|
||||
// - application/zrok.v1+json
|
||||
//
|
||||
// swagger:meta
|
||||
package rest_zrok_server
|
||||
|
@ -19,10 +19,10 @@ var (
|
||||
func init() {
|
||||
SwaggerJSON = json.RawMessage([]byte(`{
|
||||
"consumes": [
|
||||
"application/zrok.client.v1+json"
|
||||
"application/zrok.v1+json"
|
||||
],
|
||||
"produces": [
|
||||
"application/zrok.client.v1+json"
|
||||
"application/zrok.v1+json"
|
||||
],
|
||||
"schemes": [
|
||||
"http"
|
||||
@ -64,10 +64,10 @@ func init() {
|
||||
}`))
|
||||
FlatSwaggerJSON = json.RawMessage([]byte(`{
|
||||
"consumes": [
|
||||
"application/zrok.client.v1+json"
|
||||
"application/zrok.v1+json"
|
||||
],
|
||||
"produces": [
|
||||
"application/zrok.client.v1+json"
|
||||
"application/zrok.v1+json"
|
||||
],
|
||||
"schemes": [
|
||||
"http"
|
||||
|
@ -76,11 +76,11 @@ type ZrokAPI struct {
|
||||
BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
|
||||
|
||||
// JSONConsumer registers a consumer for the following mime types:
|
||||
// - application/zrok.client.v1+json
|
||||
// - application/zrok.v1+json
|
||||
JSONConsumer runtime.Consumer
|
||||
|
||||
// JSONProducer registers a producer for the following mime types:
|
||||
// - application/zrok.client.v1+json
|
||||
// - application/zrok.v1+json
|
||||
JSONProducer runtime.Producer
|
||||
|
||||
// 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))
|
||||
for _, mt := range mediaTypes {
|
||||
switch mt {
|
||||
case "application/zrok.client.v1+json":
|
||||
result["application/zrok.client.v1+json"] = o.JSONConsumer
|
||||
case "application/zrok.v1+json":
|
||||
result["application/zrok.v1+json"] = o.JSONConsumer
|
||||
}
|
||||
|
||||
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))
|
||||
for _, mt := range mediaTypes {
|
||||
switch mt {
|
||||
case "application/zrok.client.v1+json":
|
||||
result["application/zrok.client.v1+json"] = o.JSONProducer
|
||||
case "application/zrok.v1+json":
|
||||
result["application/zrok.v1+json"] = o.JSONProducer
|
||||
}
|
||||
|
||||
if p, ok := o.customProducers[mt]; ok {
|
||||
|
@ -20,9 +20,9 @@ definitions:
|
||||
type: string
|
||||
minLength: 1
|
||||
produces:
|
||||
- application/zrok.client.v1+json
|
||||
- application/zrok.v1+json
|
||||
consumes:
|
||||
- application/zrok.client.v1+json
|
||||
- application/zrok.v1+json
|
||||
schemes:
|
||||
- http
|
||||
swagger: "2.0"
|
||||
|
Loading…
Reference in New Issue
Block a user