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`

related #1246
  • Loading branch information
jeremyfiel committed Oct 28, 2024
1 parent 6522bc0 commit ddfc391
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 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
46 changes: 46 additions & 0 deletions packages/core/src/types/overlay.ts
Original file line number Diff line number Diff line change
@@ -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<string, NodeType | NormalizedScalarSchema> = {
Root,
Info,
Extends,
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 OverlayDefinition {
overlay: '1.0.0';
info: InfoObject;
extends?: string;
actions: ActionObject[];
}

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

0 comments on commit ddfc391

Please sign in to comment.