chore: re-enable the Reference Docs options in the theme.openapi config (#1617)

This commit is contained in:
Andrew Tatomyr
2024-07-22 16:43:53 +03:00
committed by GitHub
parent 373ad9d668
commit 74ff80fe7a
21 changed files with 229 additions and 297 deletions

View File

@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": patch
"@redocly/cli": patch
---
Allowed the `theme.openapi` configuration option to accept settings specific to Redoc 2.x and earlier.

4
.gitignore vendored
View File

@@ -13,3 +13,7 @@ output/
*.tgz
redoc-static.html
packages/cli/README.md
redocly.yaml
.redocly.yaml
redocly.yml
.redocly.yml

View File

@@ -4,20 +4,6 @@ exports[`E2E build-docs build docs with config option 1`] = `
🎉 bundled successfully in: nested/redoc-static.html (33 KiB) [⏱ <test>ms].
[1] nested/redocly.yaml:5:5 at #/theme/openapi/htmlTemplate
Property \`htmlTemplate\` is not expected here.
3 | theme:
4 | openapi:
5 | htmlTemplate: ../index.hbs
| ^^^^^^^^^^^^
6 |
Warning was generated by the configuration spec rule.
⚠️ Your config has 1 warning.
Found nested/redocly.yaml and using theme.openapi options
Prerendering docs

View File

@@ -91,14 +91,6 @@ ssoOnPrem:
# configurationUrl: Must be reported as a missing required prop
clientSecret: '{{ process.env.secret }}'
basic:
type: BASIC
credentials:
- teams:
- 789 # Must be a string
- correct
# username: Must be reported as a missing required prop
sso:
- WRONG # Does not match allowed options

View File

@@ -14,30 +14,30 @@ Expected type \`string\` but got \`integer\`.
Error was generated by the configuration spec rule.
[2] .redocly.yaml:103:5 at #/sso/0
[2] .redocly.yaml:95:5 at #/sso/0
\`sso\` can be one of the following only: "REDOCLY", "CORPORATE", "GUEST".
101 |
102 | sso:
103 | - WRONG # Does not match allowed options
| ^^^^^
104 |
105 | developerOnboarding:
93 |
94 | sso:
95 | - WRONG # Does not match allowed options
| ^^^^^
96 |
97 | developerOnboarding:
Error was generated by the configuration spec rule.
[3] .redocly.yaml:136:1 at #/not-listed-filed
[3] .redocly.yaml:128:1 at #/not-listed-filed
Property \`not-listed-filed\` is not expected here.
134 | test: anything
135 |
136 | not-listed-filed: Must be reported as not expected
126 | test: anything
127 |
128 | not-listed-filed: Must be reported as not expected
| ^^^^^^^^^^^^^^^^
137 |
138 | env:
129 |
130 | env:
Error was generated by the configuration spec rule.
@@ -374,269 +374,236 @@ The field \`configurationUrl\` must be present on this level.
Error was generated by the configuration spec rule.
[27] .redocly.yaml:97:9 at #/ssoOnPrem/basic/credentials/0
The field \`username\` must be present on this level.
95 | type: BASIC
96 | credentials:
97 | - teams:
| ^^^^^^
98 | - 789 # Must be a string
| ^^^^^^^^^^^^^^^^^^^^^^^^
… | < 2 more lines >
101 |
| ^
102 | sso:
103 | - WRONG # Does not match allowed options
Error was generated by the configuration spec rule.
[28] .redocly.yaml:98:13 at #/ssoOnPrem/basic/credentials/0/teams/0
Expected type \`string\` but got \`integer\`.
96 | credentials:
97 | - teams:
98 | - 789 # Must be a string
| ^^^
99 | - correct
100 | # username: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[29] .redocly.yaml:106:3 at #/developerOnboarding/wrong
[27] .redocly.yaml:98:3 at #/developerOnboarding/wrong
Property \`wrong\` is not expected here.
104 |
105 | developerOnboarding:
106 | wrong: A not allowed field
96 |
97 | developerOnboarding:
98 | wrong: A not allowed field
| ^^^^^
107 | adapters:
108 | - should be object
99 | adapters:
100 | - should be object
Error was generated by the configuration spec rule.
[30] .redocly.yaml:108:7 at #/developerOnboarding/adapters/0
[28] .redocly.yaml:100:7 at #/developerOnboarding/adapters/0
Expected type \`APIGEE_X\` (object) but got \`string\`
106 | wrong: A not allowed field
107 | adapters:
108 | - should be object
98 | wrong: A not allowed field
99 | adapters:
100 | - should be object
| ^^^^^^^^^^^^^^^^
109 | - type: 123 # Must be a string
110 | - type: APIGEE_X
101 | - type: 123 # Must be a string
102 | - type: APIGEE_X
Error was generated by the configuration spec rule.
[31] .redocly.yaml:109:7 at #/developerOnboarding/adapters/1
[29] .redocly.yaml:101:7 at #/developerOnboarding/adapters/1
The field \`organizationName\` must be present on this level.
107 | adapters:
108 | - should be object
109 | - type: 123 # Must be a string
99 | adapters:
100 | - should be object
101 | - type: 123 # Must be a string
| ^^^^^^^^^
110 | - type: APIGEE_X
111 | # organizationName: Must be reported as a missing required prop
102 | - type: APIGEE_X
103 | # organizationName: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[32] .redocly.yaml:109:7 at #/developerOnboarding/adapters/1
[30] .redocly.yaml:101:7 at #/developerOnboarding/adapters/1
The field \`auth\` must be present on this level.
107 | adapters:
108 | - should be object
109 | - type: 123 # Must be a string
99 | adapters:
100 | - should be object
101 | - type: 123 # Must be a string
| ^^^^^^^^^
110 | - type: APIGEE_X
111 | # organizationName: Must be reported as a missing required prop
102 | - type: APIGEE_X
103 | # organizationName: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[33] .redocly.yaml:109:13 at #/developerOnboarding/adapters/1/type
[31] .redocly.yaml:101:13 at #/developerOnboarding/adapters/1/type
Expected type \`string\` but got \`integer\`.
107 | adapters:
108 | - should be object
109 | - type: 123 # Must be a string
99 | adapters:
100 | - should be object
101 | - type: 123 # Must be a string
| ^^^
110 | - type: APIGEE_X
111 | # organizationName: Must be reported as a missing required prop
102 | - type: APIGEE_X
103 | # organizationName: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[34] .redocly.yaml:110:7 at #/developerOnboarding/adapters/2
[32] .redocly.yaml:102:7 at #/developerOnboarding/adapters/2
The field \`organizationName\` must be present on this level.
108 | - should be object
109 | - type: 123 # Must be a string
110 | - type: APIGEE_X
100 | - should be object
101 | - type: 123 # Must be a string
102 | - type: APIGEE_X
| ^^^^^^^^^^^^^^
111 | # organizationName: Must be reported as a missing required prop
103 | # organizationName: Must be reported as a missing required prop
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
… | < 5 more lines >
117 | not-expected: Must fail
109 | not-expected: Must fail
| ^^^^^^^^^^^^^^^^^^^^^^^
118 | - type: APIGEE_X
119 | organizationName: Test
110 | - type: APIGEE_X
111 | organizationName: Test
Error was generated by the configuration spec rule.
[35] .redocly.yaml:112:7 at #/developerOnboarding/adapters/2/auth
[33] .redocly.yaml:104:7 at #/developerOnboarding/adapters/2/auth
The field \`tokenEndpoint\` must be present on this level.
110 | - type: APIGEE_X
111 | # organizationName: Must be reported as a missing required prop
112 | auth:
102 | - type: APIGEE_X
103 | # organizationName: Must be reported as a missing required prop
104 | auth:
| ^^^^
113 | type: OAUTH2
114 | # tokenEndpoint: Must be reported as a missing required prop
105 | type: OAUTH2
106 | # tokenEndpoint: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[36] .redocly.yaml:115:19 at #/developerOnboarding/adapters/2/auth/clientId
[34] .redocly.yaml:107:19 at #/developerOnboarding/adapters/2/auth/clientId
Expected type \`string\` but got \`integer\`.
113 | type: OAUTH2
114 | # tokenEndpoint: Must be reported as a missing required prop
115 | clientId: 456 # Must be a string
105 | type: OAUTH2
106 | # tokenEndpoint: Must be reported as a missing required prop
107 | clientId: 456 # Must be a string
| ^^^
116 | clientSecret: '{{ process.env.secret }}'
117 | not-expected: Must fail
108 | clientSecret: '{{ process.env.secret }}'
109 | not-expected: Must fail
Error was generated by the configuration spec rule.
[37] .redocly.yaml:117:9 at #/developerOnboarding/adapters/2/auth/not-expected
[35] .redocly.yaml:109:9 at #/developerOnboarding/adapters/2/auth/not-expected
Property \`not-expected\` is not expected here.
115 | clientId: 456 # Must be a string
116 | clientSecret: '{{ process.env.secret }}'
117 | not-expected: Must fail
107 | clientId: 456 # Must be a string
108 | clientSecret: '{{ process.env.secret }}'
109 | not-expected: Must fail
| ^^^^^^^^^^^^
118 | - type: APIGEE_X
119 | organizationName: Test
110 | - type: APIGEE_X
111 | organizationName: Test
Error was generated by the configuration spec rule.
[38] .redocly.yaml:120:7 at #/developerOnboarding/adapters/3/auth
[36] .redocly.yaml:112:7 at #/developerOnboarding/adapters/3/auth
The field \`serviceAccountPrivateKey\` must be present on this level.
118 | - type: APIGEE_X
119 | organizationName: Test
120 | auth:
110 | - type: APIGEE_X
111 | organizationName: Test
112 | auth:
| ^^^^
121 | type: SERVICE_ACCOUNT
122 | # serviceAccountPrivateKey: Must be reported as a missing required prop
113 | type: SERVICE_ACCOUNT
114 | # serviceAccountPrivateKey: Must be reported as a missing required prop
Error was generated by the configuration spec rule.
[39] .redocly.yaml:123:30 at #/developerOnboarding/adapters/3/auth/serviceAccountEmail
[37] .redocly.yaml:115:30 at #/developerOnboarding/adapters/3/auth/serviceAccountEmail
Expected type \`string\` but got \`integer\`.
121 | type: SERVICE_ACCOUNT
122 | # serviceAccountPrivateKey: Must be reported as a missing required prop
123 | serviceAccountEmail: 789 # Must be a string
113 | type: SERVICE_ACCOUNT
114 | # serviceAccountPrivateKey: Must be reported as a missing required prop
115 | serviceAccountEmail: 789 # Must be a string
| ^^^
124 |
125 | i18n:
116 |
117 | i18n:
Error was generated by the configuration spec rule.
[40] .redocly.yaml:128:13 at #/i18n/locales/0/code
[38] .redocly.yaml:120:13 at #/i18n/locales/0/code
Expected type \`string\` but got \`integer\`.
126 | defaultLocale: en-US
127 | locales:
128 | - code: 123 # Must be a string
118 | defaultLocale: en-US
119 | locales:
120 | - code: 123 # Must be a string
| ^^^
129 | name: English
130 | - code: es-ES
121 | name: English
122 | - code: es-ES
Error was generated by the configuration spec rule.
[41] .redocly.yaml:141:12 at #/env/some-env/mockServer/off
[39] .redocly.yaml:133:12 at #/env/some-env/mockServer/off
Expected type \`boolean\` but got \`string\`.
139 | some-env:
140 | mockServer:
141 | off: must be boolean
131 | some-env:
132 | mockServer:
133 | off: must be boolean
| ^^^^^^^^^^^^^^^
142 | not-expected: Must fail
143 | apis:
134 | not-expected: Must fail
135 | apis:
Error was generated by the configuration spec rule.
[42] .redocly.yaml:142:7 at #/env/some-env/mockServer/not-expected
[40] .redocly.yaml:134:7 at #/env/some-env/mockServer/not-expected
Property \`not-expected\` is not expected here.
140 | mockServer:
141 | off: must be boolean
142 | not-expected: Must fail
132 | mockServer:
133 | off: must be boolean
134 | not-expected: Must fail
| ^^^^^^^^^^^^
143 | apis:
144 | no-root:
135 | apis:
136 | no-root:
Error was generated by the configuration spec rule.
[43] .redocly.yaml:144:7 at #/env/some-env/apis/no-root
[41] .redocly.yaml:136:7 at #/env/some-env/apis/no-root
The field \`root\` must be present on this level.
142 | not-expected: Must fail
143 | apis:
144 | no-root:
134 | not-expected: Must fail
135 | apis:
136 | no-root:
| ^^^^^^^
145 | # root: Must be defined
146 | rules: {}
137 | # root: Must be defined
138 | rules: {}
Error was generated by the configuration spec rule.
[44] .redocly.yaml:148:15 at #/env/some-env/apis/wrong-root/root
[42] .redocly.yaml:140:15 at #/env/some-env/apis/wrong-root/root
Expected type \`string\` but got \`integer\`.
146 | rules: {}
147 | wrong-root:
148 | root: 789 # Must be a string
138 | rules: {}
139 | wrong-root:
140 | root: 789 # Must be a string
| ^^^
149 |
150 | referenced-env:
141 |
142 | referenced-env:
Error was generated by the configuration spec rule.
[45] env.yaml:2:5 at #/ignore/0
[43] env.yaml:2:5 at #/ignore/0
Expected type \`string\` but got \`integer\`.
@@ -646,12 +613,12 @@ Expected type \`string\` but got \`integer\`.
3 | - correct
4 |
referenced from .redocly.yaml:151:5 at #/env/referenced-env
referenced from .redocly.yaml:143:5 at #/env/referenced-env
Error was generated by the configuration spec rule.
❌ Your config has 45 errors.
❌ Your config has 43 errors.
`;

View File

@@ -68,16 +68,15 @@ referenced from .redocly.yaml:7:3 at #/rules
Error was generated by the configuration spec rule.
[6] theme-openapi.yaml:1:1 at #/theme
[6] theme-openapi.yaml:3:15 at #/theme/logo/maxWidth
Property \`theme\` is not expected here.
Expected type \`string\` but got \`integer\`.
1 | theme: # Not expected here anymore
| ^^^^^
1 | theme:
2 | logo:
3 | maxWidth: 100
referenced from .redocly.yaml:11:5 at #/theme/openapi
| ^^^
4 |
Error was generated by the configuration spec rule.

View File

@@ -1,3 +1,3 @@
theme: # Not expected here anymore
theme:
logo:
maxWidth: 100

View File

@@ -30,17 +30,15 @@ referenced from .redocly.yaml:5:7 at #/apis/main/rules
Warning was generated by the configuration spec rule.
[3] theme-openapi.yaml:2:3 at #/content/theme
[3] theme-openapi.yaml:4:17 at #/content/theme/logo/maxWidth
Property \`theme\` is not expected here.
Expected type \`string\` but got \`integer\`.
1 | content:
2 | theme: # Not expected here anymore
| ^^^^^
3 | logo:
4 | maxWidth: 100
referenced from .redocly.yaml:11:5 at #/theme/openapi
2 | theme:
3 | logo:
4 | maxWidth: 100
| ^^^
5 |
Warning was generated by the configuration spec rule.

View File

@@ -1,4 +1,4 @@
content:
theme: # Not expected here anymore
theme:
logo:
maxWidth: 100

20
package-lock.json generated
View File

@@ -3524,9 +3524,9 @@
"link": true
},
"node_modules/@redocly/config": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.6.2.tgz",
"integrity": "sha512-c3K5u64eMnr2ootPcpEI0ioIRLE8QP8ptvLxG9MwAmb2sU8HMRfVwXDU3AZiMVY2w4Ts0mDc+Xv4HTIk8DRqFw=="
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.7.0.tgz",
"integrity": "sha512-6GKxTo/9df0654Mtivvr4lQnMOp+pRj9neVywmI5+BwfZLTtkJnj2qB3D6d8FHTr4apsNOf6zTa5FojX0Evh4g=="
},
"node_modules/@redocly/openapi-core": {
"resolved": "packages/core",
@@ -13506,6 +13506,7 @@
"handlebars": "^4.7.6",
"mobx": "^6.0.4",
"node-fetch": "^2.6.1",
"pluralize": "^8.0.0",
"react": "^17.0.0 || ^18.2.0",
"react-dom": "^17.0.0 || ^18.2.0",
"redoc": "~2.1.5",
@@ -13521,6 +13522,7 @@
"devDependencies": {
"@types/configstore": "^5.0.1",
"@types/glob": "^8.1.0",
"@types/pluralize": "^0.0.29",
"@types/react": "^17.0.0 || ^18.2.21",
"@types/react-dom": "^17.0.0 || ^18.2.7",
"@types/semver": "^7.5.0",
@@ -13551,7 +13553,7 @@
"license": "MIT",
"dependencies": {
"@redocly/ajv": "^8.11.0",
"@redocly/config": "^0.6.2",
"@redocly/config": "^0.7.0",
"colorette": "^1.2.0",
"https-proxy-agent": "^7.0.4",
"js-levenshtein": "^1.1.6",
@@ -16214,6 +16216,7 @@
"@redocly/openapi-core": "1.18.0",
"@types/configstore": "^5.0.1",
"@types/glob": "^8.1.0",
"@types/pluralize": "^0.0.29",
"@types/react": "^17.0.0 || ^18.2.21",
"@types/react-dom": "^17.0.0 || ^18.2.7",
"@types/semver": "^7.5.0",
@@ -16228,6 +16231,7 @@
"handlebars": "^4.7.6",
"mobx": "^6.0.4",
"node-fetch": "^2.6.1",
"pluralize": "^8.0.0",
"react": "^17.0.0 || ^18.2.0",
"react-dom": "^17.0.0 || ^18.2.0",
"redoc": "~2.1.5",
@@ -16251,15 +16255,15 @@
}
},
"@redocly/config": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.6.2.tgz",
"integrity": "sha512-c3K5u64eMnr2ootPcpEI0ioIRLE8QP8ptvLxG9MwAmb2sU8HMRfVwXDU3AZiMVY2w4Ts0mDc+Xv4HTIk8DRqFw=="
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@redocly/config/-/config-0.7.0.tgz",
"integrity": "sha512-6GKxTo/9df0654Mtivvr4lQnMOp+pRj9neVywmI5+BwfZLTtkJnj2qB3D6d8FHTr4apsNOf6zTa5FojX0Evh4g=="
},
"@redocly/openapi-core": {
"version": "file:packages/core",
"requires": {
"@redocly/ajv": "^8.11.0",
"@redocly/config": "^0.6.2",
"@redocly/config": "^0.7.0",
"@types/js-levenshtein": "^1.1.0",
"@types/js-yaml": "^4.0.3",
"@types/lodash.isequal": "^4.5.5",

View File

@@ -47,6 +47,7 @@
"handlebars": "^4.7.6",
"mobx": "^6.0.4",
"node-fetch": "^2.6.1",
"pluralize": "^8.0.0",
"react": "^17.0.0 || ^18.2.0",
"react-dom": "^17.0.0 || ^18.2.0",
"redoc": "~2.1.5",
@@ -58,6 +59,7 @@
"devDependencies": {
"@types/configstore": "^5.0.1",
"@types/glob": "^8.1.0",
"@types/pluralize": "^0.0.29",
"@types/react": "^17.0.0 || ^18.2.21",
"@types/react-dom": "^17.0.0 || ^18.2.7",
"@types/semver": "^7.5.0",

View File

@@ -2,14 +2,17 @@ import * as fs from 'fs';
import * as path from 'path';
import { slash } from '@redocly/openapi-core';
import { green, yellow } from 'colorette';
import pluralize = require('pluralize');
import type { OutputFormat, Config } from '@redocly/openapi-core';
import { exitWithError, HandledError, printExecutionTime } from '../../utils/miscellaneous';
import {
exitWithError,
HandledError,
pluralize,
printExecutionTime,
} from '../../utils/miscellaneous';
import { handlePushStatus } from './push-status';
import { ReuniteApiClient, getDomain, getApiKeys } from '../api';
import type { OutputFormat, Config } from '@redocly/openapi-core';
export type PushOptions = {
apis?: string[];
organization?: string;

View File

@@ -1,3 +1,5 @@
import { blue, gray } from 'colorette';
import { performance } from 'perf_hooks';
import {
Config,
formatProblems,
@@ -13,19 +15,18 @@ import {
getExecutionTime,
getFallbackApisOrExit,
handleError,
notifyAboutIncompatibleConfigOptions,
pluralize,
printConfigLintTotals,
printLintTotals,
printUnusedWarnings,
} from '../utils/miscellaneous';
import { blue, gray } from 'colorette';
import { performance } from 'perf_hooks';
import { getCommandNameFromArgs } from '../utils/getCommandNameFromArgs';
import type { OutputFormat, ProblemSeverity, RuleSeverity } from '@redocly/openapi-core';
import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
import type { CommandOptions, Skips, Totals } from '../types';
import { getCommandNameFromArgs } from '../utils/getCommandNameFromArgs';
import { Arguments } from 'yargs';
import type { Arguments } from 'yargs';
export type LintOptions = {
apis?: string[];
@@ -130,7 +131,13 @@ export function lintConfigCallback(
return;
}
return async ({ document, resolvedRefMap, config }) => {
return async ({ document, resolvedRefMap, config, parsed: { theme = {} } }) => {
const command = argv ? getCommandNameFromArgs(argv as Arguments) : undefined;
if (command === 'check-config') {
notifyAboutIncompatibleConfigOptions(theme.openapi);
}
const problems = await lintConfig({
document,
resolvedRefMap,
@@ -147,8 +154,6 @@ export function lintConfigCallback(
version,
});
const command = argv ? getCommandNameFromArgs(argv as unknown as Arguments) : undefined;
printConfigLintTotals(fileTotals, command);
if (fileTotals.errors > 0) {

View File

@@ -20,8 +20,8 @@ import {
exitWithError,
printExecutionTime,
getFallbackApisOrExit,
pluralize,
dumpBundle,
pluralize,
} from '../utils/miscellaneous';
import { promptClientToken } from './login';
import { handlePush as handleCMSPush } from '../cms/commands/push';

View File

@@ -1,4 +1,4 @@
import fetch from './fetch-with-timeout';
import * as pluralizeOne from 'pluralize';
import { basename, dirname, extname, join, resolve, relative, isAbsolute } from 'path';
import { blue, gray, green, red, yellow } from 'colorette';
import { performance } from 'perf_hooks';
@@ -9,36 +9,34 @@ import { Writable } from 'stream';
import { execSync } from 'child_process';
import { promisify } from 'util';
import {
BundleOutputFormat,
StyleguideConfig,
ResolveError,
YamlParseError,
ResolvedApi,
parseYaml,
stringifyYaml,
isAbsoluteUrl,
loadConfig,
RedoclyClient,
} from '@redocly/openapi-core';
import { isEmptyObject, isPlainObject } from '@redocly/openapi-core/lib/utils';
import { ConfigValidationError } from '@redocly/openapi-core/lib/config';
import { deprecatedRefDocsSchema } from '@redocly/config/lib/reference-docs-config-schema';
import { outputExtensions } from '../types';
import { version } from './update-version-notifier';
import { DESTINATION_REGEX } from '../commands/push';
import fetch from './fetch-with-timeout';
import type { Arguments } from 'yargs';
import type {
BundleOutputFormat,
StyleguideConfig,
ResolvedApi,
Region,
Config,
Oas3Definition,
Oas2Definition,
RedoclyClient,
} from '@redocly/openapi-core';
import {
Totals,
outputExtensions,
Entrypoint,
ConfigApis,
CommandOptions,
OutputExtensions,
} from '../types';
import { isEmptyObject } from '@redocly/openapi-core/lib/utils';
import { Arguments } from 'yargs';
import { version } from './update-version-notifier';
import { DESTINATION_REGEX } from '../commands/push';
import { ConfigValidationError } from '@redocly/openapi-core/lib/config';
import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
import type { Totals, Entrypoint, ConfigApis, CommandOptions, OutputExtensions } from '../types';
export async function getFallbackApisOrExit(
argsApis: string[] | undefined,
@@ -279,12 +277,11 @@ export function getAndValidateFileExtension(fileName: string): NonNullable<Outpu
return 'yaml';
}
export function pluralize(label: string, num: number) {
if (label.endsWith('is')) {
[label] = label.split(' ');
return num === 1 ? `${label} is` : `${label}s are`;
}
return num === 1 ? `${label}` : `${label}s`;
export function pluralize(sentence: string, count?: number, inclusive?: boolean) {
return sentence
.split(' ')
.map((word) => pluralizeOne(word, count, inclusive))
.join(' ');
}
export function handleError(e: Error, ref: string) {
@@ -664,3 +661,25 @@ export function checkForDeprecatedOptions<T>(argv: T, deprecatedOptions: Array<k
}
}
}
export function notifyAboutIncompatibleConfigOptions(
themeOpenapiOptions: Record<string, unknown> | undefined
) {
if (isPlainObject(themeOpenapiOptions)) {
const propertiesSet = Object.keys(themeOpenapiOptions);
const deprecatedSet = Object.keys(deprecatedRefDocsSchema.properties);
const intersection = propertiesSet.filter((prop) => deprecatedSet.includes(prop));
if (intersection.length > 0) {
process.stderr.write(
yellow(
`\n${pluralize('Property', intersection.length)} ${gray(
intersection.map((prop) => `'${prop}'`).join(', ')
)} ${pluralize(
'is',
intersection.length
)} only used in API Reference Docs and Redoc version 2.x or earlier.\n\n`
)
);
}
}
}

View File

@@ -36,7 +36,7 @@
],
"dependencies": {
"@redocly/ajv": "^8.11.0",
"@redocly/config": "^0.6.2",
"@redocly/config": "^0.7.0",
"colorette": "^1.2.0",
"https-proxy-agent": "^7.0.4",
"js-levenshtein": "^1.1.6",

View File

@@ -104,14 +104,6 @@ const testPortalConfig = parseYamlToDocument(
# configurationUrl: Must be reported as a missing required prop
clientSecret: '{{ process.env.secret }}'
basic:
type: BASIC
credentials:
- teams:
- 789 # Must be a string
- correct
# username: Must be reported as a missing required prop
sso:
- WRONG # Does not match allowed options
@@ -393,20 +385,6 @@ describe('lint', () => {
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/theme/openapi/showConsole",
"reportOnKey": true,
"source": "",
},
],
"message": "Property \`showConsole\` is not expected here.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
@@ -912,34 +890,6 @@ describe('lint', () => {
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/ssoOnPrem/basic/credentials/0",
"reportOnKey": true,
"source": "",
},
],
"message": "The field \`username\` must be present on this level.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [
{
"pointer": "#/ssoOnPrem/basic/credentials/0/teams/0",
"reportOnKey": false,
"source": "",
},
],
"message": "Expected type \`string\` but got \`integer\`.",
"ruleId": "configuration spec",
"severity": "error",
"suggest": [],
},
{
"from": undefined,
"location": [

View File

@@ -10,10 +10,9 @@ import { bundleConfig } from '../bundle';
import { BaseResolver } from '../resolve';
import { isBrowser } from '../env';
import type { Document } from '../resolve';
import type { Document, ResolvedRefMap } from '../resolve';
import type { RegionalToken, RegionalTokenWithValidity } from '../redocly/redocly-client-types';
import type { RawConfig, RawUniversalConfig, Region } from './types';
import type { ResolvedRefMap } from '../resolve';
import { DOMAINS } from '../redocly/domains';
async function addConfigMetadata({

View File

@@ -1,7 +1,8 @@
import { UserContext } from '../../walk';
import { Oas3_1Schema } from '../../typings/openapi';
import { getAdditionalPropertiesOption, validateExample } from '../utils';
import type { UserContext } from '../../walk';
import type { Oas3_1Schema } from '../../typings/openapi';
export const NoInvalidSchemaExamples: any = (opts: any) => {
const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false;
return {

View File

@@ -1,6 +1,7 @@
import * as pluralize from 'pluralize';
import { Oas3Rule, Oas2Rule } from '../../visitors';
import { UserContext } from '../../walk';
import { isPathParameter, isSingular } from '../../utils';
import { isPathParameter } from '../../utils';
export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
const { ignoreLastPathSegment, exceptions } = opts;
@@ -17,7 +18,7 @@ export const PathSegmentPlural: Oas3Rule | Oas2Rule = (opts) => {
for (const pathSegment of pathSegments) {
if (exceptions && exceptions.includes(pathSegment)) continue;
if (!isPathParameter(pathSegment) && isSingular(pathSegment)) {
if (!isPathParameter(pathSegment) && pluralize.isSingular(pathSegment)) {
report({
message: `path segment \`${pathSegment}\` should be plural.`,
location: location.key(),

View File

@@ -2,14 +2,14 @@ import * as fs from 'fs';
import { extname } from 'path';
import * as minimatch from 'minimatch';
import fetch from 'node-fetch';
import * as pluralize from 'pluralize';
import { parseYaml } from './js-yaml';
import { UserContext } from './walk';
import { env } from './env';
import { logger, colorize } from './logger';
import { HttpResolveConfig } from './config';
import { HttpsProxyAgent } from 'https-proxy-agent';
import type { HttpResolveConfig } from './config';
import type { UserContext } from './walk';
export { parseYaml, stringifyYaml } from './js-yaml';
export type StackFrame<T> = {
@@ -146,10 +146,6 @@ export function validateMimeTypeOAS3(
}
}
export function isSingular(path: string) {
return pluralize.isSingular(path);
}
export function readFileAsStringSync(filePath: string) {
return fs.readFileSync(filePath, 'utf-8');
}
@@ -267,7 +263,7 @@ export function pickDefined<T extends Record<string, unknown>>(
}
export function nextTick() {
new Promise((resolve) => {
return new Promise((resolve) => {
setTimeout(resolve);
});
}