Skip to content

Commit

Permalink
Merge pull request #4863 from logto-io/gao-swagger-org-apis
Browse files Browse the repository at this point in the history
refactor(core): add swagger data for org apis
  • Loading branch information
gao-sun authored Nov 14, 2023
2 parents 8730570 + 1fb8369 commit 5de7772
Show file tree
Hide file tree
Showing 9 changed files with 732 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV PUPPETEER_SKIP_DOWNLOAD=true
### Install toolchain ###
RUN npm add --location=global pnpm@^8.0.0
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#node-gyp-alpine
RUN apk add --no-cache python3 make g++
RUN apk add --no-cache python3 make g++ rsync

COPY . .

Expand Down
11 changes: 5 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
},
"scripts": {
"precommit": "lint-staged",
"copyfiles": "copyfiles -u 1 src/routes/**/*.openapi.json build/",
"build": "rm -rf build/ && tsc -p tsconfig.build.json && pnpm run copyfiles",
"build:test": "rm -rf build/ && tsc -p tsconfig.test.json --sourcemap && pnpm run copyfiles",
"copy:apidocs": "rsync -a -m --include '*/' --include '*.openapi.json' --exclude '*' src/routes/ build/routes/",
"build": "rm -rf build/ && tsc -p tsconfig.build.json && pnpm run copy:apidocs",
"build:test": "rm -rf build/ && tsc -p tsconfig.test.json --sourcemap && pnpm run copy:apidocs",
"lint": "eslint --ext .ts src",
"lint:report": "pnpm lint --format json --output-file report.json",
"dev": "rm -rf build/ && pnpm run copyfiles && nodemon",
"dev": "rm -rf build/ && pnpm run copy:apidocs && nodemon",
"start": "NODE_ENV=production node .",
"test:only": "NODE_OPTIONS=\"--experimental-vm-modules --max_old_space_size=4096\" jest --logHeapUsage",
"test": "pnpm build:test && pnpm test:only",
Expand Down Expand Up @@ -80,8 +80,8 @@
"qrcode": "^1.5.3",
"redis": "^4.6.5",
"roarr": "^7.11.0",
"semver": "^7.3.8",
"samlify": "2.8.10",
"semver": "^7.3.8",
"slonik": "^30.0.0",
"slonik-interceptor-preset": "^1.2.10",
"slonik-sql-tag-raw": "^1.1.4",
Expand Down Expand Up @@ -109,7 +109,6 @@
"@types/semver": "^7.3.12",
"@types/sinon": "^10.0.13",
"@types/supertest": "^2.0.11",
"copyfiles": "^2.4.1",
"eslint": "^8.44.0",
"jest": "^29.5.0",
"jest-matcher-specific-error": "^1.0.0",
Expand Down
291 changes: 291 additions & 0 deletions packages/core/src/routes/organization/index.openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
{
"tags": [{
"name": "Organizations",
"description": "Organization is a concept that brings together multiple identities (mostly users). Logto supports multiple organizations, and each organization can have multiple users.\n\nEvery organization shares the same set (organization template) of roles and permissions. Each user can have different roles in different organizations."
}],
"paths": {
"/api/organizations": {
"post": {
"summary": "Create a new organization",
"description": "Create a new organization with the given data.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"name": {
"description": "The name of the organization."
},
"description": {
"description": "The description of the organization."
}
}
}
}
}
},
"responses": {
"201": {
"description": "The organization was created successfully."
}
}
},
"get": {
"summary": "Get organizations",
"description": "Get organizations that match the given query with pagination.",
"parameters": [
{
"name": "q",
"in": "query",
"description": "The query to filter organizations. It can be a partial ID or name.\n\nIf not provided, all organizations will be returned."
},
{
"name": "showFeatured",
"in": "query",
"description": "Whether to show featured users in the organization. Featured users are randomly selected from the organization members.\n\nIf not provided, `featuredUsers` will not be included in the response."
}
],
"responses": {
"200": {
"description": "A list of organizations."
}
}
}
},
"/api/organizations/{id}": {
"get": {
"summary": "Get organization by ID",
"description": "Get organization details by ID.",
"responses": {
"200": {
"description": "Details of the organization."
}
}
},
"patch": {
"summary": "Update organization by ID",
"description": "Update organization details by ID with the given data.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"name": {
"description": "The updated name of the organization."
},
"description": {
"description": "The updated description of the organization."
}
}
}
}
}
},
"responses": {
"200": {
"description": "The organization was updated successfully."
}
}
},
"delete": {
"summary": "Delete organization by ID",
"description": "Delete organization by ID.",
"responses": {
"204": {
"description": "The organization was deleted successfully."
}
}
}
},
"/api/organizations/{id}/users": {
"post": {
"summary": "Add user members to organization",
"description": "Add users as members to the specified organization with the given user IDs.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"userIds": {
"description": "An array of user IDs to be added to the organization."
}
}
}
}
}
},
"responses": {
"201": {
"description": "Users were added to the organization successfully."
},
"422": {
"description": "At least one of the IDs provided is not valid. For example, the organization ID or user ID does not exist; or the user is already a member of the organization."
}
}
},
"put": {
"summary": "Replace organization user members",
"description": "Replace all user members for the specified organization with the given users. This effectively removing all existing user memberships in the organization and adding the new users as members.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"userIds": {
"description": "An array of user IDs to replace existing users."
}
}
}
}
}
},
"responses": {
"204": {
"description": "Successfully replaced all users for the organization."
},
"422": {
"description": "At least one of the IDs provided is not valid. For example, the organization ID or user ID does not exist."
}
}
},
"get": {
"summary": "Get organization user members",
"description": "Get users that are members of the specified organization for the given query with pagination.",
"parameters": [
{
"name": "q",
"in": "query",
"description": "The query to filter users. It will match multiple fields of users, including ID, name, username, email, and phone number.\n\nIf not provided, all users will be returned."
}
],
"responses": {
"200": {
"description": "A list of users that are members of the organization."
}
}
}
},
"/api/organizations/{id}/users/{userId}": {
"delete": {
"summary": "Remove user member from organization",
"description": "Remove a user's membership from the specified organization.",
"responses": {
"204": {
"description": "The user was removed from the organization members successfully."
},
"404": {
"description": "The user is not a member of the organization."
}
}
}
},
"/api/organizations/{id}/users/roles": {
"post": {
"summary": "Assign roles to organization user members",
"description": "Assign roles to user members of the specified organization with the given data.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"userIds": {
"description": "An array of user IDs to assign roles."
},
"organizationRoleIds": {
"description": "An array of organization role IDs to assign."
}
}
}
}
}
},
"responses": {
"201": {
"description": "Roles were assigned to organization users successfully."
},
"422": {
"description": "At least one of the IDs provided is not valid. For example, the organization ID, user ID, or organization role ID does not exist; the user is not a member of the organization; or the user already has the role."
}
}
}
},
"/api/organizations/{id}/users/{userId}/roles": {
"get": {
"summary": "Get roles for a user in an organization",
"description": "Get roles assigned to a user in the specified organization with pagination.",
"responses": {
"200": {
"description": "A list of roles assigned to the user."
},
"422": {
"description": "The user is not a member of the organization."
}
}
},
"put": {
"summary": "Update roles for a user in an organization",
"description": "Update roles assigned to a user in the specified organization with the provided data.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"organizationRoleIds": {
"description": "An array of organization role IDs to update for the user."
}
}
}
}
}
},
"responses": {
"204": {
"description": "Roles were updated for the user successfully."
},
"422": {
"description": "The user is not a member of the organization; or at least one of the IDs provided is not valid. For example, the organization ID or organization role ID does not exist."
}
}
},
"post": {
"summary": "Assign roles to a user in an organization",
"description": "Assign roles to a user in the specified organization with the provided data.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"organizationRoleIds": {
"description": "An array of organization role IDs to assign to the user."
}
}
}
}
}
},
"responses": {
"201": {
"description": "Roles were assigned to the user successfully."
},
"422": {
"description": "The user is not a member of the organization; or at least one of the IDs provided is not valid. For example, the organization ID or organization role ID does not exist; or the user already has the role."
}
}
}
},
"/api/organizations/{id}/users/{userId}/roles/{roleId}": {
"delete": {
"summary": "Remove a role from a user in an organization",
"description": "Remove a role assignment from a user in the specified organization.",
"responses": {
"204": {
"description": "The role was removed from the user successfully."
},
"404": {
"description": "The user is not a member of the organization; or the user does not have the role."
}
}
}
}
}
}
Loading

0 comments on commit 5de7772

Please sign in to comment.