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

openapi-types: support x- specification extensions everywhere without a pre-existing index signature #899

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mitchell-merry
Copy link

@mitchell-merry mitchell-merry commented Mar 7, 2024

Fixes #768

Per the Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1 specs, most objects should support ^x- properties for the purposes of extending the specification. However, openapi-types does not support these yet.

This PR introduces the Extensible interface, which is used to specify the types that should support this. It also bumps the prettier package to 2.2.0, which is the earliest version which supports TypeScript templating strings.

As is, this PR contains breaking changes to the types, to better fit the specfication! See details in the comments.

Interested to hear your thoughts!

@@ -92,9 +97,10 @@ export namespace OpenAPIV3_1 {
>;

export type PathsObject<T extends {} = {}, P extends {} = {}> = Record<
string,
`/${string}`,
Copy link
Author

Choose a reason for hiding this comment

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

⚠️ This is a breaking change! We constrain the key to be /${string}, as the specification states.

We need to do this because otherwise this index signature (generic string) would shadow the x-${string} signature.

@@ -214,9 +222,10 @@ export namespace OpenAPIV3_1 {
>;

export type ResponsesObject = Record<
string,
`${string}`,
Copy link
Author

Choose a reason for hiding this comment

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

@@ -234,6 +243,7 @@ export namespace OpenAPIV3_1 {
}
>;

// TODO comment
export type CallbackObject = Record<string, PathItemObject | ReferenceObject>;
Copy link
Author

Choose a reason for hiding this comment

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

This is extensible according to the specification, but a limitation of TypeScript means we can't add the x-${string} signature as it would be shadowed by the string one (which we can't constrain any further).

@@ -509,6 +523,7 @@ export namespace OpenAPIV3 {
server?: ServerObject;
}

// TODO comment
export interface CallbackObject {
Copy link
Author

Choose a reason for hiding this comment

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

@@ -641,6 +656,7 @@ export namespace OpenAPIV2 {
| SecuritySchemeOauth2Password
| SecuritySchemeOauth2Application;

// TODO comment
export interface ScopesObject {
Copy link
Author

Choose a reason for hiding this comment

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

@@ -817,12 +829,13 @@ export namespace OpenAPIV2 {
}

export interface ExternalDocumentationObject {
// TODO comment
[index: string]: any;
Copy link
Author

Choose a reason for hiding this comment

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

@@ -843,6 +856,7 @@ export namespace OpenAPIV2 {
$ref?: string;
}

// TODO comment
export interface XMLObject {
Copy link
Author

Choose a reason for hiding this comment

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

@@ -182,7 +188,8 @@ export namespace OpenAPIV3_1 {
}
>;

export type DiscriminatorObject = OpenAPIV3.DiscriminatorObject;
export type DiscriminatorObject = OpenAPIV3.DiscriminatorObject &
Copy link
Author

Choose a reason for hiding this comment

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

This is extensible in 3.1, but not in 3.0 (or at least the specification doesn't explicitly call this out).

@mitchell-merry mitchell-merry changed the title [WIP] feat: support x- specification extensions everywhere without a pre-existing index signature feat: support x- specification extensions everywhere without a pre-existing index signature Mar 7, 2024
@mitchell-merry mitchell-merry marked this pull request as ready for review March 7, 2024 13:54
@mitchell-merry mitchell-merry changed the title feat: support x- specification extensions everywhere without a pre-existing index signature openapi-types: support x- specification extensions everywhere without a pre-existing index signature Mar 7, 2024
@jsdevel
Copy link
Contributor

jsdevel commented May 8, 2024

@mitchell-merry can you resolve conflicts and ensure a passing build?

@mitchell-merry
Copy link
Author

Merge conflict resolved, though it looks like you need to approve the build to be run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom Fields in Document
2 participants