250 lines
5.1 KiB
JavaScript
Raw Permalink Normal View History

Add new @strapi/openapi package (#24024) * chore(openapi): add new @strapi/openapi package with initial setup (#23173) * enhancement(openapi): add routes collection (#23182) * chore(openapi): add new @strapi/openapi package with initial setup and configuration * fix: lint the test folder * chore(openapi): add coverage/ to .eslintignore for better linting exclusion * test(openapi): update Jest config with refined test paths and coverage * chore: remove unused test and update openapi dependencies * feat(openapi): add route providers, collector, and matcher * test(openapi): add unit tests for route matching and providers * fix: make the AbstractRoutesProvider constructor public * chore: update test paths and imports to simplify structure * test: update route provider tests to use dynamic fixture lengths * feat: add basic openapi document generation (#23365) * chore: update openapi dependencies * feat(openapi): advanced schema generation (#23467) * chore: rename openapi:generate CLI command to openapi generate (#23610) * chore(openapi): add experimental warning message for OpenAPI generation feature (#23608) Co-authored-by: Jamie Howard <jhoward1994@gmail.com> * chore: update OpenAPI types to OpenAPIV3_1 across the codebase (#23609) * chore: merge origin/develop * chore: update zod dependency from beta version to 3.25.67 across the codebase using zod/v4 where needed * fix(strapi): add output option for openapi generation command (#23849) * feat(core): add uid transformation utility for openapi compliant names (#23833) * feat(core): add uid transformation utility for openapi compliant names * chore: version openapi to 5.16.1 * chore(core): update uid parameter to use internal types * fix(core): simplify global registry check * fix(core): remove unnecessary type assertion * fix(core): add type assertions in validation attributes * fix(core): remove unused import * chore: update @strapi/openapi to 5.18.1 * Add zod schema validation to content api routes (#23886) * feat(i18n): zod validation for locale content api routes * feat(email): integrate zod for email content api routes * feat(upload): wip partial zod route validation * feat: add validation for upload and ctb content api routes (#23924) * feat: add validation for content API routes and upload * fix: fix linting errors and prettier error * fix: add missing schemas * chore(content-type-builder): more accurate zod descriptions * Centralise AbstractRouteValidator to strapi utils (#23962) * chore(utils): centralise abstractroutevalidator in utils for package use and schema aware extension in strapi core * chore(core): update query parameter transformer usage in convert-query-params tests * feat(core): enhance schema validation error handling and logging * fix: revert incorrect changes --------- Co-authored-by: Jamie Howard <jhoward1994@gmail.com> Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> * feat(users-permissions): zod schemas for content-api routes (#23997) * feat(users-permissions): zod schemas for content-api routes * fix(users-permissions): formatting * chore: include content type for API route request body --------- Co-authored-by: Ziyi <ziyi.yuan@strapi.io> * chore: minor clean up --------- Co-authored-by: Jean-Sébastien Herbaux <jean-sebastien.herbaux@epitech.eu> Co-authored-by: Ziyi <ziyi.yuan@strapi.io>
2025-07-28 12:02:09 +01:00
'use strict';
const { AbstractRouteValidator } = require('@strapi/utils');
const z = require('zod/v4');
class UsersPermissionsRouteValidator extends AbstractRouteValidator {
constructor(strapi) {
super();
this._strapi = strapi;
}
get userSchema() {
return z.object({
id: z.number(),
documentId: z.string(),
username: z.string(),
email: z.string(),
provider: z.string(),
confirmed: z.boolean(),
blocked: z.boolean(),
role: z
.union([
z.number(),
z.object({
id: z.number(),
name: z.string(),
description: z.string().nullable(),
type: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
}),
])
.optional(),
createdAt: z.string(),
updatedAt: z.string(),
publishedAt: z.string(),
});
}
get roleSchema() {
return z.object({
id: z.number(),
documentId: z.string(),
name: z.string(),
description: z.string().nullable(),
type: z.string(),
createdAt: z.string(),
updatedAt: z.string(),
publishedAt: z.string(),
nb_users: z.number().optional(),
permissions: z
.record(
z.string(), // plugin name
z.object({
controllers: z.record(
z.string(), // controller name
z.record(
z.string(), // action name
z.object({
enabled: z.boolean(),
policy: z.string(),
})
)
),
})
)
.optional(),
users: z.array(z.unknown()).optional(),
});
}
get permissionSchema() {
return z.object({
id: z.number(),
action: z.string(),
role: z.object({
id: z.number(),
name: z.string(),
description: z.string().nullable(),
type: z.string(),
}),
createdAt: z.string(),
updatedAt: z.string(),
});
}
get authResponseSchema() {
return z.object({
jwt: z.string(),
user: this.userSchema,
});
}
get authResponseWithoutJwtSchema() {
return z.object({
user: this.userSchema,
});
}
get authRegisterResponseSchema() {
return z.union([this.authResponseSchema, this.authResponseWithoutJwtSchema]);
}
get forgotPasswordResponseSchema() {
return z.object({
ok: z.boolean(),
});
}
get sendEmailConfirmationResponseSchema() {
return z.object({
email: z.string(),
sent: z.boolean(),
});
}
get rolesResponseSchema() {
return z.object({
roles: z.array(this.roleSchema),
});
}
get roleResponseSchema() {
return z.object({
role: this.roleSchema,
});
}
get roleSuccessResponseSchema() {
return z.object({
ok: z.boolean(),
});
}
get permissionsResponseSchema() {
return z.object({
permissions: z.record(
z.string(), // plugin name
z.object({
controllers: z.record(
z.string(), // controller name
z.record(
z.string(), // action name
z.object({
enabled: z.boolean(),
policy: z.string(),
})
)
),
})
),
});
}
get loginBodySchema() {
return z.object({
identifier: z.string(),
password: z.string(),
});
}
get registerBodySchema() {
return z.object({
username: z.string(),
email: z.email(),
password: z.string(),
});
}
get forgotPasswordBodySchema() {
return z.object({
email: z.email(),
});
}
get resetPasswordBodySchema() {
return z.object({
code: z.string(),
password: z.string(),
passwordConfirmation: z.string(),
});
}
get changePasswordBodySchema() {
return z.object({
currentPassword: z.string(),
password: z.string(),
passwordConfirmation: z.string(),
});
}
get sendEmailConfirmationBodySchema() {
return z.object({
email: z.email(),
});
}
get createUserBodySchema() {
return z.object({
username: z.string(),
email: z.email(),
password: z.string(),
role: z.number().optional(),
});
}
get updateUserBodySchema() {
return z.object({
username: z.string().optional(),
email: z.email().optional(),
password: z.string().optional(),
role: z.number().optional(),
});
}
get createRoleBodySchema() {
return z.object({
name: z.string(),
description: z.string().optional(),
type: z.string(),
permissions: z.record(z.string(), z.unknown()).optional(),
});
}
get updateRoleBodySchema() {
return z.object({
name: z.string().optional(),
description: z.string().optional(),
type: z.string().optional(),
permissions: z.record(z.string(), z.unknown()).optional(),
});
}
get userIdParam() {
return z.string();
}
get roleIdParam() {
return z.string();
}
get providerParam() {
return z.string();
}
}
module.exports = {
UsersPermissionsRouteValidator,
};