Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typings): update OpenAPI 3.0 and 3.1 typing declarations #1795

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-pandas-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/openapi-core": patch
---

Updated typings for OAS 3.0 and OAS 3.1 Schemas.
2 changes: 2 additions & 0 deletions packages/core/src/types/oas3_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export const Schema: NodeType = {
const: null,
$comment: { type: 'string' },
'x-tags': { type: 'array', items: { type: 'string' } },
$dynamicAnchor: { type: 'string' },
$dynamicRef: { type: 'string' },
},
extensionsPrefix: 'x-',
};
Expand Down
74 changes: 54 additions & 20 deletions packages/core/src/typings/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ export interface Oas3Parameter {
explode?: boolean;
allowReserved?: boolean;
schema?: Referenced<Oas3Schema>;
example?: any;
example?: unknown;
examples?: { [media: string]: Referenced<Oas3Example> };
content?: { [media: string]: Oas3MediaType };
}

export interface Oas3Example {
value: any;
value: unknown;
summary?: string;
description?: string;
externalValue?: string;
Expand All @@ -112,32 +112,22 @@ export interface Oas3Xml {
}

// common fields for OpenAPI Schema v3.x
interface Oas3XSchemaBase<T> {
interface Oas3XSchemaBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using the generic interface because it's less likely for the common properties to diverge. Not sure which approach would be cleaner though. Why did you decide to change the approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the keywords which utilized the generic interface were moved into the Oas3Schema and Oas3_1Schema. So it was unused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but what was the reason for moving the keywords from Oas3XSchemaBase? Was there an issue with leaving them as they were?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they have different behavior between 30 asd 31. So the extension of Oas3XSchemaBase was incorrect and the keywords should be assigned to each version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll test that once I have time. Thank you for contributing!

$ref?: string;
properties?: { [name: string]: T };
additionalProperties?: boolean | T;
description?: string;
default?: any;
items?: T;
default?: unknown;
required?: string[];
readOnly?: boolean;
writeOnly?: boolean;
deprecated?: boolean;
format?: string;
externalDocs?: Oas3ExternalDocs;
discriminator?: Oas3Discriminator;
nullable?: boolean;
oneOf?: T[];
anyOf?: T[];
allOf?: T[];
not?: T;

title?: string;
multipleOf?: number;
maximum?: number;
exclusiveMaximum?: boolean;
minimum?: number;
exclusiveMinimum?: boolean;
maxLength?: number;
minLength?: number;
pattern?: string;
Expand All @@ -146,21 +136,65 @@ interface Oas3XSchemaBase<T> {
uniqueItems?: boolean;
maxProperties?: number;
minProperties?: number;
enum?: any[];
example?: any;
enum?: unknown[];
example?: unknown;

xml?: Oas3Xml;
'x-tags'?: string[];
}

export interface Oas3Schema extends Oas3XSchemaBase<Oas3Schema> {
export interface Oas3Schema extends Oas3XSchemaBase {
type?: string;
properties?: { [name: string]: Referenced<Oas3Schema> };
additionalProperties?: boolean | Oas3Schema;
items?: Oas3Schema;
exclusiveMaximum?: boolean;
exclusiveMinimum?: boolean;
oneOf?: Oas3Schema[];
anyOf?: Oas3Schema[];
allOf?: Oas3Schema[];
not?: Oas3Schema;
nullable?: boolean;
}

export interface Oas3_1Schema extends Oas3XSchemaBase<Oas3_1Schema> {
export interface Oas3_1Schema extends Oas3XSchemaBase {
$id?: string;
id?: string;
$anchor?: string;
$dynamicAnchor?: string;
$dynamicRef?: string;
definitions?: { [name: string]: Referenced<Oas3_1Schema> };
$defs?: { [name: string]: Referenced<Oas3_1Schema> };
$vocabulary?: { [uri: string]: boolean };
$comment?: string;
type?: string | string[];
examples?: any[];
properties?: { [name: string]: Referenced<Oas3_1Schema> };
additionalProperties?: boolean | Oas3_1Schema;
examples?: unknown[];
prefixItems?: Oas3_1Schema[];
items?: Oas3_1Schema;
oneOf?: Oas3_1Schema[];
anyOf?: Oas3_1Schema[];
allOf?: Oas3_1Schema[];
not?: Oas3_1Schema;
exclusiveMaximum?: number;
exclusiveMinimum?: number;
const?: unknown;
contains?: Oas3_1Schema;
minContains?: number;
maxContains?: number;
propertyNames?: Oas3_1Schema;
if?: Oas3_1Schema;
then?: Oas3_1Schema;
else?: Oas3_1Schema;
dependentRequired?: { [name: string]: string[] };
dependentSchemas?: { [name: string]: Referenced<Oas3_1Schema> };
patternProperties?: { [name: string]: Referenced<Oas3_1Schema> };
unevaluatedItems?: Oas3_1Schema;
unevaluatedProperties?: Oas3_1Schema;
contentSchema?: Oas3_1Schema;
contentMediaType?: string;
contentEncoding?: string;
}

export interface Oas3_1Definition extends Oas3Definition {
Expand All @@ -179,7 +213,7 @@ export interface Oas3Discriminator {

export interface Oas3MediaType {
schema?: Referenced<Oas3Schema>;
example?: any;
example?: unknown;
examples?: { [name: string]: Referenced<Oas3Example> };
encoding?: { [field: string]: Oas3Encoding };
}
Expand Down
Loading