|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import { ModuleKind, ScriptTarget } from "ts-morph"; |
11 | | -import { Path } from 'swagger-schema-official'; |
12 | 11 |
|
13 | 12 | // =================================================================================== |
14 | 13 | // SECTION: OpenAPI / Swagger Specification Types |
@@ -63,6 +62,34 @@ export interface InfoObject { |
63 | 62 | version: string; |
64 | 63 | } |
65 | 64 |
|
| 65 | +/** |
| 66 | + * An object representing a Server Variable for server URL template substitution. |
| 67 | + * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.2.0.md#server-variable-object |
| 68 | + */ |
| 69 | +export interface ServerVariableObject { |
| 70 | + /** An enumeration of string values to be used if the substitution options are from a limited set. */ |
| 71 | + enum?: string[]; |
| 72 | + /** The default value to use for substitution. */ |
| 73 | + default: string; |
| 74 | + /** An optional description for the server variable. */ |
| 75 | + description?: string; |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * An object representing a Server. |
| 80 | + * @see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.2.0.md#server-object |
| 81 | + */ |
| 82 | +export interface ServerObject { |
| 83 | + /** A URL to the target host. */ |
| 84 | + url: string; |
| 85 | + /** An optional string describing the host designated by the URL. */ |
| 86 | + description?: string; |
| 87 | + /** An optional unique string to refer to the host designated by the URL. (OAS 3.2) */ |
| 88 | + name?: string; |
| 89 | + /** A map between a variable name and its value. */ |
| 90 | + variables?: { [variable: string]: ServerVariableObject }; |
| 91 | +} |
| 92 | + |
66 | 93 | /** Represents the `discriminator` object used for polymorphism in OpenAPI schemas. */ |
67 | 94 | export interface DiscriminatorObject { |
68 | 95 | /** The name of the property in the payload that determines the schema to use. */ |
@@ -158,14 +185,34 @@ export interface PathInfo { |
158 | 185 | responses?: Record<string, SwaggerResponse>; |
159 | 186 | /** The generator-derived, safe method name for this operation. */ |
160 | 187 | methodName?: string; |
| 188 | + /** Security requirements specific to this operation. keys are definitions, values are scopes. */ |
| 189 | + security?: { [key: string]: string[] }[]; |
| 190 | +} |
| 191 | + |
| 192 | +/** A single encoding definition for a multipart property. */ |
| 193 | +export interface EncodingProperty { |
| 194 | + /** The Content-Type for encoding a specific property. */ |
| 195 | + contentType?: string; |
| 196 | + /** A map of headers that are to be encoded for the property. */ |
| 197 | + headers?: Record<string, any>; |
| 198 | + /** serialization style */ |
| 199 | + style?: string; |
| 200 | + /** whether to explode array/objects */ |
| 201 | + explode?: boolean; |
| 202 | + /** allow reserved characters */ |
| 203 | + allowReserved?: boolean; |
161 | 204 | } |
162 | 205 |
|
163 | 206 | /** Represents the request body of an operation. */ |
164 | 207 | export interface RequestBody { |
165 | 208 | /** Determines if the request body is required. */ |
166 | 209 | required?: boolean; |
167 | 210 | /** A map of media types to their corresponding schemas for the request body. */ |
168 | | - content?: Record<string, { schema?: SwaggerDefinition | { $ref: string } }>; |
| 211 | + content?: Record<string, { |
| 212 | + schema?: SwaggerDefinition | { $ref: string }; |
| 213 | + /** Encoding object for multipart/form-data definitions */ |
| 214 | + encoding?: Record<string, EncodingProperty>; |
| 215 | + }>; |
169 | 216 | } |
170 | 217 |
|
171 | 218 | /** Represents a single response from an API Operation. */ |
@@ -240,24 +287,66 @@ export interface SecurityScheme { |
240 | 287 | openIdConnectUrl?: string; |
241 | 288 | } |
242 | 289 |
|
| 290 | +/** |
| 291 | + * Represents an Operation Object in OpenAPI (v2 or v3). |
| 292 | + */ |
| 293 | +export interface SpecOperation { |
| 294 | + tags?: string[]; |
| 295 | + summary?: string; |
| 296 | + description?: string; |
| 297 | + externalDocs?: ExternalDocumentationObject; |
| 298 | + operationId?: string; |
| 299 | + consumes?: string[]; |
| 300 | + produces?: string[]; |
| 301 | + parameters?: any[]; // Raw parameters (Swagger 2 or OAS 3) |
| 302 | + requestBody?: any; // OAS 3 |
| 303 | + responses: Record<string, any>; |
| 304 | + schemes?: string[]; |
| 305 | + deprecated?: boolean; |
| 306 | + security?: Record<string, string[]>[]; |
| 307 | + [key: string]: any; |
| 308 | +} |
| 309 | + |
| 310 | +/** |
| 311 | + * Represents a Path Item Object in OpenAPI (v2 or v3). |
| 312 | + */ |
| 313 | +export interface PathItem { |
| 314 | + $ref?: string; |
| 315 | + summary?: string; |
| 316 | + description?: string; |
| 317 | + get?: SpecOperation; |
| 318 | + put?: SpecOperation; |
| 319 | + post?: SpecOperation; |
| 320 | + delete?: SpecOperation; |
| 321 | + options?: SpecOperation; |
| 322 | + head?: SpecOperation; |
| 323 | + patch?: SpecOperation; |
| 324 | + trace?: SpecOperation; |
| 325 | + query?: SpecOperation; // OAS 3.2 draft |
| 326 | + parameters?: any[]; |
| 327 | + [key: string]: any; |
| 328 | +} |
| 329 | + |
243 | 330 | /** The root object of a parsed OpenAPI/Swagger specification. */ |
244 | 331 | export interface SwaggerSpec { |
245 | 332 | openapi?: string; |
246 | 333 | swagger?: string; |
247 | 334 | $self?: string; |
248 | 335 | info: InfoObject; |
249 | | - paths: { [pathName: string]: Path }; |
| 336 | + paths: { [pathName: string]: PathItem }; |
250 | 337 | /** The incoming webhooks that MAY be received as part of this API. */ |
251 | | - webhooks?: { [name: string]: Path }; |
| 338 | + webhooks?: { [name: string]: PathItem }; |
252 | 339 | /** The default value for the $schema keyword within Schema Objects. */ |
253 | 340 | jsonSchemaDialect?: string; |
| 341 | + /** An array of Server Objects, which provide connectivity information to a target server. */ |
| 342 | + servers?: ServerObject[]; |
254 | 343 | /** Schema definitions (Swagger 2.0). */ |
255 | 344 | definitions?: { [definitionsName: string]: SwaggerDefinition }; |
256 | 345 | /** Replaces `definitions` in OpenAPI 3.x. */ |
257 | 346 | components?: { |
258 | 347 | schemas?: Record<string, SwaggerDefinition>; |
259 | 348 | securitySchemes?: Record<string, SecurityScheme>; |
260 | | - pathItems?: Record<string, Path>; |
| 349 | + pathItems?: Record<string, PathItem>; |
261 | 350 | }; |
262 | 351 | /** Security definitions (Swagger 2.0). */ |
263 | 352 | securityDefinitions?: { [securityDefinitionName: string]: SecurityScheme }; |
|
0 commit comments