Skip to content

Commit

Permalink
feat: add typings and interfaces for Overlay Specification v1.0.0
Browse files Browse the repository at this point in the history
* updated references to use defined NodeTypes.
* update `any` to `unknown`
* run prettier
* rebase latest changes from main
* refactor to match Redocly#1898 type definitions

related Redocly#1246
  • Loading branch information
jeremyfiel committed Feb 10, 2025
1 parent f0446c7 commit f2af14f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-starfishes-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": minor
"@redocly/cli": minor
---

Add typings and interfaces for Overlay Specification v1.0.0
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
40 changes: 40 additions & 0 deletions packages/core/src/types/overlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { type NodeType, listOf } from '.';

const Root: NodeType = {
properties: {
overlay: { type: 'string' },
info: 'Info',
extends: { type: 'string' },
actions: 'Actions',
},
required: ['overlay', 'info', 'actions'],
extensionsPrefix: 'x-',
};

const Info: NodeType = {
properties: {
title: { type: 'string' },
version: { type: 'string' },
},
required: ['title', 'version'],
extensionsPrefix: 'x-',
};

const Actions: NodeType = listOf('Action');
const Action: NodeType = {
properties: {
target: { type: 'string' },
description: { type: 'string' },
update: {}, // any
remove: { type: 'boolean' },
},
required: ['target'],
extensionsPrefix: 'x-',
};

export const Overlay1Types: Record<string, NodeType> = {
Root,
Info,
Actions,
Action,
};
19 changes: 19 additions & 0 deletions packages/core/src/typings/overlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface InfoObject {
title: string;
version: string;
}

export interface ActionObject {
target: string;
description?: string;
update?: unknown;
remove?: boolean;
}
export interface Overlay1Definition {
overlay: '1.0.0';
info: InfoObject;
extends?: string;
actions: ActionObject[];
}

export const VERSION_PATTERN = /^1\.0\.\d+(-.+)?$/;

0 comments on commit f2af14f

Please sign in to comment.