1- import type { JSONSchema6 , JSONSchema6Definition } from 'json-schema' ;
2- import type {
3- LeadingPageMode ,
4- SPEC_RENDER_MODE_DEFAULT ,
5- SPEC_RENDER_MODE_HIDDEN ,
6- SUPPORTED_ENUM_TYPES ,
7- } from './constants' ;
1+ import type { OpenAPIV3 } from 'openapi-types' ;
2+ import type { LeadingPageMode , SPEC_RENDER_MODE_DEFAULT , SPEC_RENDER_MODE_HIDDEN } from './constants' ;
83
9- export type VarsPreset = 'internal' | 'external' ;
4+ export type Dereference < T > = T extends OpenAPIV3 . ReferenceObject
5+ ? never
6+ : T extends object
7+ ? T extends OpenAPIV3 . ReferenceObject
8+ ? never
9+ : // eslint-disable-next-line
10+ T extends any [ ]
11+ ? DereferenceArray < T [ number ] >
12+ : DereferenceObject < T >
13+ : T ;
14+
15+ type DereferenceArray < T > = Array < Dereference < T > > ;
16+
17+ type DereferenceObject < T extends object > = {
18+ [ K in keyof T ] : Dereference < T [ K ] > ;
19+ } ;
20+
21+ export type TableRef = string ;
1022
1123export type YfmPreset = Record < string , string > ;
1224// eslint-disable-next-line @typescript-eslint/no-explicit-any
1325export type Metadata = Record < string , any > ;
1426
15- export enum IncludeMode {
16- ROOT_MERGE = 'root_merge' ,
17- MERGE = 'merge' ,
18- LINK = 'link' ,
19- }
20-
2127export interface Filter {
2228 when ?: boolean | string ;
2329 [ key : string ] : unknown ;
@@ -29,68 +35,14 @@ export interface TextItem extends Filter {
2935
3036export type TextItems = string | ( TextItem | string ) [ ] ;
3137
32- export interface YfmToc extends Filter {
33- name : string ;
34- href : string ;
35- items : YfmToc [ ] ;
36- stage ?: Stage ;
37- base ?: string ;
38- title ?: TextItems ;
39- include ?: YfmTocInclude ;
40- id ?: string ;
41- singlePage ?: boolean ;
42- hidden ?: boolean ;
43- deprecated ?: boolean ;
44- }
45-
4638export interface YfmTocItem extends Filter {
4739 name : string ;
4840 href ?: string ;
4941 items ?: YfmTocItem [ ] ;
50- include ?: YfmTocInclude ;
51- id ?: string ;
52- }
53-
54- export interface YfmTocInclude {
55- repo : string ;
56- path : string ;
57- mode ?: IncludeMode ;
58- includers ?: YfmTocIncluders ;
42+ hidden ?: boolean ;
43+ deprecated ?: boolean ;
5944}
6045
61- export type YfmTocIncluders = YfmTocIncluder [ ] ;
62-
63- export type YfmTocIncluder = {
64- name : 'openapi' ;
65- // arbitrary includer parameters
66- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67- } & Record < string , unknown > ;
68-
69- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70- export type Includer < FnParams = any > = {
71- name : 'openapi' ;
72- includerFunction : IncluderFunction < FnParams > ;
73- } ;
74-
75- export type IncluderFunction < PassedParams > = (
76- args : IncluderFunctionParams < PassedParams > ,
77- ) => Promise < void > ;
78-
79- export type IncluderFunctionParams < PassedParams > = {
80- /** item that contains include that uses includer */
81- item : YfmToc ;
82- /** base read directory path */
83- readBasePath : string ;
84- /** base write directory path */
85- writeBasePath : string ;
86- /** toc with includer path */
87- tocPath : string ;
88- vars : YfmPreset ;
89- /** arbitrary includer parameters */
90- passedParams : PassedParams ;
91- index : number ;
92- } ;
93-
9446export const titleDepths = [ 1 , 2 , 3 , 4 , 5 , 6 ] as const ;
9547
9648export type TitleDepth = ( typeof titleDepths ) [ number ] ;
@@ -99,22 +51,16 @@ export type SandboxProps = {
9951 path : string ;
10052 host ?: string ;
10153 method : Method ;
102- pathParams ?: V3Parameters ;
103- searchParams ?: V3Parameters ;
104- headers ?: V3Parameters ;
54+ pathParams ?: Dereference < OpenAPIV3 . ParameterObject > [ ] ;
55+ searchParams ?: Dereference < OpenAPIV3 . ParameterObject > [ ] ;
56+ headers ?: Dereference < OpenAPIV3 . ParameterObject > [ ] ;
10557 body ?: string ;
10658 bodyType ?: string ;
107- schema ?: OpenJSONSchema ;
59+ schema ?: Dereference < OpenAPIV3 . SchemaObject > ;
10860 security ?: V3Security [ ] ;
10961 projectName : string ;
11062} ;
11163
112- export type OpenAPISpec = {
113- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
114- [ key : string ] : any ;
115- security ?: Array < Record < string , V3Security > > ;
116- } ;
117-
11864export type V3SecurityApiKey = {
11965 type : 'apiKey' ;
12066 description : string ;
@@ -145,24 +91,6 @@ export type V3Security = V3SecurityApiKey | V3SecurityOAuth2 | {type: string; de
14591
14692export type V3SecurityType = V3Security [ 'type' ] ;
14793
148- export type OpenAPIOperation = {
149- summary ?: string ;
150- description ?: string ;
151- operationId ?: string ;
152- deprecated ?: boolean ;
153- tags ?: string [ ] ;
154- servers ?: V3Servers ;
155- parameters ?: V3Parameters ;
156- responses ?: { } ;
157- requestBody ?: {
158- required ?: boolean ;
159- description ?: string ;
160- content : { [ ContentType : string ] : { schema : OpenJSONSchema } } ;
161- } ;
162- security ?: Array < Record < string , V3Security > > ;
163- 'x-navtitle' : string [ ] ;
164- } ;
165-
16694export type V3Info = {
16795 name : string ;
16896 version : string ;
@@ -198,14 +126,14 @@ export type V3Endpoints = V3Endpoint[];
198126export type V3Endpoint = {
199127 id : string ;
200128 operationId ?: string ;
201- method : Method ;
129+ method : string ;
202130 path : string ;
203131 tags : string [ ] ;
204132 summary ?: string ;
205133 description ?: string ;
206134 servers : V3Servers ;
207- parameters ?: V3Parameters ;
208- responses ? : V3Responses ;
135+ parameters : Dereference < OpenAPIV3 . ParameterObject > [ ] ;
136+ responses : V3Responses ;
209137 requestBody ?: V3Schema ;
210138 security : V3Security [ ] ;
211139 noindex ?: boolean ;
@@ -238,28 +166,10 @@ export type V3Server = {
238166 description ?: string ;
239167} ;
240168
241- // eslint-disable-next-line @typescript-eslint/no-redeclare
242- export type V3Parameters = V3Parameter [ ] ;
243-
244169export type In = 'path' | 'query' | 'header' | 'cookie' ;
245170
246171export type Primitive = string | number | boolean ;
247172
248- export type V3Parameter = {
249- name : string ;
250- in : In ;
251- required : boolean ;
252- description ?: string ;
253- example ?: Primitive ;
254- default ?: Primitive ;
255- schema : OpenJSONSchema ;
256-
257- readOnly ?: boolean ;
258- writeOnly ?: boolean ;
259- // vendor extensions
260- 'x-hidden' ?: boolean ;
261- } ;
262-
263173export type V3Responses = V3Response [ ] ;
264174
265175// eslint-disable-next-line @typescript-eslint/no-redeclare
@@ -268,41 +178,21 @@ export type V3Response = {
268178 code : string ;
269179 statusText : string ;
270180 description : string ;
271- schemas ?: V3Schemas ;
181+ schemas ?: V3Schema [ ] ;
182+ deprecated ?: boolean ;
272183} ;
273184
274- export type V3Schemas = V3Schema [ ] ;
275-
276185export type V3Schema = {
277186 type : string ;
278- schema : OpenJSONSchema ;
187+ schema : OpenAPIV3 . SchemaObject ;
279188} ;
280189
281- export type Refs = { [ typeName : string ] : OpenJSONSchema } ;
282-
283- export type JsType =
284- | 'string'
285- | 'number'
286- | 'bigint'
287- | 'boolean'
288- | 'symbol'
289- | 'undefined'
290- | 'object'
291- | 'function' ;
190+ export type Refs = { [ typeName : string ] : OpenAPIV3 . SchemaObject } ;
292191
293192export type LeadingPageSpecRenderMode =
294193 | typeof SPEC_RENDER_MODE_DEFAULT
295194 | typeof SPEC_RENDER_MODE_HIDDEN ;
296195
297- export type SupportedEnumType = ( typeof SUPPORTED_ENUM_TYPES ) [ number ] ;
298-
299- export enum Stage {
300- NEW = 'new' ,
301- PREVIEW = 'preview' ,
302- TECH_PREVIEW = 'tech-preview' ,
303- SKIP = 'skip' ,
304- }
305-
306196export type LeadingPageParams = {
307197 name ?: string ;
308198 mode ?: LeadingPageMode ;
@@ -340,32 +230,6 @@ export type OpenApiIncluderParams = {
340230 } ;
341231} ;
342232
343- export type OpenJSONSchema = JSONSchema6 & {
344- _runtime ?: true ;
345- _emptyDescription ?: true ;
346- example ?: unknown ;
347- deprecated ?: boolean ;
348- properties ?: {
349- [ key : string ] : JSONSchema6Definition & {
350- readOnly ?: boolean ;
351- writeOnly ?: boolean ;
352- 'x-hidden' ?: boolean ;
353- } ;
354- } ;
355- } ;
356- export type OpenJSONSchemaDefinition = OpenJSONSchema | boolean ;
357-
358- export type FoundRefType = {
359- ref : string ;
360- } ;
361- export type BaseJSONSchemaType = Exclude < OpenJSONSchema [ 'type' ] , undefined > ;
362- export type JSONSchemaUnionType = {
363- ref ?: string ;
364- /* Not oneOf because of collision with OpenJSONSchema['oneOf'] */
365- unionOf : JSONSchemaType [ ] ;
366- } ;
367- export type JSONSchemaType = BaseJSONSchemaType | JSONSchemaUnionType | FoundRefType ;
368-
369233export type Run = {
370234 input : string ;
371235 vars : {
0 commit comments