From e69e6122a81560a7c7130c43a8895b24575126f9 Mon Sep 17 00:00:00 2001 From: Ns2Kracy <89824014+Ns2Kracy@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:06:35 +0800 Subject: [PATCH] feat: api npm sdk (#51) --- .github/workflows/publish_npm.yaml | 16 ++++ .gitignore | 6 +- api/gateway/openapi.yaml | 116 +++++++++++++++++++++++++++++ api/index.html | 24 ++++++ go.mod | 3 - go.sum | 2 - package.json | 38 ++++++++++ tsconfig.json | 25 +++++++ 8 files changed, 224 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish_npm.yaml create mode 100644 api/gateway/openapi.yaml create mode 100644 api/index.html create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.github/workflows/publish_npm.yaml b/.github/workflows/publish_npm.yaml new file mode 100644 index 0000000..5a9ddf7 --- /dev/null +++ b/.github/workflows/publish_npm.yaml @@ -0,0 +1,16 @@ +name: publish npm + +on: + push: + tags: + - v*.*.* + workflow_dispatch: + +permissions: + contents: write + +jobs: + call-workflow-passing-data: + uses: IceWhaleTech/github/.github/workflows/npm_release.yml@main + secrets: + NPM_TOKEN_PRIVATE: ${{ secrets.NPM_TOKEN_PRIVATE }} diff --git a/.gitignore b/.gitignore index 34a9d41..55b7d9d 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ __debug_bin dist/ -/github \ No newline at end of file +/github +node_modules +yarn.lock +generate +openapitools.json diff --git a/api/gateway/openapi.yaml b/api/gateway/openapi.yaml new file mode 100644 index 0000000..5613abf --- /dev/null +++ b/api/gateway/openapi.yaml @@ -0,0 +1,116 @@ +openapi: 3.0.3 + +info: + title: CasaOS Gateway API + version: v1 + description: |- + + + + CasaOS + + +servers: + - url: /v1/gateway + +tags: + - name: USB methods + description: |- + USB methods + +security: + - access_token: [] + +paths: + /port: + put: + summary: Set gateway port + description: |- + Set gateway port + operationId: setGatewayPort + tags: + - Gateway methods + requestBody: + content: + application/json: + schema: + type: object + properties: + port: + type: integer + description: Gateway port + example: 80 + responses: + "200": + $ref: "#/components/responses/ResponseOK" + get: + summary: Get gateway port + description: |- + Get gateway port + operationId: getGatewayPort + tags: + - Gateway methods + responses: + "200": + $ref: "#/components/responses/ResponseStringOK" + "400": + $ref: "#/components/responses/ResponseBadRequest" + "500": + $ref: "#/components/responses/ResponseInternalServerError" + +components: + securitySchemes: + access_token: + type: apiKey + in: header + name: Authorization + + responses: + ResponseOK: + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/BaseResponse" + ResponseStringOK: + description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/SuccessResponseString" + ResponseBadRequest: + description: Bad Request + content: + application/json: + schema: + readOnly: true + allOf: + - $ref: "#/components/schemas/BaseResponse" + example: + message: "Bad Request" + ResponseInternalServerError: + description: Internal Server Error + content: + application/json: + schema: + readOnly: true + allOf: + - $ref: "#/components/schemas/BaseResponse" + example: + message: "Internal Server Error" + schemas: + BaseResponse: + properties: + message: + readOnly: true + description: message returned by server side if there is any + type: string + example: "" + + SuccessResponseString: + allOf: + - $ref: "#/components/schemas/BaseResponse" + - properties: + data: + type: string + description: When the interface returns success, this field is the specific success information diff --git a/api/index.html b/api/index.html new file mode 100644 index 0000000..0653efc --- /dev/null +++ b/api/index.html @@ -0,0 +1,24 @@ + + + + + CasaOS | Developers + + + + + + + + + + + + + + diff --git a/go.mod b/go.mod index f84667e..c7aced2 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha9 github.com/labstack/echo/v4 v4.12.0 github.com/spf13/viper v1.18.2 - github.com/stretchr/testify v1.8.4 go.uber.org/fx v1.20.1 gotest.tools v2.2.0+incompatible ) @@ -16,7 +15,6 @@ require ( github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-gonic/gin v1.9.1 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect @@ -24,7 +22,6 @@ require ( github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect diff --git a/go.sum b/go.sum index c7f14a0..9a91b7d 100644 --- a/go.sum +++ b/go.sum @@ -15,7 +15,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= -github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= @@ -84,7 +83,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= diff --git a/package.json b/package.json new file mode 100644 index 0000000..8ed8e0b --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "@icewhale/casaos-gateway-openapi", + "version": "0.0.1", + "scripts": { + "clean": "rm -rf generate", + "build": "rm -rf dist && tsc && yarn clean", + "generate:local": "openapi-generator-cli generate -g typescript-axios -i ./api/gateway/openapi.yaml -o ./generate", + "generate:npx": "npx @openapitools/openapi-generator-cli generate -g typescript-axios -i ./api/gateway/openapi.yaml -o ./generate", + "generate:ts": "npx openapi-typescript-codegen --input ./api/gateway/openapi.yaml --output ./generate", + "start": "yarn generate:local && yarn build" + }, + "homepage": "https://github.com/IceWhaleTech/CasaOS-Gateway#readme", + "description": "CasaOS Gateway Typescript+Axios SDK", + "keywords": [ + "CasaOS", + "SDK", + "CasaOS Axios" + ], + "main": "dist/index.js", + "files": [ + "LICENSE", + "README.md", + "dist", + "generate" + ], + "dependencies": { + "axios": "^1.1.0" + }, + "devDependencies": { + "all-contributors-cli": "^6.24.0", + "@openapitools/openapi-generator-cli": "2.5.2", + "@types/node": "^18.8.3", + "openapi-typescript-codegen": "^0.23.0", + "typescript": "^4.9.5" + }, + "author": "casaos", + "license": "Apache-2.0" +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d78c4f0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "declaration": true, + "lib": [ + "es2017", + "DOM" + ], + "module": "commonjs", + "target": "es6", + "skipLibCheck": true, + "sourceMap": false, + "strict": true, + "useUnknownInCatchVariables": false, + "resolveJsonModule": true, + "esModuleInterop": true, + "outDir": "dist", + "types": [ + "node" + ], + }, + "exclude": [ + "node_modules" + ], + "main": "generate/index" +}