Skip to content

Commit

Permalink
chore: fix OasSchema types (Redocly#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens authored Jan 18, 2024
1 parent 4f410b5 commit 63aba31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/rules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import levenshtein = require('js-levenshtein');
import { UserContext } from '../walk';
import { Location } from '../ref-utils';
import { validateJsonSchema } from './ajv';
import { Oas3Schema, Referenced } from '../typings/openapi';
import { Oas3Schema, Oas3_1Schema, Referenced } from '../typings/openapi';
import { showErrorForDeprecatedField, showWarningForDeprecatedField } from '../utils';

export function oasTypeOf(value: unknown) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export function getSuggest(given: string, variants: string[]): string[] {

export function validateExample(
example: any,
schema: Referenced<Oas3Schema>,
schema: Referenced<Oas3Schema | Oas3_1Schema>,
dataLoc: Location,
{ resolve, location, report }: UserContext,
allowAdditionalProperties: boolean
Expand Down
26 changes: 15 additions & 11 deletions packages/core/src/typings/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ export interface Oas3Xml {
wrapped?: string;
}

export interface Oas3Schema {
// common fields for OpenAPI Schema v3.x
interface Oas3XSchemaBase<T> {
$ref?: string;
type?: string;
properties?: { [name: string]: Oas3Schema };
additionalProperties?: boolean | Oas3Schema;
properties?: { [name: string]: T };
additionalProperties?: boolean | T;
description?: string;
default?: any;
items?: Oas3Schema;
items?: T;
required?: string[];
readOnly?: boolean;
writeOnly?: boolean;
Expand All @@ -127,10 +127,10 @@ export interface Oas3Schema {
externalDocs?: Oas3ExternalDocs;
discriminator?: Oas3Discriminator;
nullable?: boolean;
oneOf?: Oas3Schema[];
anyOf?: Oas3Schema[];
allOf?: Oas3Schema[];
not?: Oas3Schema;
oneOf?: T[];
anyOf?: T[];
allOf?: T[];
not?: T;

title?: string;
multipleOf?: number;
Expand All @@ -153,11 +153,15 @@ export interface Oas3Schema {
'x-tags'?: string[];
}

export type Oas3_1Schema = Oas3Schema & {
export interface Oas3Schema extends Oas3XSchemaBase<Oas3Schema> {
type?: string;
}

export interface Oas3_1Schema extends Oas3XSchemaBase<Oas3_1Schema> {
type?: string | string[];
examples?: any[];
prefixItems?: Oas3_1Schema[];
};
}

export interface Oas3_1Definition extends Oas3Definition {
webhooks?: Oas3_1Webhooks;
Expand Down

0 comments on commit 63aba31

Please sign in to comment.