Skip to content

Commit

Permalink
Swagger Typescript API (minio#1503)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Valdivia <[email protected]>
  • Loading branch information
dvaldivia authored Mar 15, 2023
1 parent bf48c08 commit 14d295b
Show file tree
Hide file tree
Showing 64 changed files with 3,475 additions and 4,458 deletions.
35 changes: 35 additions & 0 deletions .semgrepignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ignore git items
.gitignore
.git/
:include .gitignore

# Common large paths
node_modules/
portal-ui/node_modules/
build/
dist/
.idea/
vendor/
.env/
.venv/
.tox/
*.min.js

# Common test paths
test/
tests/
*_test.go

# Semgrep rules folder
.semgrep

# Semgrep-action log folder
.semgrep_logs/

# Ignore VsCode files
.vscode/
*.code-workspace
*~
.eslintcache

operatorApi.ts
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ clean-swagger:
swagger-operator:
@echo "Generating swagger server code from yaml"
@swagger generate server -A operator --main-package=operator --server-package=api --exclude-main -P models.Principal -f ./swagger.yml -r NOTICE
@echo "Generating typescript api"
@npx swagger-typescript-api -p ./swagger.yml -o ./web-app/src/api -n operatorApi.ts


swagger-gen: clean-swagger swagger-operator apply-gofmt
Expand Down
12 changes: 12 additions & 0 deletions api/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions api/tenant_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,18 @@ func getTenantDetailsResponse(session *models.Principal, params operator_api.Ten

info.Domains = &domains

var tiers []*models.TenantTierElement

for _, tier := range minTenant.Status.Usage.Tiers {
tierItem := &models.TenantTierElement{
Name: tier.Name,
Type: tier.Type,
Size: tier.TotalSize,
}

tiers = append(tiers, tierItem)
}
info.Tiers = tiers

return info, nil
}
57 changes: 57 additions & 0 deletions models/tenant.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,10 @@ definitions:
type: boolean
domains:
$ref: "#/definitions/domainsConfiguration"
tiers:
type: array
items:
$ref: "#/definitions/tenantTierElement"

tenantUsage:
type: object
Expand Down
26 changes: 10 additions & 16 deletions web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,23 @@
"@mui/styles": "^5.11.2",
"@mui/x-date-pickers": "^5.0.15",
"@reduxjs/toolkit": "^1.9.1",
"@uiw/react-textarea-code-editor": "^2.0.6",
"@uiw/react-textarea-code-editor": "^2.1.1",
"kbar": "^0.1.0-beta.39",
"local-storage-fallback": "^4.1.1",
"lodash": "^4.17.21",
"luxon": "^3.2.1",
"mds": "https://github.com/minio/mds.git#v0.2.5",
"minio": "^7.0.32",
"luxon": "^3.3.0",
"mds": "https://github.com/minio/mds.git#v0.3.0",
"react": "^18.1.0",
"react-component-export-image": "^1.0.6",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^18.1.0",
"react-dropzone": "^14.2.3",
"react-grid-layout": "^1.2.0",
"react-redux": "^8.0.5",
"react-router-dom": "6.7.0",
"react-virtualized": "^9.22.3",
"react-window": "^1.8.8",
"react-window-infinite-loader": "^1.0.7",
"recharts": "^2.2.0",
"superagent": "^8.0.8",
"tinycolor2": "^1.5.2",
"websocket": "^1.0.31"
"recharts": "^2.4.3",
"superagent": "^8.0.8"
},
"scripts": {
"start": "PORT=5050 react-scripts start",
Expand Down Expand Up @@ -61,23 +56,22 @@
},
"proxy": "http://localhost:9090/",
"devDependencies": {
"@types/luxon": "^3.2.0",
"@types/react-window": "^1.8.5",
"@types/react-window-infinite-loader": "^1.0.6",
"@types/recharts": "^1.8.24",
"@types/lodash": "^4.14.191",
"@types/minio": "^7.0.15",
"@types/luxon": "^3.2.0",
"@types/node": "18.11.18",
"@types/react": "18.0.27",
"@types/react-copy-to-clipboard": "^5.0.2",
"@types/react-dom": "18.0.10",
"@types/react-grid-layout": "^1.1.1",
"@types/react-redux": "^7.1.25",
"@types/react-virtualized": "^9.21.21",
"@types/react-window": "^1.8.5",
"@types/react-window-infinite-loader": "^1.0.6",
"@types/recharts": "^1.8.24",
"@types/superagent": "^4.1.16",
"@types/webpack-env": "^1.14.1",
"@types/websocket": "^1.0.0",
"prettier": "2.8.3",
"prettier": "2.8.4",
"react-scripts": "5.0.1",
"testcafe": "^2.3.0",
"typescript": "^4.4.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is part of MinIO Operator
// This file is part of MinIO Console Server
// Copyright (c) 2023 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -14,7 +14,22 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export interface ICallHomeResponse {
diagnosticsStatus?: boolean;
logsStatus?: boolean;
}
import { ErrorResponseHandler } from "../common/types";
import { Error } from "./operatorApi";

// errorToHandler translates a swagger error to a ErrorResponseHandler which
// is legacy, when all API calls are using the swagger API, we can remove this.
export const errorToHandler = (e: Error): ErrorResponseHandler => {
if (!e) {
return {
statusCode: 0,
errorMessage: "",
detailedError: "",
};
}
return {
statusCode: e.code,
errorMessage: e.message,
detailedError: e.detailedMessage,
};
};
38 changes: 38 additions & 0 deletions web-app/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Api, Error, FullRequestParams, HttpResponse } from "./operatorApi";

export let api = new Api();
const internalRequestFunc = api.request;
api.request = async <T = any, E = any>({
body,
secure,
path,
type,
query,
format,
baseUrl,
cancelToken,
...params
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
const internalResp = internalRequestFunc({
body,
secure,
path,
type,
query,
format,
baseUrl,
cancelToken,
...params,
});
return internalResp.then(CommonAPIValidation);
};

export function CommonAPIValidation<D, E>(
res: HttpResponse<D, E>
): HttpResponse<D, E> {
const err = res.error as Error;
if (err && err.code === 403 && err.message === "invalid session") {
document.location = "/";
}
return res;
}
Loading

0 comments on commit 14d295b

Please sign in to comment.