Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): make config validation less strict #3120

Merged
merged 6 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/docusaurus-plugin-content-blog/src/pluginOptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DEFAULT_OPTIONS = {

export const PluginOptionSchema = Joi.object({
path: Joi.string().default(DEFAULT_OPTIONS.path),
routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath),
routeBasePath: Joi.string().allow('').default(DEFAULT_OPTIONS.routeBasePath),
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
postsPerPage: Joi.number()
.integer()
Expand All @@ -45,16 +45,19 @@ export const PluginOptionSchema = Joi.object({
showReadingTime: Joi.bool().default(DEFAULT_OPTIONS.showReadingTime),
remarkPlugins: Joi.array()
.items(
Joi.alternatives().try(
Joi.function(),
Joi.array()
.items(Joi.function().required(), Joi.object().required())
.length(2),
),
Joi.array()
.items(Joi.function().required(), Joi.object().required())
.length(2),
Joi.function(),
)
.default(DEFAULT_OPTIONS.remarkPlugins),
rehypePlugins: Joi.array()
.items(Joi.string())
.items(
Joi.array()
.items(Joi.function().required(), Joi.object().required())
.length(2),
Joi.function(),
)
.default(DEFAULT_OPTIONS.rehypePlugins),
editUrl: Joi.string().uri(),
truncateMarker: Joi.object().default(DEFAULT_OPTIONS.truncateMarker),
Expand Down
13 changes: 10 additions & 3 deletions packages/docusaurus-plugin-content-docs/src/pluginOptionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,27 @@ export const DEFAULT_OPTIONS: PluginOptions = {
export const PluginOptionSchema = Joi.object({
path: Joi.string().default(DEFAULT_OPTIONS.path),
editUrl: Joi.string().uri(),
routeBasePath: Joi.string().default(DEFAULT_OPTIONS.routeBasePath),
routeBasePath: Joi.string().allow('').default(DEFAULT_OPTIONS.routeBasePath),
homePageId: Joi.string().default(DEFAULT_OPTIONS.homePageId),
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
sidebarPath: Joi.string().default(DEFAULT_OPTIONS.sidebarPath),
docLayoutComponent: Joi.string().default(DEFAULT_OPTIONS.docLayoutComponent),
docItemComponent: Joi.string().default(DEFAULT_OPTIONS.docItemComponent),
remarkPlugins: Joi.array()
.items(
Joi.array().items(Joi.function(), Joi.object()).length(2),
Joi.array()
.items(Joi.function().required(), Joi.object().required())
.length(2),
Joi.function(),
)
.default(DEFAULT_OPTIONS.remarkPlugins),
rehypePlugins: Joi.array()
.items(Joi.string())
.items(
Joi.array()
.items(Joi.function().required(), Joi.object().required())
.length(2),
Joi.function(),
)
.default(DEFAULT_OPTIONS.rehypePlugins),
showLastUpdateTime: Joi.bool().default(DEFAULT_OPTIONS.showLastUpdateTime),
showLastUpdateAuthor: Joi.bool().default(
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-classic/src/themeConfigSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const ThemeConfigSchema = Joi.object({
'themeConfig.navbar.links has been renamed as themeConfig.navbar.items',
}),
items: Joi.array().items(NavbarItemSchema),
title: Joi.string().required(),
title: Joi.string().allow('', null),
logo: Joi.object({
alt: Joi.string(),
src: Joi.string().required(),
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus/src/server/configValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import {DocusaurusConfig} from '@docusaurus/types';
import Joi from '@hapi/joi';
import {CONFIG_FILE_NAME} from '../constants';
import Joi from '@hapi/joi';

export const DEFAULT_CONFIG: Pick<
DocusaurusConfig,
Expand Down Expand Up @@ -66,14 +66,14 @@ const ConfigSchema = Joi.object({
src: Joi.string().required(),
async: Joi.bool(),
defer: Joi.bool(),
}).oxor('async', 'defer'),
}),
),
stylesheets: Joi.array().items(
Joi.string(),
Joi.object({
href: Joi.string().uri().required(),
href: Joi.string().required(),
type: Joi.string().required(),
}),
}).unknown(),
),
tagline: Joi.string(),
});
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17578,7 +17578,7 @@ react-dev-utils@^9.1.0:
strip-ansi "5.2.0"
text-table "0.2.0"

react-dom@^16.10.2, react-dom@^16.8.4:
react-dom@^16.8.4:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
Expand Down Expand Up @@ -17739,7 +17739,7 @@ react-waypoint@^9.0.2:
prop-types "^15.0.0"
react-is "^16.6.3"

react@^16.10.2, react@^16.8.4:
react@^16.8.4:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
Expand Down