Skip to content

Commit

Permalink
feat: add support for Overlay v1 documents
Browse files Browse the repository at this point in the history
* linting
* preprocessors
* decorators
* type extensions
  • Loading branch information
jeremyfiel committed Feb 10, 2025
1 parent f4cdd75 commit b9f71e5
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .changeset/funny-lobsters-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": minor
"@redocly/cli": minor
---

Added support for linting, preprocessors, decorators, and type extensions for Overlay v1 documents.
6 changes: 0 additions & 6 deletions .changeset/stale-starfishes-rule.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`E2E build-docs build docs with config option 1`] = `
Found nested/redocly.yaml and using theme.openapi options
Prerendering docs
🎉 bundled successfully in: nested/redoc-static.html (36 KiB) [⏱ <test>ms].
🎉 bundled successfully in: nested/redoc-static.html (33 KiB) [⏱ <test>ms].
`;
2 changes: 1 addition & 1 deletion __tests__/build-docs/simple-build-docs/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`E2E build-docs simple build-docs 1`] = `
Found undefined and using theme.openapi options
Prerendering docs
🎉 bundled successfully in: redoc-static.html (330 KiB) [⏱ <test>ms].
🎉 bundled successfully in: redoc-static.html (324 KiB) [⏱ <test>ms].
`;
1 change: 1 addition & 0 deletions packages/cli/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ describe('checkIfRulesetExist', () => {
async2: {},
async3: {},
arazzo1: {},
overlay1: {},
};
expect(() => checkIfRulesetExist(rules)).toThrowError(
'⚠️ No rules were configured. Learn how to configure rules: https://redocly.com/docs/cli/rules/'
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function commandWrapper<T extends CommandOptions>(
? 'asyncapi'
: document?.arazzo
? 'arazzo'
: document?.overlay
? 'overlay'
: undefined;
if (specKeyword) {
specFullVersion = document[specKeyword] as string;
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ export function mapTypeToComponent(typeName: string, version: SpecMajorVersion)
default:
return null;
}
case SpecMajorVersion.Overlay1:
switch (typeName) {
default:
return null;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ exports[`resolveConfig should ignore minimal from the root and read local file 1
"tag-description": "warn",
"tags-alphabetical": "off",
},
"overlay1Decorators": {},
"overlay1Preprocessors": {},
"overlay1Rules": {},
"preprocessors": {},
"recommendedFallback": false,
"rules": {
Expand Down Expand Up @@ -437,6 +440,9 @@ exports[`resolveStyleguideConfig should resolve extends with local file config w
"tag-description": "warn",
"tags-alphabetical": "off",
},
"overlay1Decorators": {},
"overlay1Preprocessors": {},
"overlay1Rules": {},
"preprocessors": {},
"recommendedFallback": undefined,
"rules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ StyleguideConfig {
"oas3_0": {},
"oas3_1": {},
},
"overlay1": {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
},
},
"doNotResolveExamples": false,
"extendPaths": [],
Expand Down Expand Up @@ -76,6 +81,11 @@ StyleguideConfig {
"oas3_0": {},
"oas3_1": {},
},
"overlay1": {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
},
},
"rawConfig": {
"_usedRules": Set {},
Expand Down Expand Up @@ -203,6 +213,20 @@ StyleguideConfig {
"operation-summary": "error",
},
},
"overlay1": {
"oas2": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas3_0": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas3_1": {
"no-empty-servers": "error",
"operation-summary": "error",
},
},
},
}
`;
11 changes: 11 additions & 0 deletions packages/core/src/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('getMergedConfig', () => {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
"overlay1": {},
},
"doNotResolveExamples": false,
"extendPaths": [],
Expand All @@ -136,6 +137,7 @@ describe('getMergedConfig', () => {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
"overlay1": {},
},
"rawConfig": {
"extendPaths": [],
Expand Down Expand Up @@ -164,6 +166,9 @@ describe('getMergedConfig', () => {
"oas3_1": {
"operation-summary": "warn",
},
"overlay1": {
"operation-summary": "warn",
},
},
},
"telemetry": "on",
Expand Down Expand Up @@ -238,6 +243,7 @@ describe('getMergedConfig', () => {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
"overlay1": {},
},
"doNotResolveExamples": false,
"extendPaths": [],
Expand All @@ -251,6 +257,7 @@ describe('getMergedConfig', () => {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
"overlay1": {},
},
"rawConfig": {
"extendPaths": [],
Expand Down Expand Up @@ -287,6 +294,10 @@ describe('getMergedConfig', () => {
"no-empty-servers": "error",
"operation-summary": "error",
},
"overlay1": {
"no-empty-servers": "error",
"operation-summary": "error",
},
},
},
"telemetry": "on",
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
Async2RuleSet,
Async3RuleSet,
Arazzo1RuleSet,
Overlay1RuleSet,
} from '../oas-types';
import type { NodeType } from '../types';
import type {
Expand Down Expand Up @@ -75,6 +76,7 @@ export class StyleguideConfig {
'async2Rules',
'async3Rules',
'arazzo1Rules',
'overlay1Rules',
];

replaceSpecWithStruct(ruleGroups, rawConfig);
Expand All @@ -86,6 +88,7 @@ export class StyleguideConfig {
[SpecVersion.Async2]: { ...rawConfig.rules, ...rawConfig.async2Rules },
[SpecVersion.Async3]: { ...rawConfig.rules, ...rawConfig.async3Rules },
[SpecVersion.Arazzo1]: { ...rawConfig.rules, ...rawConfig.arazzo1Rules },
[SpecVersion.Overlay1]: { ...rawConfig.rules, ...rawConfig.overlay1Rules },
};

this.preprocessors = {
Expand All @@ -95,6 +98,7 @@ export class StyleguideConfig {
[SpecVersion.Async2]: { ...rawConfig.preprocessors, ...rawConfig.async2Preprocessors },
[SpecVersion.Async3]: { ...rawConfig.preprocessors, ...rawConfig.async3Preprocessors },
[SpecVersion.Arazzo1]: { ...rawConfig.arazzo1Preprocessors },
[SpecVersion.Overlay1]: { ...rawConfig.preprocessors, ...rawConfig.overlay1Preprocessors },
};

this.decorators = {
Expand All @@ -104,6 +108,7 @@ export class StyleguideConfig {
[SpecVersion.Async2]: { ...rawConfig.decorators, ...rawConfig.async2Decorators },
[SpecVersion.Async3]: { ...rawConfig.decorators, ...rawConfig.async3Decorators },
[SpecVersion.Arazzo1]: { ...rawConfig.arazzo1Decorators },
[SpecVersion.Overlay1]: { ...rawConfig.decorators, ...rawConfig.overlay1Decorators },
};

this.extendPaths = rawConfig.extendPaths || [];
Expand Down Expand Up @@ -207,6 +212,10 @@ export class StyleguideConfig {
if (!plugin.typeExtension.arazzo1) continue;
extendedTypes = plugin.typeExtension.arazzo1(extendedTypes, version);
break;
case SpecVersion.Overlay1:
if (!plugin.typeExtension.overlay1) continue;
extendedTypes = plugin.typeExtension.overlay1(extendedTypes, version);
break;
default:
throw new Error('Not implemented');
}
Expand Down Expand Up @@ -328,6 +337,17 @@ export class StyleguideConfig {
(p) => p.decorators?.arazzo1 && arazzo1Rules.push(p.decorators.arazzo1)
);
return arazzo1Rules;
case SpecMajorVersion.Overlay1:
// eslint-disable-next-line no-case-declarations
const overlay1Rules: Overlay1RuleSet[] = [];
this.plugins.forEach(
(p) => p.preprocessors?.overlay1 && overlay1Rules.push(p.preprocessors.overlay1)
);
this.plugins.forEach((p) => p.rules?.overlay1 && overlay1Rules.push(p.rules.overlay1));
this.plugins.forEach(
(p) => p.decorators?.overlay1 && overlay1Rules.push(p.decorators.overlay1)
);
return overlay1Rules;
}
}

Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/config/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Async3RuleSet,
Oas2RuleSet,
Oas3RuleSet,
Overlay1RuleSet,
SpecVersion,
} from '../oas-types';
import type { StyleguideConfig } from './config';
Expand All @@ -18,7 +19,14 @@ type InitializedRule = {
};

export function initRules(
rules: (Oas3RuleSet | Oas2RuleSet | Async2RuleSet | Async3RuleSet | Arazzo1RuleSet)[],
rules: (
| Oas3RuleSet
| Oas2RuleSet
| Async2RuleSet
| Async3RuleSet
| Arazzo1RuleSet
| Overlay1RuleSet
)[],
config: StyleguideConfig,
type: 'rules' | 'preprocessors' | 'decorators',
oasVersion: SpecVersion
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import type {
Arazzo1PreprocessorsSet,
Arazzo1DecoratorsSet,
RuleMap,
Overlay1PreprocessorsSet,
Overlay1DecoratorsSet,
Overlay1RuleSet,
} from '../oas-types';
import type { NodeType } from '../types';
import type { SkipFunctionContext } from '../visitors';
Expand Down Expand Up @@ -53,6 +56,7 @@ export type StyleguideRawConfig<T = undefined> = {
async2Rules?: RuleMap<string, RuleConfig, T>;
async3Rules?: RuleMap<string, RuleConfig, T>;
arazzo1Rules?: RuleMap<string, RuleConfig, T>;
overlay1Rules?: RuleMap<string, RuleConfig, T>;

preprocessors?: Record<string, PreprocessorConfig>;
oas2Preprocessors?: Record<string, PreprocessorConfig>;
Expand All @@ -61,6 +65,7 @@ export type StyleguideRawConfig<T = undefined> = {
async2Preprocessors?: Record<string, PreprocessorConfig>;
async3Preprocessors?: Record<string, PreprocessorConfig>;
arazzo1Preprocessors?: Record<string, PreprocessorConfig>;
overlay1Preprocessors?: Record<string, PreprocessorConfig>;

decorators?: Record<string, DecoratorConfig>;
oas2Decorators?: Record<string, DecoratorConfig>;
Expand All @@ -69,6 +74,7 @@ export type StyleguideRawConfig<T = undefined> = {
async2Decorators?: Record<string, DecoratorConfig>;
async3Decorators?: Record<string, DecoratorConfig>;
arazzo1Decorators?: Record<string, DecoratorConfig>;
overlay1Decorators?: Record<string, DecoratorConfig>;
};

export type ApiStyleguideRawConfig = Omit<StyleguideRawConfig, 'plugins'>;
Expand All @@ -87,6 +93,7 @@ export type PreprocessorsConfig = {
async2?: Async2PreprocessorsSet;
async3?: Async3PreprocessorsSet;
arazzo1?: Arazzo1PreprocessorsSet;
overlay1?: Overlay1PreprocessorsSet;
};

export type DecoratorsConfig = {
Expand All @@ -95,6 +102,7 @@ export type DecoratorsConfig = {
async2?: Async2DecoratorsSet;
async3?: Async3DecoratorsSet;
arazzo1?: Arazzo1DecoratorsSet;
overlay1?: Overlay1DecoratorsSet;
};

export type TypesExtensionFn = (
Expand All @@ -110,6 +118,7 @@ export type RulesConfig<T> = {
async2?: Async2RuleSet<T>;
async3?: Async3RuleSet<T>;
arazzo1?: Arazzo1RuleSet<T>;
overlay1?: Overlay1RuleSet<T>;
};

export type CustomRulesConfig = RulesConfig<undefined>;
Expand Down Expand Up @@ -278,17 +287,20 @@ export type RulesFields =
| 'async2Rules'
| 'async3Rules'
| 'arazzo1Rules'
| 'overlay1Rules'
| 'preprocessors'
| 'oas2Preprocessors'
| 'oas3_0Preprocessors'
| 'oas3_1Preprocessors'
| 'async2Preprocessors'
| 'async3Preprocessors'
| 'arazzo1Preprocessors'
| 'overlay1Preprocessors'
| 'decorators'
| 'oas2Decorators'
| 'oas3_0Decorators'
| 'oas3_1Decorators'
| 'async2Decorators'
| 'async3Decorators'
| 'arazzo1Decorators';
| 'arazzo1Decorators'
| 'overlay1Decorators';
Loading

0 comments on commit b9f71e5

Please sign in to comment.