Skip to content

Commit b4a8afe

Browse files
committed
test: fix typecheck
1 parent 12fa7d6 commit b4a8afe

6 files changed

Lines changed: 46 additions & 31 deletions

File tree

.changeset/deep-paws-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/spec-types": minor
3+
---
4+
5+
**BREAKING**: rename `OpenAPIExtensions` to `SpecExtensions`

.changeset/olive-sides-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/spec-types": minor
3+
---
4+
5+
**BREAKING**: remove OpenAPI types from JSON Schema documents

packages/shared/src/ir/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-namespace */
22
import type { Symbol } from '@hey-api/codegen-core';
3-
import type { JSONSchemaDraft2020_12, OpenAPIExtensions, OpenAPIV3_1 } from '@hey-api/spec-types';
3+
import type { JSONSchemaDraft2020_12, OpenAPIV3_1, SpecExtensions } from '@hey-api/spec-types';
44

55
import type { IRMediaType } from './mediaType';
66

@@ -22,7 +22,7 @@ interface IRComponentsObject {
2222
schemas?: Record<string, IRSchemaObject>;
2323
}
2424

25-
export interface IROperationObject extends OpenAPIExtensions {
25+
export interface IROperationObject extends SpecExtensions {
2626
body?: IRBodyObject;
2727
deprecated?: boolean;
2828
description?: string;
@@ -46,7 +46,7 @@ export interface IRParametersObject {
4646
}
4747

4848
export interface IRParameterObject
49-
extends Pick<JSONSchemaDraft2020_12.Document, 'deprecated' | 'description'>, OpenAPIExtensions {
49+
extends Pick<JSONSchemaDraft2020_12.Document, 'deprecated' | 'description'>, SpecExtensions {
5050
/**
5151
* 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.
5252
*/
@@ -130,9 +130,9 @@ export interface IRSchemaObject
130130
| 'pattern'
131131
| 'required'
132132
| 'title'
133-
| 'example'
134133
>,
135-
OpenAPIExtensions {
134+
Pick<OpenAPIV3_1.SchemaObject, 'example'>,
135+
SpecExtensions {
136136
/**
137137
* If the schema is intended to be used as an object property, it can be
138138
* marked as read-only or write-only. This value controls whether the schema

packages/spec-types/src/json-schema/draft-2020-12/spec.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { AnyString, MaybeArray } from '@hey-api/types';
22

33
// TODO: left out some keywords related to structuring a complex schema and declaring a dialect
4-
export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords, StringKeywords {
4+
export interface BaseDocument<TDocument = unknown>
5+
extends ArrayKeywords<TDocument>, NumberKeywords, ObjectKeywords<TDocument>, StringKeywords {
56
/**
67
* 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.
78
*/
@@ -19,13 +20,13 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
1920
*
2021
* {@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.
2122
*/
22-
allOf?: Array<Document>;
23+
allOf?: Array<TDocument>;
2324
/**
2425
* `anyOf`: (OR) Must be valid against _any_ of the subschemas
2526
*
2627
* To validate against `anyOf`, the given data must be valid against any (one or more) of the given subschemas.
2728
*/
28-
anyOf?: Array<Document>;
29+
anyOf?: Array<TDocument>;
2930
/**
3031
* The `const` keyword is used to restrict a value to a single value.
3132
*/
@@ -55,7 +56,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
5556
/**
5657
* 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.
5758
*/
58-
dependentSchemas?: Record<string, Document>;
59+
dependentSchemas?: Record<string, TDocument>;
5960
/**
6061
* 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.
6162
*/
@@ -73,7 +74,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
7374
*
7475
* If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored.
7576
*/
76-
else?: Document;
77+
else?: TDocument;
7778
/**
7879
* 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.
7980
*
@@ -101,21 +102,21 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
101102
*
102103
* If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored.
103104
*/
104-
if?: Document;
105+
if?: TDocument;
105106
/**
106107
* `not`: (NOT) Must _not_ be valid against the given schema
107108
*
108109
* The `not` keyword declares that an instance validates if it doesn't validate against the given subschema.
109110
*/
110-
not?: Document;
111+
not?: TDocument;
111112
/**
112113
* `oneOf`: (XOR) Must be valid against _exactly one_ of the subschemas
113114
*
114115
* To validate against `oneOf`, the given data must be valid against exactly one of the given subschemas.
115116
*
116117
* 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.
117118
*/
118-
oneOf?: Array<Document>;
119+
oneOf?: Array<TDocument>;
119120
/**
120121
* 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.
121122
*/
@@ -129,7 +130,7 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
129130
*
130131
* If `then` and/or `else` appear in a schema without `if`, `then` and `else` are ignored.
131132
*/
132-
then?: Document;
133+
then?: TDocument;
133134
/**
134135
* 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.
135136
*/
@@ -144,19 +145,21 @@ export interface Document extends ArrayKeywords, NumberKeywords, ObjectKeywords,
144145
writeOnly?: boolean;
145146
}
146147

147-
export interface ArrayKeywords {
148+
export type Document = BaseDocument<Document>;
149+
150+
export interface ArrayKeywords<TDocument = unknown> {
148151
/**
149152
* 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.
150153
*/
151-
contains?: Document;
154+
contains?: TDocument;
152155
/**
153156
* 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.
154157
*
155158
* The `items` keyword can be used to control whether it's valid to have additional items in a tuple beyond what is defined in `prefixItems`. The value of the `items` keyword is a schema that all additional items must pass in order for the keyword to validate.
156159
*
157160
* 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}.
158161
*/
159-
items?: Document | false;
162+
items?: TDocument | false;
160163
/**
161164
* `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.
162165
*/
@@ -176,7 +179,7 @@ export interface ArrayKeywords {
176179
/**
177180
* `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.
178181
*/
179-
prefixItems?: Array<Document>;
182+
prefixItems?: Array<TDocument>;
180183
/**
181184
* The `unevaluatedItems` keyword is useful mainly when you want to add or disallow extra items to an array.
182185
*
@@ -186,7 +189,7 @@ export interface ArrayKeywords {
186189
*
187190
* Like with `items`, if you set `unevaluatedItems` to false, you can disallow extra items in the array.
188191
*/
189-
unevaluatedItems?: Document | false;
192+
unevaluatedItems?: TDocument | false;
190193
/**
191194
* A schema can ensure that each of the items in an array is unique. Simply set the `uniqueItems` keyword to `true`.
192195
*/
@@ -260,15 +263,15 @@ export interface NumberKeywords {
260263
multipleOf?: number;
261264
}
262265

263-
export interface ObjectKeywords {
266+
export interface ObjectKeywords<TDocument = unknown> {
264267
/**
265268
* 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.
266269
*
267270
* The value of the `additionalProperties` keyword is a schema that will be used to validate any properties in the {@link https://json-schema.org/learn/glossary#instance instance} that are not matched by `properties` or `patternProperties`. Setting the `additionalProperties` schema to `false` means no additional properties will be allowed.
268271
*
269272
* 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}.
270273
*/
271-
additionalProperties?: Document | false;
274+
additionalProperties?: TDocument | false;
272275
/**
273276
* 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.
274277
*/
@@ -280,11 +283,11 @@ export interface ObjectKeywords {
280283
/**
281284
* 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.
282285
*/
283-
patternProperties?: Record<string, Document>;
286+
patternProperties?: Record<string, TDocument>;
284287
/**
285288
* 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.
286289
*/
287-
properties?: Record<string, Document | true>;
290+
properties?: Record<string, TDocument | true>;
288291
/**
289292
* 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.
290293
*
@@ -294,7 +297,7 @@ export interface ObjectKeywords {
294297
* { "type": "string" }
295298
* ```
296299
*/
297-
propertyNames?: Document;
300+
propertyNames?: TDocument;
298301
/**
299302
* 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.
300303
*
@@ -306,7 +309,7 @@ export interface ObjectKeywords {
306309
*
307310
* `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.
308311
*/
309-
unevaluatedProperties?: Document | false;
312+
unevaluatedProperties?: TDocument | false;
310313
}
311314

312315
export interface StringKeywords {

packages/spec-types/src/openapi/v2/spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CodeSampleObject } from '../../extensions/code-samples';
22
import type { EnumExtensions } from '../../extensions/enum';
3-
import type { Document as JSONSchemaDraft4 } from '../../json-schema/draft-4/spec';
3+
import type { Document as JSONSchemaDraft4 } from '../../json-schema/draft-4';
44
import type { OpenAPIV2NullableExtensions } from './extensions';
55

66
/**

packages/spec-types/src/openapi/v3-1/spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CodeSampleObject } from '../../extensions/code-samples';
22
import type { EnumExtensions } from '../../extensions/enum';
33
import type { SpecExtensions } from '../../extensions/spec';
4-
import type { Document as JSONSchemaDraft2020_12 } from '../../json-schema/draft-2020-12';
4+
import type { BaseDocument as JSONSchemaDraft2020_12 } from '../../json-schema/draft-2020-12';
55
import type { OpenAPIV3_1SchemaExtensions } from './extensions';
66

77
/**
@@ -1668,10 +1668,12 @@ export interface ResponsesObject extends SpecExtensions {
16681668
*
16691669
* 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.
16701670
*/
1671-
export type SchemaObject = JSONSchemaDraft2020_12 &
1672-
OpenAPIV3_1SchemaExtensions &
1673-
SpecExtensions &
1674-
EnumExtensions;
1671+
export interface SchemaObject
1672+
extends
1673+
JSONSchemaDraft2020_12<SchemaObject>,
1674+
OpenAPIV3_1SchemaExtensions,
1675+
SpecExtensions,
1676+
EnumExtensions {}
16751677

16761678
/**
16771679
* 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}.

0 commit comments

Comments
 (0)