From cb491c072893c784ca8563dcbce12b1a0a2f8b8d Mon Sep 17 00:00:00 2001 From: Jeremy Fiel Date: Thu, 17 Oct 2024 16:29:36 -0400 Subject: [PATCH] feat: add typings and interfaces for Overlay Specification v1.0.0 * updated references to use defined NodeTypes. * update `any` to `unknown` * run prettier related #1246 --- .changeset/stale-starfishes-rule.md | 6 ++++ packages/core/src/types/overlay.ts | 46 ++++++++++++++++++++++++++++ packages/core/src/typings/overlay.ts | 19 ++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .changeset/stale-starfishes-rule.md create mode 100644 packages/core/src/types/overlay.ts create mode 100644 packages/core/src/typings/overlay.ts diff --git a/.changeset/stale-starfishes-rule.md b/.changeset/stale-starfishes-rule.md new file mode 100644 index 000000000..6fc49d652 --- /dev/null +++ b/.changeset/stale-starfishes-rule.md @@ -0,0 +1,6 @@ +--- +"@redocly/openapi-core": minor +"@redocly/cli": minor +--- + +Add typings and interfaces for Overlay Specification v1.0.0 diff --git a/packages/core/src/types/overlay.ts b/packages/core/src/types/overlay.ts new file mode 100644 index 000000000..55abee46f --- /dev/null +++ b/packages/core/src/types/overlay.ts @@ -0,0 +1,46 @@ +import { type NodeType, type NormalizedScalarSchema, listOf } from '.'; + +const Root: NodeType = { + properties: { + overlay: { type: 'string' }, + info: 'Info', + extends: 'Extends', + actions: 'Actions', + }, + required: ['overlay', 'info', 'actions'], + extensionsPrefix: 'x-', +}; + +const Info: NodeType = { + properties: { + title: { type: 'string' }, + version: { type: 'string' }, + }, + required: ['title', 'version'], + extensionsPrefix: 'x-', +}; + +const Extends: NormalizedScalarSchema = { + type: 'string', + resolvable: true, +}; + +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 OverlayTypes: Record = { + Root, + Info, + Extends, + Actions, + Action, +}; diff --git a/packages/core/src/typings/overlay.ts b/packages/core/src/typings/overlay.ts new file mode 100644 index 000000000..1d854072e --- /dev/null +++ b/packages/core/src/typings/overlay.ts @@ -0,0 +1,19 @@ +export interface InfoObject { + title: string; + version: string; +} + +export interface ActionObject { + target: string; + description?: string; + update?: unknown; + remove?: boolean; +} +export interface OverlayDefinition { + overlay: '1.0.0'; + info: InfoObject; + extends?: string; + actions: ActionObject[]; +} + +export const VERSION_PATTERN = /^1\.0\.\d+(-.+)?$/;