Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing Swagger File through Executor and providing Swagger UI through endpoint #1730

Merged
merged 11 commits into from
Apr 24, 2020
3 changes: 2 additions & 1 deletion executor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ executor
./bin/
cover.out
executor.tar

openapi/

2 changes: 2 additions & 0 deletions executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o executor
FROM gcr.io/distroless/static:latest
WORKDIR /
COPY --from=builder /workspace/executor .
# Copy openapi spec and swagger UI files
COPY openapi/ /openapi/
COPY licenses/license.txt .
ENTRYPOINT ["/executor"]
9 changes: 7 additions & 2 deletions executor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ add_protos:
test: fmt vet
go test ./api/... ./predictor/... ./k8s/... -coverprofile cover.out

copy-openapi-resources:
mkdir -p openapi/
cp ../openapi/swagger-ui/* openapi/
cp ../openapi/engine.oas3.json openapi/seldon.json

# Build the docker image
docker-build: test
docker-build: test copy-openapi-resources
docker build -f Dockerfile -t ${IMG} .

# Build the docker image for Redhat
docker-build-redhat: test
docker-build-redhat: test copy-openapi-resources
docker build . -f Dockerfile.redhat -t ${IMG_REDHAT}

# Push the docker image
Expand Down
2 changes: 2 additions & 0 deletions executor/api/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,13 @@ func (r *SeldonRestApi) Initialise() {
api01.Handle("/predictions", r.wrapMetrics(metric.PredictionHttpServiceName, r.predictions))
r.Router.NewRoute().Path("/api/v0.1/status/{" + ModelHttpPathVariable + "}").Methods("GET").HandlerFunc(r.wrapMetrics(metric.StatusHttpServiceName, r.status))
r.Router.NewRoute().Path("/api/v0.1/metadata/{" + ModelHttpPathVariable + "}").Methods("GET").HandlerFunc(r.wrapMetrics(metric.StatusHttpServiceName, r.metadata))
r.Router.NewRoute().PathPrefix("/api/v0.1/doc/").Handler(http.StripPrefix("/api/v0.1/doc/", http.FileServer(http.Dir("./openapi/"))))
//v1.0 API
api1 := r.Router.PathPrefix("/api/v1.0").Methods("POST").Subrouter()
api1.Handle("/predictions", r.wrapMetrics(metric.PredictionServiceMetricName, r.predictions))
r.Router.NewRoute().Path("/api/v1.0/status/{" + ModelHttpPathVariable + "}").Methods("GET").HandlerFunc(r.wrapMetrics(metric.StatusHttpServiceName, r.status))
r.Router.NewRoute().Path("/api/v1.0/metadata/{" + ModelHttpPathVariable + "}").Methods("GET").HandlerFunc(r.wrapMetrics(metric.StatusHttpServiceName, r.metadata))
r.Router.NewRoute().PathPrefix("/api/v1.0/doc/").Handler(http.StripPrefix("/api/v1.0/doc/", http.FileServer(http.Dir("./openapi/"))))

case api.ProtocolTensorflow:
r.Router.NewRoute().Path("/v1/models/{" + ModelHttpPathVariable + "}/:predict").Methods("POST").HandlerFunc(r.wrapMetrics(metric.PredictionHttpServiceName, r.predictions))
Expand Down
58 changes: 58 additions & 0 deletions openapi/swagger-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.24.2/swagger-ui.css" >
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}

*,
*:before,
*:after
{
box-sizing: inherit;
}

body
{
margin:0;
background: #fafafa;
}
</style>
</head>

<body>
<div id="swagger-ui"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.24.2/swagger-ui-bundle.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/3.24.2/swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./seldon.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region

window.ui = ui
}
</script>
</body>
</html>
84 changes: 84 additions & 0 deletions openapi/swagger-ui/index_bundled.html

Large diffs are not rendered by default.