-
Notifications
You must be signed in to change notification settings - Fork 5
chore(api): generated docs #2197
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SHELL := /bin/bash | ||
|
||
.PHONY: swagger | ||
swagger: | ||
swag fmt -g api.go | ||
swag init -g api.go | ||
|
||
.PHONY: swag | ||
swag: | ||
which swag || (go install github.com/swaggo/swag/cmd/swag@latest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,34 @@ import ( | |
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/replicatedhq/embedded-cluster/api/controllers/auth" | ||
"github.com/replicatedhq/embedded-cluster/api/controllers/console" | ||
"github.com/replicatedhq/embedded-cluster/api/controllers/install" | ||
_ "github.com/replicatedhq/embedded-cluster/api/docs" | ||
"github.com/replicatedhq/embedded-cluster/api/types" | ||
"github.com/sirupsen/logrus" | ||
httpSwagger "github.com/swaggo/http-swagger/v2" | ||
) | ||
|
||
// @title Embedded Cluster API | ||
// @version 0.1 | ||
// @description This is the API for the Embedded Cluster project. | ||
// @termsOfService http://swagger.io/terms/ | ||
|
||
// @contact.name API Support | ||
// @contact.url https://github.com/replicatedhq/embedded-cluster/issues | ||
// @contact.email [email protected] | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
|
||
// @host localhost:30080 | ||
// @BasePath /api | ||
|
||
// @securityDefinitions.basic BasicAuth | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is incorrect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we remove it then? |
||
|
||
// @externalDocs.description OpenAPI | ||
// @externalDocs.url https://swagger.io/resources/open-api/ | ||
type API struct { | ||
authController auth.Controller | ||
consoleController console.Controller | ||
|
@@ -94,11 +114,12 @@ func New(password string, opts ...APIOption) (*API, error) { | |
|
||
func (a *API) RegisterRoutes(router *mux.Router) { | ||
router.HandleFunc("/health", a.getHealth).Methods("GET") | ||
router.PathPrefix("/swagger/").Handler(httpSwagger.WrapHandler) | ||
|
||
router.HandleFunc("/auth/login", a.postAuthLogin).Methods("POST") | ||
router.HandleFunc("/branding", a.getBranding).Methods("GET") | ||
|
||
authenticatedRouter := router.PathPrefix("").Subrouter() | ||
authenticatedRouter := router.PathPrefix("/").Subrouter() | ||
authenticatedRouter.Use(a.authMiddleware) | ||
|
||
installRouter := authenticatedRouter.PathPrefix("/install").Subrouter() | ||
|
@@ -111,7 +132,7 @@ func (a *API) RegisterRoutes(router *mux.Router) { | |
consoleRouter.HandleFunc("/available-network-interfaces", a.getListAvailableNetworkInterfaces).Methods("GET") | ||
} | ||
|
||
func (a *API) JSON(w http.ResponseWriter, r *http.Request, code int, payload any) { | ||
func (a *API) json(w http.ResponseWriter, r *http.Request, code int, payload any) { | ||
response, err := json.Marshal(payload) | ||
if err != nil { | ||
a.logError(r, err, "failed to encode response") | ||
|
@@ -124,7 +145,7 @@ func (a *API) JSON(w http.ResponseWriter, r *http.Request, code int, payload any | |
w.Write(response) | ||
} | ||
|
||
func (a *API) JSONError(w http.ResponseWriter, r *http.Request, err error) { | ||
func (a *API) jsonError(w http.ResponseWriter, r *http.Request, err error) { | ||
var apiErr *types.APIError | ||
if !errors.As(err, &apiErr) { | ||
apiErr = types.NewInternalServerError(err) | ||
|
@@ -133,7 +154,7 @@ func (a *API) JSONError(w http.ResponseWriter, r *http.Request, err error) { | |
response, err := json.Marshal(apiErr) | ||
if err != nil { | ||
a.logError(r, err, "failed to encode response") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Package docs Code generated by swaggo/swag. DO NOT EDIT | ||
package docs | ||
|
||
import "github.com/swaggo/swag" | ||
|
||
const docTemplate = `{ | ||
"schemes": {{ marshal .Schemes }}, | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "{{escape .Description}}", | ||
"title": "{{.Title}}", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": { | ||
"name": "API Support", | ||
"url": "https://github.com/replicatedhq/embedded-cluster/issues", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": { | ||
"/health": { | ||
"get": { | ||
"description": "get the health of the API", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"health" | ||
], | ||
"summary": "Get the health of the API", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/types.Health" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"types.Health": { | ||
"type": "object", | ||
"properties": { | ||
"status": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BasicAuth": { | ||
"type": "basic" | ||
} | ||
}, | ||
"externalDocs": { | ||
"description": "OpenAPI", | ||
"url": "https://swagger.io/resources/open-api/" | ||
} | ||
}` | ||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it | ||
var SwaggerInfo = &swag.Spec{ | ||
Version: "0.1", | ||
Host: "localhost:30080", | ||
BasePath: "/api", | ||
Schemes: []string{}, | ||
Title: "Embedded Cluster API", | ||
Description: "This is the API for the Embedded Cluster project.", | ||
InfoInstanceName: "swagger", | ||
SwaggerTemplate: docTemplate, | ||
LeftDelim: "{{", | ||
RightDelim: "}}", | ||
} | ||
|
||
func init() { | ||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is the API for the Embedded Cluster project.", | ||
"title": "Embedded Cluster API", | ||
"termsOfService": "http://swagger.io/terms/", | ||
"contact": { | ||
"name": "API Support", | ||
"url": "https://github.com/replicatedhq/embedded-cluster/issues", | ||
"email": "[email protected]" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "0.1" | ||
}, | ||
"host": "localhost:30080", | ||
"basePath": "/api", | ||
"paths": { | ||
"/health": { | ||
"get": { | ||
"description": "get the health of the API", | ||
"consumes": [ | ||
"application/json" | ||
], | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"health" | ||
], | ||
"summary": "Get the health of the API", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/types.Health" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"types.Health": { | ||
"type": "object", | ||
"properties": { | ||
"status": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"securityDefinitions": { | ||
"BasicAuth": { | ||
"type": "basic" | ||
} | ||
}, | ||
"externalDocs": { | ||
"description": "OpenAPI", | ||
"url": "https://swagger.io/resources/open-api/" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be dynamic