Skip to content

Commit

Permalink
Merge branch 'dev/7.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Oct 24, 2024
2 parents f1a085a + da0081e commit ffcb885
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 361 deletions.
28 changes: 28 additions & 0 deletions apps/app/bin/swagger-jsdoc/definition-apiv1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const pkg = require('../../package.json');

module.exports = {
openapi: '3.0.1',
info: {
title: 'GROWI REST API v1',
version: pkg.version,
},
servers: [
{
url: 'https://demo.growi.org/_api',
},
],
security: [
{
api_key: [],
},
],
components: {
securitySchemes: {
api_key: {
type: 'apiKey',
name: 'access_token',
in: 'query',
},
},
},
};
28 changes: 28 additions & 0 deletions apps/app/bin/swagger-jsdoc/definition-apiv3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const pkg = require('../../package.json');

module.exports = {
openapi: '3.0.1',
info: {
title: 'GROWI REST API v3',
version: pkg.version,
},
servers: [
{
url: 'https://demo.growi.org/_api/v3',
},
],
security: [
{
api_key: [],
},
],
components: {
securitySchemes: {
api_key: {
type: 'apiKey',
name: 'access_token',
in: 'query',
},
},
},
};
15 changes: 15 additions & 0 deletions apps/app/bin/swagger-jsdoc/generate-spec-apiv1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# USAGE:
# cd apps/app && sh bin/swagger-jsdoc/generate-spec-apiv1.sh
# APP_PATH=/path/to/apps/app sh bin/swagger-jsdoc/generate-spec-apiv1.sh
# APP_PATH=/path/to/apps/app OUT=/path/to/output sh bin/swagger-jsdoc/generate-spec-apiv1.sh

APP_PATH=${APP_PATH:-"."}

OUT=${OUT:-"${APP_PATH}/tmp/openapi-spec-apiv1.json"}

swagger-jsdoc \
-o "${OUT}" \
-d "${APP_PATH}/bin/swagger-jsdoc/definition-apiv1.js" \
"${APP_PATH}/src/server/routes/*/*.{js,ts}" \
"${APP_PATH}/src/server/routes/attachment/**/*.{js,ts}" \
"${APP_PATH}/src/server/models/openapi/**/*.{js,ts}"
14 changes: 14 additions & 0 deletions apps/app/bin/swagger-jsdoc/generate-spec-apiv3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# USAGE:
# cd apps/app && sh bin/swagger-jsdoc/generate-spec-apiv3.sh
# APP_PATH=/path/to/apps/app sh bin/swagger-jsdoc/generate-spec-apiv3.sh
# APP_PATH=/path/to/apps/app OUT=/path/to/output sh bin/swagger-jsdoc/generate-spec-apiv3.sh

APP_PATH=${APP_PATH:-"."}

OUT=${OUT:-"${APP_PATH}/tmp/openapi-spec-apiv3.json"}

swagger-jsdoc \
-o "${OUT}" \
-d "${APP_PATH}/bin/swagger-jsdoc/definition-apiv3.js" \
"${APP_PATH}/src/server/routes/apiv3/**/*.{js,ts}" \
"${APP_PATH}/src/server/models/openapi/**/*.{js,ts}"
37 changes: 0 additions & 37 deletions apps/app/config/swagger-definition.js

This file was deleted.

13 changes: 7 additions & 6 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"lint:typecheck": "npx -y tspc",
"lint:eslint": "yarn eslint --quiet \"**/*.{js,jsx,ts,tsx}\"",
"lint:styles": "stylelint \"src/**/*.scss\"",
"lint:swagger2openapi": "node node_modules/.bin/oas-validate tmp/swagger.json",
"lint:swagger2openapi:apiv3": "node node_modules/.bin/oas-validate tmp/openapi-spec-apiv3.json",
"lint:swagger2openapi:apiv1": "node node_modules/.bin/oas-validate tmp/openapi-spec-apiv1.json",
"lint": "run-p lint:*",
"prelint:swagger2openapi": "yarn openapi:v3",
"prelint:swagger2openapi:apiv3": "yarn swagger2openapi:apiv3",
"prelint:swagger2openapi:apiv1": "yarn swagger2openapi:apiv1",
"test": "run-p test:*",
"test:jest": "cross-env NODE_ENV=test TS_NODE_PROJECT=test/integration/tsconfig.json jest",
"test:vitest": "vitest run --coverage",
Expand All @@ -42,9 +44,8 @@
"//// misc": "",
"console": "yarn repl",
"repl": "yarn cross-env NODE_ENV=development yarn ts-node src/server/repl.ts",
"swagger-jsdoc": "swagger-jsdoc -o tmp/swagger.json -d config/swagger-definition.js",
"openapi:v3": "yarn cross-env API_VERSION=3 yarn swagger-jsdoc -- \"src/server/routes/apiv3/**/*.js\" \"src/server/models/**/*.js\"",
"openapi:v1": "yarn cross-env API_VERSION=1 yarn swagger-jsdoc -- \"src/server/*/*.js\" \"src/server/models/**/*.js\"",
"swagger2openapi:apiv3": "sh bin/swagger-jsdoc/generate-spec-apiv3.sh",
"swagger2openapi:apiv1": "sh bin/swagger-jsdoc/generate-spec-apiv1.sh",
"ts-node": "node -r ts-node/register/transpile-only -r tsconfig-paths/register -r dotenv-flow/config",
"version": "yarn version --no-git-tag-version --non-interactive --preid=RC"
},
Expand Down Expand Up @@ -196,7 +197,7 @@
"stream-to-promise": "^3.0.0",
"string-width": "=4.2.2",
"superjson": "^1.9.1",
"swagger-jsdoc": "^6.1.0",
"swagger-jsdoc": "^6.2.8",
"swr": "^2.2.2",
"throttle-debounce": "^5.0.0",
"uglifycss": "^0.0.29",
Expand Down
File renamed without changes.
79 changes: 79 additions & 0 deletions apps/app/src/server/models/openapi/page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @swagger
*
* components:
* schemas:
* Page:
* description: Page
* type: object
* properties:
* _id:
* type: string
* description: page ID
* example: 5e07345972560e001761fa63
* __v:
* type: number
* description: DB record version
* example: 0
* commentCount:
* type: number
* description: count of comments
* example: 3
* createdAt:
* type: string
* description: date created at
* example: 2010-01-01T00:00:00.000Z
* creator:
* $ref: '#/components/schemas/User'
* extended:
* type: object
* description: extend data
* example: {}
* grant:
* type: number
* description: grant
* example: 1
* grantedUsers:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: ["5ae5fccfc5577b0004dbd8ab"]
* lastUpdateUser:
* $ref: '#/components/schemas/User'
* liker:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: []
* path:
* type: string
* description: page path
* example: /
* revision:
* type: string
* description: page revision
* seenUsers:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: ["5ae5fccfc5577b0004dbd8ab"]
* status:
* type: string
* description: status
* enum:
* - 'wip'
* - 'published'
* - 'deleted'
* - 'deprecated'
* example: published
* updatedAt:
* type: string
* description: date updated at
* example: 2010-01-01T00:00:00.000Z
*/
39 changes: 39 additions & 0 deletions apps/app/src/server/models/openapi/revision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @swagger
*
* components:
* schemas:
* Revision:
* description: Revision
* type: object
* properties:
* _id:
* type: string
* description: revision ID
* example: 5e0734e472560e001761fa68
* __v:
* type: number
* description: DB record version
* example: 0
* author:
* $ref: '#/components/schemas/User/properties/_id'
* body:
* type: string
* description: content body
* example: |
* # test
*
* test
* format:
* type: string
* description: format
* example: markdown
* path:
* type: string
* description: path
* example: /user/alice/test
* createdAt:
* type: string
* description: date created at
* example: 2010-01-01T00:00:00.000Z
*/
79 changes: 3 additions & 76 deletions apps/app/src/server/routes/apiv3/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,85 +52,12 @@ const router = express.Router();
* name: Page
*/


/**
* @swagger
*
* components:
* schemas:
* Page:
* description: Page
* type: object
* properties:
* _id:
* type: string
* description: page ID
* example: 5e07345972560e001761fa63
* __v:
* type: number
* description: DB record version
* example: 0
* commentCount:
* type: number
* description: count of comments
* example: 3
* createdAt:
* type: string
* description: date created at
* example: 2010-01-01T00:00:00.000Z
* creator:
* $ref: '#/components/schemas/User'
* extended:
* type: object
* description: extend data
* example: {}
* grant:
* type: number
* description: grant
* example: 1
* grantedUsers:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: ["5ae5fccfc5577b0004dbd8ab"]
* lastUpdateUser:
* $ref: '#/components/schemas/User'
* liker:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: []
* path:
* type: string
* description: page path
* example: /
* revision:
* type: string
* description: page revision
* seenUsers:
* type: array
* description: granted users
* items:
* type: string
* description: user ID
* example: ["5ae5fccfc5577b0004dbd8ab"]
* status:
* type: string
* description: status
* enum:
* - 'wip'
* - 'published'
* - 'deleted'
* - 'deprecated'
* example: published
* updatedAt:
* type: string
* description: date updated at
* example: 2010-01-01T00:00:00.000Z
*
* components:
* schemas:
* LikeParams:
* description: LikeParams
* type: object
Expand Down
Loading

0 comments on commit ffcb885

Please sign in to comment.