@ahoo-wang/wow-generator 9.2.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +177 -0
  3. package/README.zh-CN.md +149 -0
  4. package/dist/analysis/aggregates.d.cts +21 -0
  5. package/dist/analysis/aggregates.d.ts +21 -0
  6. package/dist/analysis/analyze.d.cts +18 -0
  7. package/dist/analysis/analyze.d.ts +18 -0
  8. package/dist/analysis/apiClients.d.cts +14 -0
  9. package/dist/analysis/apiClients.d.ts +14 -0
  10. package/dist/analysis/clientNames.d.cts +55 -0
  11. package/dist/analysis/clientNames.d.ts +55 -0
  12. package/dist/analysis/model.d.cts +212 -0
  13. package/dist/analysis/model.d.ts +212 -0
  14. package/dist/analysis/modelInfo.d.cts +23 -0
  15. package/dist/analysis/modelInfo.d.ts +23 -0
  16. package/dist/analysis/models.d.cts +17 -0
  17. package/dist/analysis/models.d.ts +17 -0
  18. package/dist/api/configuration.d.cts +30 -0
  19. package/dist/api/configuration.d.ts +30 -0
  20. package/dist/api/errors.d.cts +41 -0
  21. package/dist/api/errors.d.ts +41 -0
  22. package/dist/api/logger.d.cts +61 -0
  23. package/dist/api/logger.d.ts +61 -0
  24. package/dist/api/options.d.cts +47 -0
  25. package/dist/api/options.d.ts +47 -0
  26. package/dist/cli/program.d.cts +35 -0
  27. package/dist/cli/program.d.ts +35 -0
  28. package/dist/cli/runGenerate.d.cts +65 -0
  29. package/dist/cli/runGenerate.d.ts +65 -0
  30. package/dist/cli.cjs +3 -0
  31. package/dist/cli.cjs.map +1 -0
  32. package/dist/cli.d.cts +6 -0
  33. package/dist/cli.d.ts +6 -0
  34. package/dist/cli.js +98 -0
  35. package/dist/cli.js.map +1 -0
  36. package/dist/codeGenerator-DpDTDC4o.cjs +23 -0
  37. package/dist/codeGenerator-DpDTDC4o.cjs.map +1 -0
  38. package/dist/codeGenerator-kyY9eLML.js +2583 -0
  39. package/dist/codeGenerator-kyY9eLML.js.map +1 -0
  40. package/dist/emit/importRegistry.d.cts +50 -0
  41. package/dist/emit/importRegistry.d.ts +50 -0
  42. package/dist/emit/imports.d.cts +49 -0
  43. package/dist/emit/imports.d.ts +49 -0
  44. package/dist/emit/jsdoc.d.cts +38 -0
  45. package/dist/emit/jsdoc.d.ts +38 -0
  46. package/dist/emit/moduleBuilder.d.cts +80 -0
  47. package/dist/emit/moduleBuilder.d.ts +80 -0
  48. package/dist/emitters/apiClients.d.cts +10 -0
  49. package/dist/emitters/apiClients.d.ts +10 -0
  50. package/dist/emitters/commandClients.d.cts +14 -0
  51. package/dist/emitters/commandClients.d.ts +14 -0
  52. package/dist/emitters/decorators.d.cts +83 -0
  53. package/dist/emitters/decorators.d.ts +83 -0
  54. package/dist/emitters/emit.d.cts +15 -0
  55. package/dist/emitters/emit.d.ts +15 -0
  56. package/dist/emitters/indexFiles.d.cts +12 -0
  57. package/dist/emitters/indexFiles.d.ts +12 -0
  58. package/dist/emitters/models.d.cts +77 -0
  59. package/dist/emitters/models.d.ts +77 -0
  60. package/dist/emitters/queryClients.d.cts +11 -0
  61. package/dist/emitters/queryClients.d.ts +11 -0
  62. package/dist/emitters/target.d.cts +14 -0
  63. package/dist/emitters/target.d.ts +14 -0
  64. package/dist/finalize/finalize.d.cts +16 -0
  65. package/dist/finalize/finalize.d.ts +16 -0
  66. package/dist/finalize/typeOnlyImports.d.cts +13 -0
  67. package/dist/finalize/typeOnlyImports.d.ts +13 -0
  68. package/dist/finalize/verification.d.cts +14 -0
  69. package/dist/finalize/verification.d.ts +14 -0
  70. package/dist/index.cjs +1 -0
  71. package/dist/index.d.cts +8 -0
  72. package/dist/index.d.ts +8 -0
  73. package/dist/index.js +2 -0
  74. package/dist/input/configuration.d.cts +87 -0
  75. package/dist/input/configuration.d.ts +87 -0
  76. package/dist/input/parsers.d.cts +39 -0
  77. package/dist/input/parsers.d.ts +39 -0
  78. package/dist/input/resources.d.cts +36 -0
  79. package/dist/input/resources.d.ts +36 -0
  80. package/dist/naming/modelInfo.d.cts +10 -0
  81. package/dist/naming/modelInfo.d.ts +10 -0
  82. package/dist/naming/naming.d.cts +102 -0
  83. package/dist/naming/naming.d.ts +102 -0
  84. package/dist/naming/order.d.cts +2 -0
  85. package/dist/naming/order.d.ts +2 -0
  86. package/dist/naming/paths.d.cts +27 -0
  87. package/dist/naming/paths.d.ts +27 -0
  88. package/dist/openapi/components.d.cts +55 -0
  89. package/dist/openapi/components.d.ts +55 -0
  90. package/dist/openapi/document.d.cts +25 -0
  91. package/dist/openapi/document.d.ts +25 -0
  92. package/dist/openapi/operations.d.cts +78 -0
  93. package/dist/openapi/operations.d.ts +78 -0
  94. package/dist/openapi/references.d.cts +28 -0
  95. package/dist/openapi/references.d.ts +28 -0
  96. package/dist/openapi/responses.d.cts +44 -0
  97. package/dist/openapi/responses.d.ts +44 -0
  98. package/dist/openapi/schemas.d.cts +112 -0
  99. package/dist/openapi/schemas.d.ts +112 -0
  100. package/dist/output/outputStore.d.cts +92 -0
  101. package/dist/output/outputStore.d.ts +92 -0
  102. package/dist/pipeline/codeGenerator.d.cts +61 -0
  103. package/dist/pipeline/codeGenerator.d.ts +61 -0
  104. package/dist/pipeline/seams.d.cts +29 -0
  105. package/dist/pipeline/seams.d.ts +29 -0
  106. package/dist/types/typeResolver.d.cts +124 -0
  107. package/dist/types/typeResolver.d.ts +124 -0
  108. package/dist/version.d.cts +2 -0
  109. package/dist/version.d.ts +2 -0
  110. package/dist/wow/conventions.d.cts +154 -0
  111. package/dist/wow/conventions.d.ts +154 -0
  112. package/dist/wow/model.d.cts +116 -0
  113. package/dist/wow/model.d.ts +116 -0
  114. package/dist/wow/resolveWowModel.d.cts +21 -0
  115. package/dist/wow/resolveWowModel.d.ts +21 -0
  116. package/package.json +108 -0
@@ -0,0 +1,36 @@
1
+ /** How long a remote document may take before the request is abandoned. */
2
+ export declare const DEFAULT_HTTP_TIMEOUT_MS = 30000;
3
+ /**
4
+ * Options for loading a resource over HTTP. Files ignore them.
5
+ */
6
+ export interface LoadResourceOptions {
7
+ /** Request headers, for example `Authorization`. */
8
+ readonly headers?: Record<string, string>;
9
+ /** Milliseconds before the request is abandoned. */
10
+ readonly timeoutMs?: number;
11
+ /** Abandons the request when it aborts, as an interrupted run does. */
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * Tells whether a location names an http(s) resource rather than a file.
16
+ *
17
+ * @param path - A file path or URL
18
+ * @returns True for an `http://` or `https://` URL
19
+ */
20
+ export declare function isHttpLocation(path: string): boolean;
21
+ export declare function loadResource(path: string, options?: LoadResourceOptions): Promise<string>;
22
+ /**
23
+ * Fetches a resource and returns its body.
24
+ *
25
+ * A response outside 2xx is a failure: a 401 or 404 page is not the document
26
+ * the caller asked for, and parsing it would only fail later with a message
27
+ * about the page instead of the request.
28
+ *
29
+ * @param url - The http(s) URL
30
+ * @param options - Headers and timeout
31
+ * @returns The response body as text
32
+ * @throws Error naming the status, the timeout or the network failure; the
33
+ * caller names the URL
34
+ */
35
+ export declare function loadHttpResource(url: string, options?: LoadResourceOptions): Promise<string>;
36
+ export declare function loadFile(path: string): Promise<string>;
@@ -0,0 +1,36 @@
1
+ /** How long a remote document may take before the request is abandoned. */
2
+ export declare const DEFAULT_HTTP_TIMEOUT_MS = 30000;
3
+ /**
4
+ * Options for loading a resource over HTTP. Files ignore them.
5
+ */
6
+ export interface LoadResourceOptions {
7
+ /** Request headers, for example `Authorization`. */
8
+ readonly headers?: Record<string, string>;
9
+ /** Milliseconds before the request is abandoned. */
10
+ readonly timeoutMs?: number;
11
+ /** Abandons the request when it aborts, as an interrupted run does. */
12
+ readonly signal?: AbortSignal;
13
+ }
14
+ /**
15
+ * Tells whether a location names an http(s) resource rather than a file.
16
+ *
17
+ * @param path - A file path or URL
18
+ * @returns True for an `http://` or `https://` URL
19
+ */
20
+ export declare function isHttpLocation(path: string): boolean;
21
+ export declare function loadResource(path: string, options?: LoadResourceOptions): Promise<string>;
22
+ /**
23
+ * Fetches a resource and returns its body.
24
+ *
25
+ * A response outside 2xx is a failure: a 401 or 404 page is not the document
26
+ * the caller asked for, and parsing it would only fail later with a message
27
+ * about the page instead of the request.
28
+ *
29
+ * @param url - The http(s) URL
30
+ * @param options - Headers and timeout
31
+ * @returns The response body as text
32
+ * @throws Error naming the status, the timeout or the network failure; the
33
+ * caller names the URL
34
+ */
35
+ export declare function loadHttpResource(url: string, options?: LoadResourceOptions): Promise<string>;
36
+ export declare function loadFile(path: string): Promise<string>;
@@ -0,0 +1,10 @@
1
+ import { Named } from '@ahoo-wang/wow-client';
2
+ /**
3
+ * Where a generated declaration lives: its name, and the directory under the
4
+ * output directory whose `types.ts` declares it, or the package it is
5
+ * imported from (a path starting with `@`).
6
+ */
7
+ export interface ModelInfo extends Named {
8
+ name: string;
9
+ path: string;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { Named } from '@ahoo-wang/wow-client';
2
+ /**
3
+ * Where a generated declaration lives: its name, and the directory under the
4
+ * output directory whose `types.ts` declares it, or the package it is
5
+ * imported from (a path starting with `@`).
6
+ */
7
+ export interface ModelInfo extends Named {
8
+ name: string;
9
+ path: string;
10
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Tells whether a name is a valid identifier as written.
3
+ *
4
+ * @param name - The candidate
5
+ * @returns True when it can name a variable, a parameter or a type
6
+ */
7
+ export declare function isIdentifier(name: string): boolean;
8
+ /**
9
+ * Turns a name from the document into a value identifier: a parameter, a
10
+ * method or a variable.
11
+ *
12
+ * A valid identifier is kept as written. Anything else is camel-cased on its
13
+ * separators (`item-id` → `itemId`), prefixed with `_` when it starts with a
14
+ * digit, and suffixed with `_` when it is a reserved word (`default` →
15
+ * `default_`).
16
+ *
17
+ * @param name - The name the document uses
18
+ * @returns A valid identifier
19
+ */
20
+ export declare function toIdentifier(name: string): string;
21
+ /**
22
+ * Turns a name from the document into a type identifier: a model, an enum or
23
+ * a class.
24
+ *
25
+ * Each part that starts with an upper-case letter and holds no separator is
26
+ * kept as written, acronyms included (`MCPListTools` stays `MCPListTools`).
27
+ * Any other part is pascal-cased on its separators (`order_item` →
28
+ * `OrderItem`, `Page«User»` → `PageUser`). The result is prefixed with `_`
29
+ * when it starts with a digit (`1stThing` → `_1stThing`).
30
+ *
31
+ * @param name - A name, or the parts of one
32
+ * @returns A valid type identifier
33
+ */
34
+ export declare function toTypeIdentifier(name: string | string[]): string;
35
+ export declare function splitName(name: string): string[];
36
+ /**
37
+ * Splits a name string or array of strings by common naming separators.
38
+ *
39
+ * This function takes a string or array of strings and splits them based on common naming
40
+ * separators including hyphens, underscores, spaces, dots, and before uppercase letters.
41
+ * If an array is provided, each element is split individually and the results are flattened.
42
+ *
43
+ * @param name - A string or array of strings to split by naming separators
44
+ * @returns An array of string parts split by naming separators
45
+ */
46
+ export declare function tokenizeName(name: string | string[]): string[];
47
+ /**
48
+ * Splits camelCase strings properly, keeping consecutive uppercase letters together.
49
+ *
50
+ * @param parts - Array of string parts to process
51
+ * @returns Array of properly split parts
52
+ */
53
+ export declare function splitCamelCase(parts: string[]): string[];
54
+ /**
55
+ * Converts a string or array of strings to PascalCase format.
56
+ *
57
+ * This function takes a string or array of strings and converts them to PascalCase format
58
+ * by splitting the input based on common naming separators and capitalizing the first
59
+ * letter of each part.
60
+ *
61
+ * @param name - A string or array of strings to convert to PascalCase
62
+ * @returns The PascalCase formatted string
63
+ */
64
+ export declare function pascalCase(name: string | string[]): string;
65
+ /**
66
+ * Converts a string or array of strings to camelCase format.
67
+ *
68
+ * This function first converts the input to PascalCase and then converts the first character to lowercase.
69
+ *
70
+ * @param name - A string or array of strings to convert to camelCase
71
+ * @returns The camelCase formatted string
72
+ */
73
+ export declare function camelCase(name: string | string[]): string;
74
+ /**
75
+ * Converts a string or array of strings to UPPER_SNAKE_CASE format.
76
+ *
77
+ * This function takes a string or array of strings and converts them to UPPER_SNAKE_CASE format
78
+ * by splitting the input based on common naming separators, converting each part to uppercase,
79
+ * and joining them with underscores. It properly handles consecutive uppercase letters
80
+ * (like acronyms) by treating them as single units.
81
+ *
82
+ * @param name - A string or array of strings to convert to UPPER_SNAKE_CASE
83
+ * @returns The UPPER_SNAKE_CASE formatted string
84
+ */
85
+ export declare function upperSnakeCase(name: string | string[]): string;
86
+ export declare function resolvePropertyName(name: string): string;
87
+ /**
88
+ * The member key an enum value prefers, before quoting: its UPPER_SNAKE_CASE
89
+ * form, `NUM_` and the digits for a number.
90
+ */
91
+ export declare function enumMemberKey(name: string): string;
92
+ /**
93
+ * Renders a value as a single-quoted TypeScript string literal.
94
+ *
95
+ * A property name is whatever the document says it is, so one carrying a
96
+ * quote or a backslash has to be escaped rather than wrapped - `owner'sName`
97
+ * would otherwise close the literal and generate a syntax error.
98
+ *
99
+ * @param value - The string to render
100
+ * @returns The escaped string literal, quotes included
101
+ */
102
+ export declare function quoteStringLiteral(value: string): string;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Tells whether a name is a valid identifier as written.
3
+ *
4
+ * @param name - The candidate
5
+ * @returns True when it can name a variable, a parameter or a type
6
+ */
7
+ export declare function isIdentifier(name: string): boolean;
8
+ /**
9
+ * Turns a name from the document into a value identifier: a parameter, a
10
+ * method or a variable.
11
+ *
12
+ * A valid identifier is kept as written. Anything else is camel-cased on its
13
+ * separators (`item-id` → `itemId`), prefixed with `_` when it starts with a
14
+ * digit, and suffixed with `_` when it is a reserved word (`default` →
15
+ * `default_`).
16
+ *
17
+ * @param name - The name the document uses
18
+ * @returns A valid identifier
19
+ */
20
+ export declare function toIdentifier(name: string): string;
21
+ /**
22
+ * Turns a name from the document into a type identifier: a model, an enum or
23
+ * a class.
24
+ *
25
+ * Each part that starts with an upper-case letter and holds no separator is
26
+ * kept as written, acronyms included (`MCPListTools` stays `MCPListTools`).
27
+ * Any other part is pascal-cased on its separators (`order_item` →
28
+ * `OrderItem`, `Page«User»` → `PageUser`). The result is prefixed with `_`
29
+ * when it starts with a digit (`1stThing` → `_1stThing`).
30
+ *
31
+ * @param name - A name, or the parts of one
32
+ * @returns A valid type identifier
33
+ */
34
+ export declare function toTypeIdentifier(name: string | string[]): string;
35
+ export declare function splitName(name: string): string[];
36
+ /**
37
+ * Splits a name string or array of strings by common naming separators.
38
+ *
39
+ * This function takes a string or array of strings and splits them based on common naming
40
+ * separators including hyphens, underscores, spaces, dots, and before uppercase letters.
41
+ * If an array is provided, each element is split individually and the results are flattened.
42
+ *
43
+ * @param name - A string or array of strings to split by naming separators
44
+ * @returns An array of string parts split by naming separators
45
+ */
46
+ export declare function tokenizeName(name: string | string[]): string[];
47
+ /**
48
+ * Splits camelCase strings properly, keeping consecutive uppercase letters together.
49
+ *
50
+ * @param parts - Array of string parts to process
51
+ * @returns Array of properly split parts
52
+ */
53
+ export declare function splitCamelCase(parts: string[]): string[];
54
+ /**
55
+ * Converts a string or array of strings to PascalCase format.
56
+ *
57
+ * This function takes a string or array of strings and converts them to PascalCase format
58
+ * by splitting the input based on common naming separators and capitalizing the first
59
+ * letter of each part.
60
+ *
61
+ * @param name - A string or array of strings to convert to PascalCase
62
+ * @returns The PascalCase formatted string
63
+ */
64
+ export declare function pascalCase(name: string | string[]): string;
65
+ /**
66
+ * Converts a string or array of strings to camelCase format.
67
+ *
68
+ * This function first converts the input to PascalCase and then converts the first character to lowercase.
69
+ *
70
+ * @param name - A string or array of strings to convert to camelCase
71
+ * @returns The camelCase formatted string
72
+ */
73
+ export declare function camelCase(name: string | string[]): string;
74
+ /**
75
+ * Converts a string or array of strings to UPPER_SNAKE_CASE format.
76
+ *
77
+ * This function takes a string or array of strings and converts them to UPPER_SNAKE_CASE format
78
+ * by splitting the input based on common naming separators, converting each part to uppercase,
79
+ * and joining them with underscores. It properly handles consecutive uppercase letters
80
+ * (like acronyms) by treating them as single units.
81
+ *
82
+ * @param name - A string or array of strings to convert to UPPER_SNAKE_CASE
83
+ * @returns The UPPER_SNAKE_CASE formatted string
84
+ */
85
+ export declare function upperSnakeCase(name: string | string[]): string;
86
+ export declare function resolvePropertyName(name: string): string;
87
+ /**
88
+ * The member key an enum value prefers, before quoting: its UPPER_SNAKE_CASE
89
+ * form, `NUM_` and the digits for a number.
90
+ */
91
+ export declare function enumMemberKey(name: string): string;
92
+ /**
93
+ * Renders a value as a single-quoted TypeScript string literal.
94
+ *
95
+ * A property name is whatever the document says it is, so one carrying a
96
+ * quote or a backslash has to be escaped rather than wrapped - `owner'sName`
97
+ * would otherwise close the literal and generate a syntax error.
98
+ *
99
+ * @param value - The string to render
100
+ * @returns The escaped string literal, quotes included
101
+ */
102
+ export declare function quoteStringLiteral(value: string): string;
@@ -0,0 +1,2 @@
1
+ /** Compares two names in the fixed `en-US` order; a comparator for `sort`. */
2
+ export declare function compareNames(left: string, right: string): number;
@@ -0,0 +1,2 @@
1
+ /** Compares two names in the fixed `en-US` order; a comparator for `sort`. */
2
+ export declare function compareNames(left: string, right: string): number;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Joins a relative path onto a base with exactly one `/` between them, as
3
+ * `@ahoo-wang/fetcher`'s `combineURLs` does, so the generator process need
4
+ * not load fetcher for it: `('a/', '/b.ts')` → `a/b.ts`. An empty relative
5
+ * path gives the base, and a URL with a scheme (`https://…`, `//host/…`)
6
+ * replaces it.
7
+ *
8
+ * @param base - The path to join onto
9
+ * @param relative - The path to join
10
+ */
11
+ export declare function combinePaths(base: string, relative: string): string;
12
+ /** The file every model of a package is declared in. */
13
+ export declare const MODEL_FILE_NAME = "types.ts";
14
+ /**
15
+ * The file a model is declared in, relative to the output directory: the
16
+ * `types.ts` of its package.
17
+ *
18
+ * @param model - The model, whose path is its package (`/` for the root)
19
+ */
20
+ export declare function modelFilePath(model: {
21
+ readonly path: string;
22
+ }): string;
23
+ /**
24
+ * The file that declares a bounded context's alias constant, relative to the
25
+ * output directory.
26
+ */
27
+ export declare function boundedContextFilePath(contextAlias: string): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Joins a relative path onto a base with exactly one `/` between them, as
3
+ * `@ahoo-wang/fetcher`'s `combineURLs` does, so the generator process need
4
+ * not load fetcher for it: `('a/', '/b.ts')` → `a/b.ts`. An empty relative
5
+ * path gives the base, and a URL with a scheme (`https://…`, `//host/…`)
6
+ * replaces it.
7
+ *
8
+ * @param base - The path to join onto
9
+ * @param relative - The path to join
10
+ */
11
+ export declare function combinePaths(base: string, relative: string): string;
12
+ /** The file every model of a package is declared in. */
13
+ export declare const MODEL_FILE_NAME = "types.ts";
14
+ /**
15
+ * The file a model is declared in, relative to the output directory: the
16
+ * `types.ts` of its package.
17
+ *
18
+ * @param model - The model, whose path is its package (`/` for the root)
19
+ */
20
+ export declare function modelFilePath(model: {
21
+ readonly path: string;
22
+ }): string;
23
+ /**
24
+ * The file that declares a bounded context's alias constant, relative to the
25
+ * output directory.
26
+ */
27
+ export declare function boundedContextFilePath(contextAlias: string): string;
@@ -0,0 +1,55 @@
1
+ import { Components, Parameter, Reference, RequestBody, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /** Prefix for OpenAPI components references */
3
+ export declare const COMPONENTS_PREFIX = "#/components/";
4
+ /** Reference prefix for parameters components */
5
+ export declare const COMPONENTS_PARAMETERS_REF = "#/components/parameters/";
6
+ /** Reference prefix for request bodies components */
7
+ export declare const COMPONENTS_REQUEST_BODIES_REF = "#/components/requestBodies/";
8
+ /** Reference prefix for responses components */
9
+ export declare const COMPONENTS_RESPONSES_REF = "#/components/responses/";
10
+ /** Reference prefix for schemas components */
11
+ export declare const COMPONENTS_SCHEMAS_REF = "#/components/schemas/";
12
+ /**
13
+ * Represents a schema with its key identifier.
14
+ */
15
+ export interface KeySchema<T extends Schema | Reference = Schema> {
16
+ /** The schema key */
17
+ key: string;
18
+ /** The schema definition */
19
+ schema: T;
20
+ }
21
+ /**
22
+ * Extracts the component key from an OpenAPI reference.
23
+ * @param reference - The OpenAPI reference object
24
+ * @returns The component key (last part of the reference path)
25
+ */
26
+ export declare function extractComponentKey(reference: Reference): string;
27
+ export declare function extractSchema(reference: Reference, components: Components): Schema | undefined;
28
+ /**
29
+ * Extracts a response from OpenAPI components using a reference.
30
+ * @param reference - The reference to the response
31
+ * @param components - The OpenAPI components object
32
+ * @returns The response if found, undefined otherwise
33
+ */
34
+ export declare function extractResponse(reference: Reference, components: Components): Response | undefined;
35
+ /**
36
+ * Extracts a request body from OpenAPI components using a reference.
37
+ * @param reference - The reference to the request body
38
+ * @param components - The OpenAPI components object
39
+ * @returns The request body if found, undefined otherwise
40
+ */
41
+ export declare function extractRequestBody(reference: Reference, components: Components): RequestBody | undefined;
42
+ /**
43
+ * Extracts a parameter from OpenAPI components using a reference.
44
+ * @param reference - The reference to the parameter
45
+ * @param components - The OpenAPI components object
46
+ * @returns The parameter if found, undefined otherwise
47
+ */
48
+ export declare function extractParameter(reference: Reference, components: Components): Parameter | undefined;
49
+ /**
50
+ * Creates a KeySchema object from a reference and components.
51
+ * @param reference - The reference to the schema
52
+ * @param components - The OpenAPI components object
53
+ * @returns A KeySchema containing the key and resolved schema
54
+ */
55
+ export declare function keySchema(reference: Reference, components: Components): KeySchema;
@@ -0,0 +1,55 @@
1
+ import { Components, Parameter, Reference, RequestBody, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /** Prefix for OpenAPI components references */
3
+ export declare const COMPONENTS_PREFIX = "#/components/";
4
+ /** Reference prefix for parameters components */
5
+ export declare const COMPONENTS_PARAMETERS_REF = "#/components/parameters/";
6
+ /** Reference prefix for request bodies components */
7
+ export declare const COMPONENTS_REQUEST_BODIES_REF = "#/components/requestBodies/";
8
+ /** Reference prefix for responses components */
9
+ export declare const COMPONENTS_RESPONSES_REF = "#/components/responses/";
10
+ /** Reference prefix for schemas components */
11
+ export declare const COMPONENTS_SCHEMAS_REF = "#/components/schemas/";
12
+ /**
13
+ * Represents a schema with its key identifier.
14
+ */
15
+ export interface KeySchema<T extends Schema | Reference = Schema> {
16
+ /** The schema key */
17
+ key: string;
18
+ /** The schema definition */
19
+ schema: T;
20
+ }
21
+ /**
22
+ * Extracts the component key from an OpenAPI reference.
23
+ * @param reference - The OpenAPI reference object
24
+ * @returns The component key (last part of the reference path)
25
+ */
26
+ export declare function extractComponentKey(reference: Reference): string;
27
+ export declare function extractSchema(reference: Reference, components: Components): Schema | undefined;
28
+ /**
29
+ * Extracts a response from OpenAPI components using a reference.
30
+ * @param reference - The reference to the response
31
+ * @param components - The OpenAPI components object
32
+ * @returns The response if found, undefined otherwise
33
+ */
34
+ export declare function extractResponse(reference: Reference, components: Components): Response | undefined;
35
+ /**
36
+ * Extracts a request body from OpenAPI components using a reference.
37
+ * @param reference - The reference to the request body
38
+ * @param components - The OpenAPI components object
39
+ * @returns The request body if found, undefined otherwise
40
+ */
41
+ export declare function extractRequestBody(reference: Reference, components: Components): RequestBody | undefined;
42
+ /**
43
+ * Extracts a parameter from OpenAPI components using a reference.
44
+ * @param reference - The reference to the parameter
45
+ * @param components - The OpenAPI components object
46
+ * @returns The parameter if found, undefined otherwise
47
+ */
48
+ export declare function extractParameter(reference: Reference, components: Components): Parameter | undefined;
49
+ /**
50
+ * Creates a KeySchema object from a reference and components.
51
+ * @param reference - The reference to the schema
52
+ * @param components - The OpenAPI components object
53
+ * @returns A KeySchema containing the key and resolved schema
54
+ */
55
+ export declare function keySchema(reference: Reference, components: Components): KeySchema;
@@ -0,0 +1,25 @@
1
+ import { Components, OpenAPI } from '@ahoo-wang/fetcher-openapi';
2
+ import { OperationEndpoint } from './operations.cjs';
3
+ /**
4
+ * A parsed OpenAPI document as the generator reads it: the document itself,
5
+ * which nothing changes, and its operations, listed once.
6
+ */
7
+ export interface OpenApiDocument {
8
+ /** The parsed document. Read only: every stage reads the same one. */
9
+ readonly openAPI: OpenAPI;
10
+ /** Its components, if it has any. */
11
+ readonly components?: Components;
12
+ /**
13
+ * Every operation with its method and path, the path item's parameters
14
+ * merged into its own (an operation's parameter overrides the path item's
15
+ * one of the same name and location), ordered by operation id, then path,
16
+ * then method.
17
+ */
18
+ readonly endpoints: readonly OperationEndpoint[];
19
+ }
20
+ /**
21
+ * Reads a parsed document: lists its operations once, for every stage.
22
+ *
23
+ * @param openAPI - The parsed document; left unchanged
24
+ */
25
+ export declare function openApiDocument(openAPI: OpenAPI): OpenApiDocument;
@@ -0,0 +1,25 @@
1
+ import { Components, OpenAPI } from '@ahoo-wang/fetcher-openapi';
2
+ import { OperationEndpoint } from './operations.js';
3
+ /**
4
+ * A parsed OpenAPI document as the generator reads it: the document itself,
5
+ * which nothing changes, and its operations, listed once.
6
+ */
7
+ export interface OpenApiDocument {
8
+ /** The parsed document. Read only: every stage reads the same one. */
9
+ readonly openAPI: OpenAPI;
10
+ /** Its components, if it has any. */
11
+ readonly components?: Components;
12
+ /**
13
+ * Every operation with its method and path, the path item's parameters
14
+ * merged into its own (an operation's parameter overrides the path item's
15
+ * one of the same name and location), ordered by operation id, then path,
16
+ * then method.
17
+ */
18
+ readonly endpoints: readonly OperationEndpoint[];
19
+ }
20
+ /**
21
+ * Reads a parsed document: lists its operations once, for every stage.
22
+ *
23
+ * @param openAPI - The parsed document; left unchanged
24
+ */
25
+ export declare function openApiDocument(openAPI: OpenAPI): OpenApiDocument;
@@ -0,0 +1,78 @@
1
+ import { Components, HTTPMethod, Operation, Parameter, PathItem, Paths, Reference, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /**
3
+ * Represents an HTTP method and its associated operation.
4
+ */
5
+ export interface MethodOperation {
6
+ /** The HTTP method */
7
+ method: HTTPMethod;
8
+ /** The OpenAPI operation */
9
+ operation: Operation;
10
+ }
11
+ export interface OperationEndpoint extends MethodOperation {
12
+ path: string;
13
+ }
14
+ export declare function operationEndpointComparator(left: OperationEndpoint, right: OperationEndpoint): number;
15
+ export declare function extractOperationEndpoints(paths: Paths, components?: Components): Array<OperationEndpoint>;
16
+ /**
17
+ * Extracts all operations from a path item.
18
+ * @param pathItem - The OpenAPI path item
19
+ * @returns Array of method-operation pairs
20
+ */
21
+ export declare function extractOperations(pathItem: PathItem): MethodOperation[];
22
+ /**
23
+ * Picks the status code of an operation's success response: `200`, else the
24
+ * lowest other 2xx code, else `2XX`.
25
+ *
26
+ * @param operation - The OpenAPI operation
27
+ * @returns The status code key, or undefined when no 2xx response is declared
28
+ */
29
+ export declare function okResponseStatus(operation: Operation): string | undefined;
30
+ /**
31
+ * Extracts the success response from an operation: `200`, else the lowest
32
+ * other 2xx response, else `2XX`.
33
+ * @param operation - The OpenAPI operation
34
+ * @param components - Optional components used to resolve response references
35
+ * @returns The success response or undefined if not found
36
+ */
37
+ export declare function extractOkResponse(operation: Operation, components?: Components): Response | Reference | undefined;
38
+ /**
39
+ * Extracts the JSON schema from the OK response of an operation.
40
+ * @param operation - The OpenAPI operation
41
+ * @param components - Optional components used to resolve response references
42
+ * @returns The JSON schema from the OK response or undefined if not found
43
+ */
44
+ export declare function extractOperationOkResponseJsonSchema(operation: Operation, components?: Components): Schema | Reference | undefined;
45
+ /**
46
+ * Extracts the parameters of an operation, references resolved, in document
47
+ * order.
48
+ * @param operation - The OpenAPI operation
49
+ * @param components - The OpenAPI components object used to resolve references
50
+ * @returns The parameters
51
+ */
52
+ export declare function extractParameters(operation: Operation, components: Components): Parameter[];
53
+ /**
54
+ * Extracts path parameters from an operation.
55
+ * @param operation - The OpenAPI operation to extract path parameters from
56
+ * @param components - The OpenAPI components object used to resolve references
57
+ * @returns Array of path parameters
58
+ */
59
+ export declare function extractPathParameters(operation: Operation, components: Components): Parameter[];
60
+ /**
61
+ * Orders path parameters as the path holds them, whatever order the document
62
+ * lists them in: `/cart/{id}/{customerId}` gives `id`, then `customerId`.
63
+ * A method takes them in this order, so a route that gains a variable keeps
64
+ * the arguments before it where they were. Parameters the path does not
65
+ * hold keep their order, after the others.
66
+ *
67
+ * @param path - The route, with `{name}` variables
68
+ * @param parameters - Its path parameters
69
+ * @returns A new array, sorted
70
+ */
71
+ export declare function inPathOrder<P extends Pick<Parameter, 'name'>>(path: string, parameters: readonly P[]): P[];
72
+ /**
73
+ * Resolves the type of a path parameter.
74
+ * @param parameter - The path parameter to resolve the type for
75
+ * @returns The resolved primitive type as a string, or the default path parameter type if the schema is missing,
76
+ * is a reference, lacks a type, or the type is not primitive
77
+ */
78
+ export declare function resolvePathParameterType(parameter: Parameter): string;