From b4a8afe05ad44cec1eab472426e15866f7913ca6 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 7 Apr 2026 01:03:24 +0200 Subject: [PATCH] test: fix typecheck --- .changeset/deep-paws-call.md | 5 +++ .changeset/olive-sides-mate.md | 5 +++ packages/shared/src/ir/types.ts | 10 ++--- .../src/json-schema/draft-2020-12/spec.ts | 43 ++++++++++--------- packages/spec-types/src/openapi/v2/spec.ts | 2 +- packages/spec-types/src/openapi/v3-1/spec.ts | 12 +++--- 6 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 .changeset/deep-paws-call.md create mode 100644 .changeset/olive-sides-mate.md diff --git a/.changeset/deep-paws-call.md b/.changeset/deep-paws-call.md new file mode 100644 index 000000000..d04da00ee --- /dev/null +++ b/.changeset/deep-paws-call.md @@ -0,0 +1,5 @@ +--- +"@hey-api/spec-types": minor +--- + +**BREAKING**: rename `OpenAPIExtensions` to `SpecExtensions` diff --git a/.changeset/olive-sides-mate.md b/.changeset/olive-sides-mate.md new file mode 100644 index 000000000..f624896f9 --- /dev/null +++ b/.changeset/olive-sides-mate.md @@ -0,0 +1,5 @@ +--- +"@hey-api/spec-types": minor +--- + +**BREAKING**: remove OpenAPI types from JSON Schema documents diff --git a/packages/shared/src/ir/types.ts b/packages/shared/src/ir/types.ts index b4a6c150b..e2a4876d8 100644 --- a/packages/shared/src/ir/types.ts +++ b/packages/shared/src/ir/types.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-namespace */ import type { Symbol } from '@hey-api/codegen-core'; -import type { JSONSchemaDraft2020_12, OpenAPIExtensions, OpenAPIV3_1 } from '@hey-api/spec-types'; +import type { JSONSchemaDraft2020_12, OpenAPIV3_1, SpecExtensions } from '@hey-api/spec-types'; import type { IRMediaType } from './mediaType'; @@ -22,7 +22,7 @@ interface IRComponentsObject { schemas?: Record; } -export interface IROperationObject extends OpenAPIExtensions { +export interface IROperationObject extends SpecExtensions { body?: IRBodyObject; deprecated?: boolean; description?: string; @@ -46,7 +46,7 @@ export interface IRParametersObject { } export interface IRParameterObject - extends Pick, OpenAPIExtensions { + extends Pick, SpecExtensions { /** * Determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 `:/?#[]@!$&'()*+,;=` to be included without percent-encoding. The default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of `contentType` (implicit or explicit) SHALL be ignored. */ @@ -130,9 +130,9 @@ export interface IRSchemaObject | 'pattern' | 'required' | 'title' - | 'example' >, - OpenAPIExtensions { + Pick, + SpecExtensions { /** * If the schema is intended to be used as an object property, it can be * marked as read-only or write-only. This value controls whether the schema diff --git a/packages/spec-types/src/json-schema/draft-2020-12/spec.ts b/packages/spec-types/src/json-schema/draft-2020-12/spec.ts index 16a8fd013..9b203ab7e 100644 --- a/packages/spec-types/src/json-schema/draft-2020-12/spec.ts +++ b/packages/spec-types/src/json-schema/draft-2020-12/spec.ts @@ -1,7 +1,8 @@ import type { AnyString, MaybeArray } from '@hey-api/types'; // TODO: left out some keywords related to structuring a complex schema and declaring a dialect -export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, StringKeywords { +export interface BaseDocument + extends ArrayKeywords, NumberKeywords, ObjectKeywords, StringKeywords { /** * The `$comment` {@link https://json-schema.org/learn/glossary#keyword keyword} is strictly intended for adding comments to a schema. Its value must always be a string. Unlike the annotations `title`, `description`, and `examples`, JSON schema {@link https://json-schema.org/learn/glossary#implementation implementations} aren't allowed to attach any meaning or behavior to it whatsoever, and may even strip them at any time. Therefore, they are useful for leaving notes to future editors of a JSON schema, but should not be used to communicate to users of the schema. */ @@ -19,13 +20,13 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, * * {@link https://json-schema.org/understanding-json-schema/reference/combining#allof allOf} can not be used to "extend" a schema to add more details to it in the sense of object-oriented inheritance. {@link https://json-schema.org/learn/glossary#instance Instances} must independently be valid against "all of" the schemas in the `allOf`. See the section on {@link https://json-schema.org/understanding-json-schema/reference/object#extending Extending Closed Schemas} for more information. */ - allOf?: Array; + allOf?: Array; /** * `anyOf`: (OR) Must be valid against _any_ of the subschemas * * To validate against `anyOf`, the given data must be valid against any (one or more) of the given subschemas. */ - anyOf?: Array; + anyOf?: Array; /** * The `const` keyword is used to restrict a value to a single value. */ @@ -55,7 +56,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, /** * The `dependentSchemas` keyword conditionally applies a {@link https://json-schema.org/learn/glossary#subschema subschema} when a given property is present. This schema is applied in the same way {@link https://json-schema.org/understanding-json-schema/reference/combining#allof allOf} applies schemas. Nothing is merged or extended. Both schemas apply independently. */ - dependentSchemas?: Record; + dependentSchemas?: Record; /** * The `deprecated` keyword is a boolean that indicates that the {@link https://json-schema.org/learn/glossary#instance instance} value the keyword applies to should not be used and may be removed in the future. */ @@ -73,7 +74,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, * * If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored. */ - else?: Document; + else?: TDocument; /** * The `enum` {@link https://json-schema.org/learn/glossary#keyword keyword} is used to restrict a value to a fixed set of values. It must be an array with at least one element, where each element is unique. * @@ -101,13 +102,13 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, * * If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored. */ - if?: Document; + if?: TDocument; /** * `not`: (NOT) Must _not_ be valid against the given schema * * The `not` keyword declares that an instance validates if it doesn't validate against the given subschema. */ - not?: Document; + not?: TDocument; /** * `oneOf`: (XOR) Must be valid against _exactly one_ of the subschemas * @@ -115,7 +116,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, * * Careful consideration should be taken when using `oneOf` entries as the nature of it requires verification of _every_ sub-schema which can lead to increased processing times. Prefer `anyOf` where possible. */ - oneOf?: Array; + oneOf?: Array; /** * The boolean keywords `readOnly` and `writeOnly` are typically used in an API context. `readOnly` indicates that a value should not be modified. It could be used to indicate that a `PUT` request that changes a value would result in a `400 Bad Request` response. `writeOnly` indicates that a value may be set, but will remain hidden. In could be used to indicate you can set a value with a `PUT` request, but it would not be included when retrieving that record with a `GET` request. */ @@ -129,7 +130,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, * * If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored. */ - then?: Document; + then?: TDocument; /** * The `title` and `description` keywords must be strings. A "title" will preferably be short, whereas a "description" will provide a more lengthy explanation about the purpose of the data described by the schema. */ @@ -144,11 +145,13 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, writeOnly?: boolean; } -export interface ArrayKeywords { +export type Document = BaseDocument; + +export interface ArrayKeywords { /** * While the `items` schema must be valid for every item in the array, the `contains` schema only needs to validate against one or more items in the array. */ - contains?: Document; + contains?: TDocument; /** * List validation is useful for arrays of arbitrary length where each item matches the same schema. For this kind of array, set the `items` {@link https://json-schema.org/learn/glossary#keyword keyword} to a single schema that will be used to validate all of the items in the array. * @@ -156,7 +159,7 @@ export interface ArrayKeywords { * * Note that `items` doesn't "see inside" any {@link https://json-schema.org/learn/glossary#instance instances} of `allOf`, `anyOf`, or `oneOf` in the same {@link https://json-schema.org/learn/glossary#subschema subschema}. */ - items?: Document | false; + items?: TDocument | false; /** * `minContains` and `maxContains` can be used with `contains` to further specify how many times a schema matches a `contains` constraint. These keywords can be any non-negative number including zero. */ @@ -176,7 +179,7 @@ export interface ArrayKeywords { /** * `prefixItems` is an array, where each item is a schema that corresponds to each index of the document's array. That is, an array where the first element validates the first element of the input array, the second element validates the second element of the input array, etc. */ - prefixItems?: Array; + prefixItems?: Array; /** * The `unevaluatedItems` keyword is useful mainly when you want to add or disallow extra items to an array. * @@ -186,7 +189,7 @@ export interface ArrayKeywords { * * Like with `items`, if you set `unevaluatedItems` to false, you can disallow extra items in the array. */ - unevaluatedItems?: Document | false; + unevaluatedItems?: TDocument | false; /** * A schema can ensure that each of the items in an array is unique. Simply set the `uniqueItems` keyword to `true`. */ @@ -260,7 +263,7 @@ export interface NumberKeywords { multipleOf?: number; } -export interface ObjectKeywords { +export interface ObjectKeywords { /** * The `additionalProperties` keyword is used to control the handling of extra stuff, that is, properties whose names are not listed in the `properties` keyword or match any of the regular expressions in the `patternProperties` keyword. By default any additional properties are allowed. * @@ -268,7 +271,7 @@ export interface ObjectKeywords { * * It's important to note that `additionalProperties` only recognizes properties declared in the same {@link https://json-schema.org/learn/glossary#subschema subschema} as itself. So, `additionalProperties` can restrict you from "extending" a schema using {@link https://json-schema.org/understanding-json-schema/reference/combining combining} keywords such as {@link https://json-schema.org/understanding-json-schema/reference/combining#allof allOf}. */ - additionalProperties?: Document | false; + additionalProperties?: TDocument | false; /** * The number of properties on an object can be restricted using the `minProperties` and `maxProperties` keywords. Each of these must be a non-negative integer. */ @@ -280,11 +283,11 @@ export interface ObjectKeywords { /** * Sometimes you want to say that, given a particular kind of property name, the value should match a particular schema. That's where `patternProperties` comes in: it maps regular expressions to schemas. If a property name matches the given regular expression, the property value must validate against the corresponding schema. */ - patternProperties?: Record; + patternProperties?: Record; /** * The properties (key-value pairs) on an object are defined using the `properties` {@link https://json-schema.org/learn/glossary#keyword keyword}. The value of `properties` is an object, where each key is the name of a property and each value is a {@link https://json-schema.org/learn/glossary#schema schema} used to validate that property. Any property that doesn't match any of the property names in the `properties` keyword is ignored by this keyword. */ - properties?: Record; + properties?: Record; /** * The names of properties can be validated against a schema, irrespective of their values. This can be useful if you don't want to enforce specific properties, but you want to make sure that the names of those properties follow a specific convention. You might, for example, want to enforce that all names are valid ASCII tokens so they can be used as attributes in a particular programming language. * @@ -294,7 +297,7 @@ export interface ObjectKeywords { * { "type": "string" } * ``` */ - propertyNames?: Document; + propertyNames?: TDocument; /** * By default, the properties defined by the `properties` keyword are not required. However, one can provide a list of required properties using the `required` keyword. * @@ -306,7 +309,7 @@ export interface ObjectKeywords { * * `unevaluatedProperties` works by collecting any properties that are successfully validated when processing the schemas and using those as the allowed list of properties. This allows you to do more complex things like conditionally adding properties. */ - unevaluatedProperties?: Document | false; + unevaluatedProperties?: TDocument | false; } export interface StringKeywords { diff --git a/packages/spec-types/src/openapi/v2/spec.ts b/packages/spec-types/src/openapi/v2/spec.ts index be939339a..e60800e5a 100644 --- a/packages/spec-types/src/openapi/v2/spec.ts +++ b/packages/spec-types/src/openapi/v2/spec.ts @@ -1,6 +1,6 @@ import type { CodeSampleObject } from '../../extensions/code-samples'; import type { EnumExtensions } from '../../extensions/enum'; -import type { Document as JSONSchemaDraft4 } from '../../json-schema/draft-4/spec'; +import type { Document as JSONSchemaDraft4 } from '../../json-schema/draft-4'; import type { OpenAPIV2NullableExtensions } from './extensions'; /** diff --git a/packages/spec-types/src/openapi/v3-1/spec.ts b/packages/spec-types/src/openapi/v3-1/spec.ts index b4e9d14af..e4b579356 100644 --- a/packages/spec-types/src/openapi/v3-1/spec.ts +++ b/packages/spec-types/src/openapi/v3-1/spec.ts @@ -1,7 +1,7 @@ import type { CodeSampleObject } from '../../extensions/code-samples'; import type { EnumExtensions } from '../../extensions/enum'; import type { SpecExtensions } from '../../extensions/spec'; -import type { Document as JSONSchemaDraft2020_12 } from '../../json-schema/draft-2020-12'; +import type { BaseDocument as JSONSchemaDraft2020_12 } from '../../json-schema/draft-2020-12'; import type { OpenAPIV3_1SchemaExtensions } from './extensions'; /** @@ -1668,10 +1668,12 @@ export interface ResponsesObject extends SpecExtensions { * * This object MAY be extended with {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specification-extensions Specification Extensions}, though as noted, additional properties MAY omit the `x-` prefix within this object. */ -export type SchemaObject = JSONSchemaDraft2020_12 & - OpenAPIV3_1SchemaExtensions & - SpecExtensions & - EnumExtensions; +export interface SchemaObject + extends + JSONSchemaDraft2020_12, + OpenAPIV3_1SchemaExtensions, + SpecExtensions, + EnumExtensions {} /** * Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsSecuritySchemes Security Schemes} under the {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#components-object Components Object}. -- 2.51.2