Skip to content

Commit e423e1a

Browse files
committed
feat: api npm sdk
1 parent 4a2c4ce commit e423e1a

File tree

8 files changed

+224
-6
lines changed

8 files changed

+224
-6
lines changed

.github/workflows/publish_npm.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: publish npm
2+
3+
on:
4+
push:
5+
tags:
6+
- v*.*.*
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
call-workflow-passing-data:
14+
uses: IceWhaleTech/github/.github/workflows/npm_release.yml@main
15+
secrets:
16+
NPM_TOKEN_PRIVATE: ${{ secrets.NPM_TOKEN_PRIVATE }}

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ __debug_bin
2929

3030

3131
dist/
32-
/github
32+
/github
33+
node_modules
34+
yarn.lock
35+
generate
36+
openapitools.json

api/gateway/openapi.yaml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
openapi: 3.0.3
2+
3+
info:
4+
title: CasaOS Gateway API
5+
version: v1
6+
description: |-
7+
<picture>
8+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_dark_night_800px.png">
9+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
10+
<img alt="CasaOS" src="https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png">
11+
</picture>
12+
13+
servers:
14+
- url: /v1/gateway
15+
16+
tags:
17+
- name: USB methods
18+
description: |-
19+
USB methods
20+
21+
security:
22+
- access_token: []
23+
24+
paths:
25+
/port:
26+
put:
27+
summary: Set gateway port
28+
description: |-
29+
Set gateway port
30+
operationId: setGatewayPort
31+
tags:
32+
- Gateway methods
33+
requestBody:
34+
content:
35+
application/json:
36+
schema:
37+
type: object
38+
properties:
39+
port:
40+
type: integer
41+
description: Gateway port
42+
example: 80
43+
responses:
44+
"200":
45+
$ref: "#/components/responses/ResponseOK"
46+
get:
47+
summary: Get gateway port
48+
description: |-
49+
Get gateway port
50+
operationId: getGatewayPort
51+
tags:
52+
- Gateway methods
53+
responses:
54+
"200":
55+
$ref: "#/components/responses/ResponseStringOK"
56+
"400":
57+
$ref: "#/components/responses/ResponseBadRequest"
58+
"500":
59+
$ref: "#/components/responses/ResponseInternalServerError"
60+
61+
components:
62+
securitySchemes:
63+
access_token:
64+
type: apiKey
65+
in: header
66+
name: Authorization
67+
68+
responses:
69+
ResponseOK:
70+
description: OK
71+
content:
72+
application/json:
73+
schema:
74+
$ref: "#/components/schemas/BaseResponse"
75+
ResponseStringOK:
76+
description: OK
77+
content:
78+
application/json:
79+
schema:
80+
$ref: "#/components/schemas/SuccessResponseString"
81+
ResponseBadRequest:
82+
description: Bad Request
83+
content:
84+
application/json:
85+
schema:
86+
readOnly: true
87+
allOf:
88+
- $ref: "#/components/schemas/BaseResponse"
89+
example:
90+
message: "Bad Request"
91+
ResponseInternalServerError:
92+
description: Internal Server Error
93+
content:
94+
application/json:
95+
schema:
96+
readOnly: true
97+
allOf:
98+
- $ref: "#/components/schemas/BaseResponse"
99+
example:
100+
message: "Internal Server Error"
101+
schemas:
102+
BaseResponse:
103+
properties:
104+
message:
105+
readOnly: true
106+
description: message returned by server side if there is any
107+
type: string
108+
example: ""
109+
110+
SuccessResponseString:
111+
allOf:
112+
- $ref: "#/components/schemas/BaseResponse"
113+
- properties:
114+
data:
115+
type: string
116+
description: When the interface returns success, this field is the specific success information

api/index.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>CasaOS | Developers</title>
6+
7+
<meta charset="utf-8" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
10+
11+
<style>
12+
body {
13+
margin: 0;
14+
padding: 0;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<redoc spec-url='gateway/openapi.yaml' expandResponses='all' jsonSampleExpandLevel='all'></redoc>
21+
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
22+
</body>
23+
24+
</html>

go.mod

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha9
77
github.com/labstack/echo/v4 v4.12.0
88
github.com/spf13/viper v1.18.2
9-
github.com/stretchr/testify v1.8.4
109
go.uber.org/fx v1.20.1
1110
gotest.tools v2.2.0+incompatible
1211
)
@@ -16,15 +15,13 @@ require (
1615
github.com/bytedance/sonic v1.9.1 // indirect
1716
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
1817
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
19-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2018
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
2119
github.com/gin-gonic/gin v1.9.1 // indirect
2220
github.com/godbus/dbus/v5 v5.1.0 // indirect
2321
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
2422
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
2523
github.com/labstack/gommon v0.4.2 // indirect
2624
github.com/mattn/go-colorable v0.1.13 // indirect
27-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2825
github.com/rogpeppe/go-internal v1.10.0 // indirect
2926
github.com/sagikazarmark/locafero v0.4.0 // indirect
3027
github.com/sagikazarmark/slog-shim v0.1.0 // indirect

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
1515
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1616
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1717
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
18-
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1918
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
2019
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
2120
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=
8483
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8584
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8685
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
87-
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8886
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
8987
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
9088
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=

package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@icewhale/casaos-gateway-openapi",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"clean": "rm -rf generate",
6+
"build": "rm -rf dist && tsc && yarn clean",
7+
"generate:local": "openapi-generator-cli generate -g typescript-axios -i ./api/gateway/openapi.yaml -o ./generate",
8+
"generate:npx": "npx @openapitools/openapi-generator-cli generate -g typescript-axios -i ./api/gateway/openapi.yaml -o ./generate",
9+
"generate:ts": "npx openapi-typescript-codegen --input ./api/gateway/openapi.yaml --output ./generate",
10+
"start": "yarn generate:local && yarn build"
11+
},
12+
"homepage": "https://github.com/IceWhaleTech/CasaOS-Gateway#readme",
13+
"description": "CasaOS Gateway Typescript+Axios SDK",
14+
"keywords": [
15+
"CasaOS",
16+
"SDK",
17+
"CasaOS Axios"
18+
],
19+
"main": "dist/index.js",
20+
"files": [
21+
"LICENSE",
22+
"README.md",
23+
"dist",
24+
"generate"
25+
],
26+
"dependencies": {
27+
"axios": "^1.1.0"
28+
},
29+
"devDependencies": {
30+
"all-contributors-cli": "^6.24.0",
31+
"@openapitools/openapi-generator-cli": "2.5.2",
32+
"@types/node": "^18.8.3",
33+
"openapi-typescript-codegen": "^0.23.0",
34+
"typescript": "^4.9.5"
35+
},
36+
"author": "casaos",
37+
"license": "Apache-2.0"
38+
}

tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"lib": [
5+
"es2017",
6+
"DOM"
7+
],
8+
"module": "commonjs",
9+
"target": "es6",
10+
"skipLibCheck": true,
11+
"sourceMap": false,
12+
"strict": true,
13+
"useUnknownInCatchVariables": false,
14+
"resolveJsonModule": true,
15+
"esModuleInterop": true,
16+
"outDir": "dist",
17+
"types": [
18+
"node"
19+
],
20+
},
21+
"exclude": [
22+
"node_modules"
23+
],
24+
"main": "generate/index"
25+
}

0 commit comments

Comments
 (0)