swagger-sdk-generator 0.0.0-stage → 3.0.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.
- package/README.md +58 -2
- package/dist/cli/commands/generate.d.ts +2 -0
- package/dist/cli/commands/generate.js +196 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +130 -0
- package/dist/cli/commands/inspect.d.ts +2 -0
- package/dist/cli/commands/inspect.js +164 -0
- package/dist/cli/commands/templates.d.ts +2 -0
- package/dist/cli/commands/templates.js +126 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/context.js +85 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +25 -0
- package/dist/config/dotenv.d.ts +2 -0
- package/dist/config/dotenv.js +82 -0
- package/dist/config/interpolate.d.ts +8 -0
- package/dist/config/interpolate.js +85 -0
- package/dist/config/load.d.ts +11 -0
- package/dist/config/load.js +182 -0
- package/dist/config/migrate-v3.d.ts +5 -0
- package/dist/config/migrate-v3.js +6 -0
- package/dist/config/mode-compatibility.d.ts +9 -0
- package/dist/config/mode-compatibility.js +17 -0
- package/dist/config/modes.d.ts +13 -0
- package/dist/config/modes.js +27 -0
- package/dist/config/preset-definitions.d.ts +2 -0
- package/dist/config/preset-definitions.js +4 -0
- package/dist/config/presets.d.ts +25 -0
- package/dist/config/presets.js +36 -0
- package/dist/config/resolve.d.ts +32 -0
- package/dist/config/resolve.js +288 -0
- package/dist/config/schema.d.ts +93 -0
- package/dist/config/schema.js +173 -0
- package/dist/config/types.d.ts +42 -0
- package/dist/config/types.js +2 -0
- package/dist/config/workspace.d.ts +30 -0
- package/dist/config/workspace.js +95 -0
- package/dist/core/case-align.d.ts +5 -0
- package/dist/core/case-align.js +90 -0
- package/dist/core/deep-merge.d.ts +2 -0
- package/dist/core/deep-merge.js +21 -0
- package/dist/core/file-set.d.ts +10 -0
- package/dist/core/file-set.js +31 -0
- package/dist/core/import-module.d.ts +1 -0
- package/dist/core/import-module.js +61 -0
- package/dist/core/log.d.ts +9 -0
- package/dist/core/log.js +24 -0
- package/dist/core/manifest.d.ts +17 -0
- package/dist/core/manifest.js +195 -0
- package/dist/core/overlaps.d.ts +6 -0
- package/dist/core/overlaps.js +67 -0
- package/dist/core/package-version.d.ts +1 -0
- package/dist/core/package-version.js +44 -0
- package/dist/core/pipeline.d.ts +30 -0
- package/dist/core/pipeline.js +335 -0
- package/dist/core/plugin.d.ts +72 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/targets.d.ts +14 -0
- package/dist/core/targets.js +120 -0
- package/dist/core/unmanaged.d.ts +3 -0
- package/dist/core/unmanaged.js +101 -0
- package/dist/core/writer.d.ts +28 -0
- package/dist/core/writer.js +148 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +37 -0
- package/dist/ir/casing.d.ts +5 -0
- package/dist/ir/casing.js +22 -0
- package/dist/ir/graph.d.ts +8 -0
- package/dist/ir/graph.js +95 -0
- package/dist/ir/operations/grouping.d.ts +17 -0
- package/dist/ir/operations/grouping.js +39 -0
- package/dist/ir/operations/legacy-naming.d.ts +2 -0
- package/dist/ir/operations/legacy-naming.js +8 -0
- package/dist/ir/operations/naming.d.ts +6 -0
- package/dist/ir/operations/naming.js +54 -0
- package/dist/ir/option-errors.d.ts +3 -0
- package/dist/ir/option-errors.js +68 -0
- package/dist/ir/transforms/builtins.d.ts +2 -0
- package/dist/ir/transforms/builtins.js +4 -0
- package/dist/ir/transforms/index.d.ts +10 -0
- package/dist/ir/transforms/index.js +39 -0
- package/dist/ir/transforms/types.d.ts +9 -0
- package/dist/ir/transforms/types.js +2 -0
- package/dist/ir/types.d.ts +140 -0
- package/dist/ir/types.js +2 -0
- package/dist/runtime/axios.d.ts +28 -0
- package/dist/runtime/axios.js +132 -0
- package/dist/runtime/fetch.d.ts +6 -0
- package/dist/runtime/fetch.js +38 -0
- package/dist/runtime/index.d.ts +54 -0
- package/dist/runtime/index.js +167 -0
- package/dist/runtime/rtk.d.ts +35 -0
- package/dist/runtime/rtk.js +36 -0
- package/dist/runtime/transport.d.ts +38 -0
- package/dist/runtime/transport.js +30 -0
- package/dist/runtime/wire.d.ts +27 -0
- package/dist/runtime/wire.js +148 -0
- package/dist/spec/html-entities.d.ts +1 -0
- package/dist/spec/html-entities.js +25 -0
- package/dist/spec/load.d.ts +26 -0
- package/dist/spec/load.js +130 -0
- package/dist/spec/openapi/all-of.d.ts +3 -0
- package/dist/spec/openapi/all-of.js +9 -0
- package/dist/spec/openapi/normalize.d.ts +4 -0
- package/dist/spec/openapi/normalize.js +31 -0
- package/dist/spec/openapi/operations.d.ts +4 -0
- package/dist/spec/openapi/operations.js +173 -0
- package/dist/spec/openapi/schema.d.ts +51 -0
- package/dist/spec/openapi/schema.js +307 -0
- package/dist/targets/declarative/config.d.ts +533 -0
- package/dist/targets/declarative/config.js +280 -0
- package/dist/targets/declarative/extensions.d.ts +45 -0
- package/dist/targets/declarative/extensions.js +123 -0
- package/dist/targets/declarative/files.d.ts +13 -0
- package/dist/targets/declarative/files.js +127 -0
- package/dist/targets/declarative/format.d.ts +4 -0
- package/dist/targets/declarative/format.js +104 -0
- package/dist/targets/declarative/index.d.ts +9 -0
- package/dist/targets/declarative/index.js +170 -0
- package/dist/targets/declarative/liquid.d.ts +8 -0
- package/dist/targets/declarative/liquid.js +57 -0
- package/dist/targets/declarative/naming-case.d.ts +3 -0
- package/dist/targets/declarative/naming-case.js +31 -0
- package/dist/targets/declarative/naming.d.ts +42 -0
- package/dist/targets/declarative/naming.js +174 -0
- package/dist/targets/declarative/scaffold.d.ts +5 -0
- package/dist/targets/declarative/scaffold.js +146 -0
- package/dist/targets/declarative/types.d.ts +52 -0
- package/dist/targets/declarative/types.js +287 -0
- package/dist/targets/declarative/views.d.ts +180 -0
- package/dist/targets/declarative/views.js +447 -0
- package/dist/targets/python/extensions.js +152 -0
- package/dist/targets/python/target.json +549 -0
- package/dist/targets/python/templates/client/client.liquid +114 -0
- package/dist/targets/python/templates/client/httpx_transport.liquid +172 -0
- package/dist/targets/python/templates/client/init.liquid +20 -0
- package/dist/targets/python/templates/client/partials/operation_method.liquid +41 -0
- package/dist/targets/python/templates/client/resource.liquid +28 -0
- package/dist/targets/python/templates/client/runtime.liquid +133 -0
- package/dist/targets/python/templates/client/transport.liquid +62 -0
- package/dist/targets/python/templates/models/module.liquid +48 -0
- package/dist/targets/python/templates/models/partials/docstring.liquid +5 -0
- package/dist/targets/python/templates/models/partials/enum_class.liquid +11 -0
- package/dist/targets/python/templates/models/partials/field_line.liquid +5 -0
- package/dist/targets/python/templates/models/partials/model_class.liquid +17 -0
- package/dist/targets/typescript/compatibility-naming.d.ts +6 -0
- package/dist/targets/typescript/compatibility-naming.js +28 -0
- package/dist/targets/typescript/compatibility-options.d.ts +5 -0
- package/dist/targets/typescript/compatibility-options.js +8 -0
- package/dist/targets/typescript/compatibility-target.d.ts +5 -0
- package/dist/targets/typescript/compatibility-target.js +10 -0
- package/dist/targets/typescript/http-operations.d.ts +34 -0
- package/dist/targets/typescript/http-operations.js +155 -0
- package/dist/targets/typescript/imports.d.ts +43 -0
- package/dist/targets/typescript/imports.js +154 -0
- package/dist/targets/typescript/index.d.ts +7 -0
- package/dist/targets/typescript/index.js +52 -0
- package/dist/targets/typescript/mock-compatibility.d.ts +4 -0
- package/dist/targets/typescript/mock-compatibility.js +6 -0
- package/dist/targets/typescript/mock-hints.d.ts +13 -0
- package/dist/targets/typescript/mock-hints.js +75 -0
- package/dist/targets/typescript/mock-reachability.d.ts +12 -0
- package/dist/targets/typescript/mock-reachability.js +87 -0
- package/dist/targets/typescript/model-compatibility.d.ts +14 -0
- package/dist/targets/typescript/model-compatibility.js +16 -0
- package/dist/targets/typescript/naming.d.ts +13 -0
- package/dist/targets/typescript/naming.js +50 -0
- package/dist/targets/typescript/options.d.ts +124 -0
- package/dist/targets/typescript/options.js +90 -0
- package/dist/targets/typescript/outputs/client.d.ts +67 -0
- package/dist/targets/typescript/outputs/client.js +187 -0
- package/dist/targets/typescript/outputs/mocks.d.ts +32 -0
- package/dist/targets/typescript/outputs/mocks.js +371 -0
- package/dist/targets/typescript/outputs/models.d.ts +85 -0
- package/dist/targets/typescript/outputs/models.js +246 -0
- package/dist/targets/typescript/outputs/rtk-query.d.ts +69 -0
- package/dist/targets/typescript/outputs/rtk-query.js +266 -0
- package/dist/targets/typescript/prettier.d.ts +7 -0
- package/dist/targets/typescript/prettier.js +44 -0
- package/dist/targets/typescript/templates/client/client.liquid +30 -0
- package/dist/targets/typescript/templates/client/partials/api-member.liquid +13 -0
- package/dist/targets/typescript/templates/client/partials/jsdoc.liquid +10 -0
- package/dist/targets/typescript/templates/client/partials/method.liquid +26 -0
- package/dist/targets/typescript/templates/client/partials/query-type.liquid +10 -0
- package/dist/targets/typescript/templates/client/resource.liquid +34 -0
- package/dist/targets/typescript/templates/mocks/mock.liquid +15 -0
- package/dist/targets/typescript/templates/mocks/partials/factory.liquid +12 -0
- package/dist/targets/typescript/templates/mocks/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/models/alias.liquid +16 -0
- package/dist/targets/typescript/templates/models/enum.liquid +27 -0
- package/dist/targets/typescript/templates/models/index.liquid +14 -0
- package/dist/targets/typescript/templates/models/model.liquid +25 -0
- package/dist/targets/typescript/templates/models/partials/const.liquid +10 -0
- package/dist/targets/typescript/templates/models/partials/imports.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/jsdoc.liquid +9 -0
- package/dist/targets/typescript/templates/models/partials/property.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/api.liquid +16 -0
- package/dist/targets/typescript/templates/rtk-query/partials/arg-types.liquid +6 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-mutation.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/endpoint-query.liquid +13 -0
- package/dist/targets/typescript/templates/rtk-query/partials/file-warning.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/hooks.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/partials/imports.liquid +7 -0
- package/dist/targets/typescript/templates/rtk-query/partials/request-config.liquid +9 -0
- package/dist/targets/typescript/templates/rtk-query/resource.liquid +40 -0
- package/dist/targets/typescript/ts-type.d.ts +70 -0
- package/dist/targets/typescript/ts-type.js +62 -0
- package/dist/targets/typescript/type-printer.d.ts +21 -0
- package/dist/targets/typescript/type-printer.js +115 -0
- package/dist/templates/engine.d.ts +20 -0
- package/dist/templates/engine.js +161 -0
- package/dist/templates/inspect.d.ts +27 -0
- package/dist/templates/inspect.js +331 -0
- package/package.json +65 -4
- package/schema/sdk-gen.local.schema.json +75 -0
- package/schema/sdk-gen.schema.json +980 -0
- package/schema/sdk-gen.target.schema.json +1384 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
One member of the object `createApi()` returns: `key: createXApi(send),` or a folder `key: { … },`.
|
|
3
|
+
Data: member: ClientApiMemberView
|
|
4
|
+
{% endcomment -%}
|
|
5
|
+
{% if member.factoryName -%}
|
|
6
|
+
{{ member.key }}: {{ member.factoryName }}(send),
|
|
7
|
+
{% else -%}
|
|
8
|
+
{{ member.key }}: {
|
|
9
|
+
{% for child in member.children -%}
|
|
10
|
+
{{ child.key }}: {{ child.factoryName }}(send),
|
|
11
|
+
{% endfor -%}
|
|
12
|
+
},
|
|
13
|
+
{% endif -%}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
A JSDoc block (with its trailing newline) from pre-split lines (`*/` already neutralized);
|
|
3
|
+
nothing when there are no lines.
|
|
4
|
+
Data: doc: string[]
|
|
5
|
+
{% endcomment -%}
|
|
6
|
+
{% if doc.size > 0 -%}
|
|
7
|
+
/**
|
|
8
|
+
{% for line in doc %} *{% if line != "" %} {{ line }}{% endif %}
|
|
9
|
+
{% endfor %} */
|
|
10
|
+
{% endif -%}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
One API method: its parameters, then a single `send()` call describing the request.
|
|
3
|
+
Data: method: ClientMethodView
|
|
4
|
+
{% endcomment -%}
|
|
5
|
+
{% render 'client/partials/jsdoc', doc: method.doc -%}
|
|
6
|
+
{{ method.name }}({% for param in method.params %}{{ param.name }}{% if param.optional %}?{% endif %}: {{ param.type }}{% unless forloop.last %}, {% endunless %}{% endfor %}): Promise<{{ method.successType }}> {
|
|
7
|
+
return send<{{ method.successType }}>(
|
|
8
|
+
{
|
|
9
|
+
operation: {{ method.operation | quote }},
|
|
10
|
+
method: {{ method.method | quote }},
|
|
11
|
+
path: `{{ method.path }}`,
|
|
12
|
+
{% if method.queryType -%}
|
|
13
|
+
query,
|
|
14
|
+
{% endif -%}
|
|
15
|
+
{% if method.headerParams.size > 0 -%}
|
|
16
|
+
headerParams: [{% for header in method.headerParams %}{% if header.key == header.name %}{{ header.name | quote }}{% else %}[{{ header.key | quote }}, {{ header.name | quote }}]{% endif %}{% unless forloop.last %}, {% endunless %}{% endfor %}],
|
|
17
|
+
{% endif -%}
|
|
18
|
+
{% if method.hasBody -%}
|
|
19
|
+
body,
|
|
20
|
+
contentType: {{ method.contentType | quote }},
|
|
21
|
+
{% endif -%}
|
|
22
|
+
responseType: {{ method.responseType | quote }},
|
|
23
|
+
},
|
|
24
|
+
options,
|
|
25
|
+
);
|
|
26
|
+
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
`<Op>Query`: the operation's query and header parameters (header ones are sent as request headers).
|
|
3
|
+
Data: method: ClientMethodView
|
|
4
|
+
{% endcomment -%}
|
|
5
|
+
export type {{ method.queryType }} = {
|
|
6
|
+
{% for field in method.queryFields -%}
|
|
7
|
+
{% render 'client/partials/jsdoc', doc: field.doc -%}
|
|
8
|
+
{{ field.key }}{% if field.optional %}?{% endif %}: {{ field.type }};
|
|
9
|
+
{% endfor -%}
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
Renders one resource file of the client (`<resource>.ts`): the `<Op>Query` types, the
|
|
3
|
+
`create<Resource>Api(send)` factory (one method per operation) and its `<Resource>Api` type.
|
|
4
|
+
Data: ClientResourceView
|
|
5
|
+
{% endcomment -%}
|
|
6
|
+
{{ banner }}
|
|
7
|
+
{% block imports -%}
|
|
8
|
+
import type { RequestOptions, Send } from "swagger-sdk-generator/runtime";
|
|
9
|
+
{% for import in imports -%}
|
|
10
|
+
import {% if import.typeOnly %}type {% endif %}{ {{ import.names }} } from {{ import.specifier | quote }};
|
|
11
|
+
{% endfor -%}
|
|
12
|
+
{% endblock %}
|
|
13
|
+
|
|
14
|
+
{% block types -%}
|
|
15
|
+
{% for method in methods -%}
|
|
16
|
+
{% if method.queryType -%}
|
|
17
|
+
{% render 'client/partials/query-type', method: method %}
|
|
18
|
+
|
|
19
|
+
{% endif -%}
|
|
20
|
+
{% endfor -%}
|
|
21
|
+
{% endblock %}
|
|
22
|
+
|
|
23
|
+
{% block factory -%}
|
|
24
|
+
export function {{ factoryName }}(send: Send) {
|
|
25
|
+
return {
|
|
26
|
+
{% for method in methods -%}
|
|
27
|
+
{% render 'client/partials/method', method: method %}
|
|
28
|
+
|
|
29
|
+
{% endfor -%}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type {{ typeName }} = ReturnType<typeof {{ factoryName }}>;
|
|
34
|
+
{% endblock %}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Generated deterministic mock factory file: banner, imports, and seeded `get<Name>Mock()` factory.
|
|
3
|
+
Data: MockFileView
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- block header -%}
|
|
6
|
+
{{ header }}
|
|
7
|
+
{% endblock -%}
|
|
8
|
+
{%- block imports -%}
|
|
9
|
+
import { faker } from '@faker-js/faker';
|
|
10
|
+
{% render 'mocks/partials/imports', imports: imports -%}
|
|
11
|
+
{% render 'mocks/partials/imports', imports: refImports %}
|
|
12
|
+
{% endblock -%}
|
|
13
|
+
{%- block factory -%}
|
|
14
|
+
{% render 'mocks/partials/factory', createName: createName, exportName: exportName, typeName: typeName, seed: seed, valueExpression: valueExpression, depthParam: depthParam %}
|
|
15
|
+
{%- endblock -%}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Unseeded `create<Name>Mock(depth)` (ref composition, bounded by maxDepth) plus seeded public `get<Name>Mock`; both hoisted, explicitly typed, nothing built at module load.
|
|
3
|
+
Data: createName, exportName, typeName, seed, valueExpression, depthParam
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
export function {{ createName }}({{ depthParam }}): {{ typeName }} {
|
|
6
|
+
return {{ valueExpression }};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function {{ exportName }}(): {{ typeName }} {
|
|
10
|
+
faker.seed({{ seed }});
|
|
11
|
+
return {{ createName }}();
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Import statements for a mock file, preserving the provided order (one per line, nothing when empty).
|
|
3
|
+
Data: MockImportView[] (as `imports`)
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- for import in imports -%}
|
|
6
|
+
import {% if import.typeOnly %}type {% endif %}{ {{ import.names }} } from '{{ import.specifier }}';
|
|
7
|
+
{% endfor -%}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Alias model file for any non-object, non-enum schema (array, union, primitive, map, …): `export type <Name> = <type>;`.
|
|
3
|
+
Data: AliasModelView
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- block header -%}
|
|
6
|
+
{%- if header %}{{ header }}
|
|
7
|
+
|
|
8
|
+
{% endif -%}
|
|
9
|
+
{%- endblock -%}
|
|
10
|
+
{%- block imports -%}
|
|
11
|
+
{%- render 'models/partials/imports', imports: imports -%}
|
|
12
|
+
{%- endblock -%}
|
|
13
|
+
{%- block type -%}
|
|
14
|
+
{%- render 'models/partials/jsdoc', lines: doc, indent: '' -%}
|
|
15
|
+
export type {{ name }} = {{ type }};
|
|
16
|
+
{% endblock -%}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Enum model file (`enumSchemas`): `export enum`, a literal-union alias, or an `as const` object + its value type.
|
|
3
|
+
Data: EnumModelView
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- block header -%}
|
|
6
|
+
{%- if header %}{{ header }}
|
|
7
|
+
|
|
8
|
+
{% endif -%}
|
|
9
|
+
{%- endblock -%}
|
|
10
|
+
{%- block enum -%}
|
|
11
|
+
{%- render 'models/partials/jsdoc', lines: doc, indent: '' -%}
|
|
12
|
+
{%- if style == 'enum' -%}
|
|
13
|
+
export enum {{ name }} {
|
|
14
|
+
{% for member in members %} {{ member.key }} = {{ member.value }},
|
|
15
|
+
{% endfor -%}
|
|
16
|
+
}
|
|
17
|
+
{% elsif style == 'union' -%}
|
|
18
|
+
export type {{ name }} = {{ union }};
|
|
19
|
+
{% else -%}
|
|
20
|
+
export const {{ name }} = {
|
|
21
|
+
{% for member in members %} {{ member.key }}: {{ member.value }},
|
|
22
|
+
{% endfor -%}
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
export type {{ name }} = (typeof {{ name }})[keyof typeof {{ name }}];
|
|
26
|
+
{% endif -%}
|
|
27
|
+
{%- endblock -%}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Barrel `index.ts` re-exporting every model's public names (first model wins on a name clash).
|
|
3
|
+
Data: IndexView
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- block header -%}
|
|
6
|
+
{%- if header %}{{ header }}
|
|
7
|
+
|
|
8
|
+
{% endif -%}
|
|
9
|
+
{%- endblock -%}
|
|
10
|
+
{%- block exports -%}
|
|
11
|
+
{%- for statement in exports -%}
|
|
12
|
+
{{ statement.keyword }} { {{ statement.names }} } from {{ statement.specifier | quote }};
|
|
13
|
+
{% endfor -%}
|
|
14
|
+
{%- endblock -%}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Object model file: banner, imports, hoisted enum consts, then `export type <Name> = { … }`.
|
|
3
|
+
Data: ObjectModelView
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- block header -%}
|
|
6
|
+
{%- if header %}{{ header }}
|
|
7
|
+
|
|
8
|
+
{% endif -%}
|
|
9
|
+
{%- endblock -%}
|
|
10
|
+
{%- block imports -%}
|
|
11
|
+
{%- render 'models/partials/imports', imports: imports -%}
|
|
12
|
+
{%- endblock -%}
|
|
13
|
+
{%- block consts -%}
|
|
14
|
+
{%- for item in consts -%}
|
|
15
|
+
{%- render 'models/partials/const', item: item -%}
|
|
16
|
+
{%- endfor -%}
|
|
17
|
+
{%- endblock -%}
|
|
18
|
+
{%- block type -%}
|
|
19
|
+
{%- render 'models/partials/jsdoc', lines: doc, indent: '' -%}
|
|
20
|
+
export type {{ name }} = {
|
|
21
|
+
{% for property in properties -%}
|
|
22
|
+
{%- render 'models/partials/property', property: property -%}
|
|
23
|
+
{%- endfor -%}
|
|
24
|
+
}{{ suffix }};
|
|
25
|
+
{% endblock -%}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
One hoisted enum object: `export const <Name> = { key: value, … }` (`as const` when asConst), then a blank line.
|
|
3
|
+
Data: ConstView (as `item`)
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
export const {{ item.name }} = {
|
|
6
|
+
{% for member in item.members %} {{ member.key }}: {{ member.value }},
|
|
7
|
+
{% endfor -%}
|
|
8
|
+
}{% if item.asConst %} as const{% endif %};
|
|
9
|
+
|
|
10
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
Import statements of one model file, then a blank line (nothing when there are none).
|
|
3
|
+
Data: ImportView[] (as `imports`)
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- for import in imports -%}
|
|
6
|
+
import {% if import.typeOnly %}type {% endif %}{ {{ import.names }} } from {{ import.specifier | quote }};
|
|
7
|
+
{% if forloop.last %}
|
|
8
|
+
{% endif -%}
|
|
9
|
+
{%- endfor -%}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
A JSDoc block, one ` * line` per entry (nothing when `lines` is null).
|
|
3
|
+
Data: string[] | null (as `lines`), indent string (as `indent`)
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- if lines -%}
|
|
6
|
+
{{ indent }}/**
|
|
7
|
+
{% for line in lines %}{{ indent }} *{% if line != '' %} {{ line }}{% endif %}
|
|
8
|
+
{% endfor %}{{ indent }} */
|
|
9
|
+
{% endif -%}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{%- comment -%}
|
|
2
|
+
One member of an object type: optional JSDoc, then `key?: type;`.
|
|
3
|
+
Data: PropertyView (as `property`)
|
|
4
|
+
{%- endcomment -%}
|
|
5
|
+
{%- render 'models/partials/jsdoc', lines: property.doc, indent: ' ' -%}
|
|
6
|
+
{{ property.key }}{% if property.optional %}?{% endif %}: {{ property.type }};
|
|
7
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{% render 'rtk-query/partials/file-warning' %}
|
|
2
|
+
import { createApi{% if toolkit %}, fetchBaseQuery{% endif %} } from "@reduxjs/toolkit/query/react";
|
|
3
|
+
{% unless toolkit -%}
|
|
4
|
+
import { createRtkRuntime } from "swagger-sdk-generator/runtime/rtk";
|
|
5
|
+
|
|
6
|
+
export const { transportBaseQuery, configureRtk } = createRtkRuntime({
|
|
7
|
+
defaultBaseUrl: {{ defaultBaseUrl | quote }},
|
|
8
|
+
fetchFallback: {{ fetchTransport }},
|
|
9
|
+
});
|
|
10
|
+
{% endunless %}
|
|
11
|
+
|
|
12
|
+
export const baseApi = createApi({
|
|
13
|
+
reducerPath: {{ reducerPath | quote }},
|
|
14
|
+
baseQuery: {% if toolkit %}fetchBaseQuery({ baseUrl: {{ defaultBaseUrl | quote }} }){% else %}transportBaseQuery{% endif %},
|
|
15
|
+
endpoints: () => ({}),
|
|
16
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
`<Name>ApiResponse` and `<Name>ApiArg` type aliases of one endpoint; no arg fields → `void`.
|
|
3
|
+
Data: RtkEndpointViewModel (as `endpoint`)
|
|
4
|
+
{% endcomment -%}
|
|
5
|
+
export type {{ endpoint.responseAlias }} = {{ endpoint.responseType }};
|
|
6
|
+
export type {{ endpoint.argAlias }} = {% if endpoint.argFields.size > 0 %}{ {% for field in endpoint.argFields %}{{ field.key }}{% if field.optional %}?{% endif %}: {{ field.type }}{% unless forloop.last %}; {% endunless %}{% endfor %} }{% else %}void{% endif %};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
One `build.mutation` endpoint. Owns the `invalidatesTags` list/id convention: a path id invalidates
|
|
3
|
+
that id + the LIST, no path id invalidates the LIST.
|
|
4
|
+
Data: RtkEndpointViewModel (as `endpoint`), tagType: string
|
|
5
|
+
{% endcomment -%}
|
|
6
|
+
{{ endpoint.name }}: build.mutation<{{ endpoint.responseAlias }}, {{ endpoint.argAlias }}>({
|
|
7
|
+
query: (queryArg) => ({% render 'rtk-query/partials/request-config', endpoint: endpoint %}),
|
|
8
|
+
{% if endpoint.idParam %}
|
|
9
|
+
invalidatesTags: (_result, _error, queryArg) => [{ type: {{ tagType | quote }} as const, id: {{ endpoint.idParam.accessor }} }, { type: {{ tagType | quote }} as const, id: "LIST" }],
|
|
10
|
+
{% else %}
|
|
11
|
+
invalidatesTags: [{ type: {{ tagType | quote }} as const, id: "LIST" }],
|
|
12
|
+
{% endif %}
|
|
13
|
+
}),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
One `build.query` endpoint. Owns the `providesTags` list/id convention: a path id tags that id,
|
|
3
|
+
no path id tags the LIST.
|
|
4
|
+
Data: RtkEndpointViewModel (as `endpoint`), tagType: string
|
|
5
|
+
{% endcomment -%}
|
|
6
|
+
{{ endpoint.name }}: build.query<{{ endpoint.responseAlias }}, {{ endpoint.argAlias }}>({
|
|
7
|
+
query: (queryArg) => ({% render 'rtk-query/partials/request-config', endpoint: endpoint %}),
|
|
8
|
+
{% if endpoint.idParam %}
|
|
9
|
+
providesTags: (_result, _error, queryArg) => [{ type: {{ tagType | quote }} as const, id: {{ endpoint.idParam.accessor }} }],
|
|
10
|
+
{% else %}
|
|
11
|
+
providesTags: [{ type: {{ tagType | quote }} as const, id: "LIST" }],
|
|
12
|
+
{% endif %}
|
|
13
|
+
}),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
Destructured `use*Query` / `use*Mutation` hook exports taken off the injected api const.
|
|
3
|
+
Data: endpoints: RtkEndpointViewModel[], apiConstName: string
|
|
4
|
+
{% endcomment -%}
|
|
5
|
+
export const {
|
|
6
|
+
{% for endpoint in endpoints %}
|
|
7
|
+
{{ endpoint.hookName }},
|
|
8
|
+
{% endfor %}
|
|
9
|
+
} = {{ apiConstName }};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
The request object returned by an endpoint's `query: (queryArg) => (...)`: url (literal or
|
|
3
|
+
template literal over path params), explicit method for non-GET, body, query params, header
|
|
4
|
+
params (optional ones only when set), and with `runtime: "transport"` the spec's contentType /
|
|
5
|
+
responseType when they are not the defaults.
|
|
6
|
+
Inline (single line, no trailing newline).
|
|
7
|
+
Data: RtkEndpointViewModel (as `endpoint`)
|
|
8
|
+
{% endcomment -%}
|
|
9
|
+
{ url: {% if endpoint.hasPathParams %}`{% for part in endpoint.urlParts %}{% if part.accessor %}{{ '${' }}{{ part.accessor }}}{% else %}{{ part.text }}{% endif %}{% endfor %}`{% else %}{{ endpoint.path | quote }}{% endif %}{% if endpoint.emitMethod %}, method: {{ endpoint.httpMethod | quote }}{% endif %}{% if endpoint.body %}, body: {{ endpoint.body.accessor }}{% endif %}{% if endpoint.queryParams.size > 0 %}, params: { {% for param in endpoint.queryParams %}{{ param.key }}: {{ param.accessor }}{% unless forloop.last %}, {% endunless %}{% endfor %} }{% endif %}{% if endpoint.headerParams.size > 0 %}, headers: { {% for header in endpoint.headerParams %}{% if header.required %}{{ header.key }}: String({{ header.accessor }}){% else %}...({{ header.accessor }} != null ? { {{ header.key }}: String({{ header.accessor }}) } : {}){% endif %}{% unless forloop.last %}, {% endunless %}{% endfor %} }{% endif %}{% if endpoint.contentType %}, contentType: {{ endpoint.contentType | quote }}{% endif %}{% if endpoint.readAs %}, responseType: {{ endpoint.readAs | quote }} as const{% endif %}{% if endpoint.toolkitHandler == 'blob' %}, responseHandler: (response: Response) => response.blob(){% elsif endpoint.toolkitHandler == 'text' %}, responseHandler: "text" as const{% endif %} }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{% comment -%}
|
|
2
|
+
Renders one RTK Query resource file (`<apiConstName>.ts`): arg/response type aliases,
|
|
3
|
+
one `injectEndpoints` call (an endpoint per operation), then the destructured hook exports.
|
|
4
|
+
Data: RtkResourceViewModel
|
|
5
|
+
{% endcomment -%}
|
|
6
|
+
{% block header %}
|
|
7
|
+
{% render 'rtk-query/partials/file-warning' %}
|
|
8
|
+
{% endblock %}
|
|
9
|
+
|
|
10
|
+
{% block imports %}
|
|
11
|
+
import { baseApi } from {{ baseApiImport | quote }};
|
|
12
|
+
{% render 'rtk-query/partials/imports', imports: imports %}
|
|
13
|
+
{% endblock %}
|
|
14
|
+
|
|
15
|
+
{% block types %}
|
|
16
|
+
{% for endpoint in endpoints %}
|
|
17
|
+
{% render 'rtk-query/partials/arg-types', endpoint: endpoint %}
|
|
18
|
+
{% endfor %}
|
|
19
|
+
{% endblock %}
|
|
20
|
+
|
|
21
|
+
{% block api %}
|
|
22
|
+
export const {{ apiConstName }} = baseApi
|
|
23
|
+
.enhanceEndpoints({ addTagTypes: [{{ tagType | quote }}] })
|
|
24
|
+
.injectEndpoints({
|
|
25
|
+
endpoints: (build) => ({
|
|
26
|
+
{% for endpoint in endpoints %}
|
|
27
|
+
{% if endpoint.builder == 'query' %}
|
|
28
|
+
{% render 'rtk-query/partials/endpoint-query', endpoint: endpoint, tagType: tagType %}
|
|
29
|
+
{% else %}
|
|
30
|
+
{% render 'rtk-query/partials/endpoint-mutation', endpoint: endpoint, tagType: tagType %}
|
|
31
|
+
{% endif %}
|
|
32
|
+
{% endfor %}
|
|
33
|
+
}),
|
|
34
|
+
overrideExisting: false,
|
|
35
|
+
});
|
|
36
|
+
{% endblock %}
|
|
37
|
+
|
|
38
|
+
{% block hooks %}
|
|
39
|
+
{% render 'rtk-query/partials/hooks', endpoints: endpoints, apiConstName: apiConstName %}
|
|
40
|
+
{% endblock %}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { EnumValue, ModelId, TypeNode } from '../../ir/types';
|
|
2
|
+
import { type ConstMember } from './naming';
|
|
3
|
+
export type TsType = TsKeyword | TsLiteral | TsNamed | TsRef | TsArray | TsRecord | TsObject | TsUnion | TsIntersection | TsWidened | TsConstRef | TsEnumRef;
|
|
4
|
+
export type TsKeywordName = 'string' | 'number' | 'boolean' | 'unknown' | 'any' | 'object' | 'null' | 'undefined' | 'void' | 'never';
|
|
5
|
+
export interface TsKeyword {
|
|
6
|
+
kind: 'keyword';
|
|
7
|
+
name: TsKeywordName;
|
|
8
|
+
source?: TypeNode;
|
|
9
|
+
}
|
|
10
|
+
export interface TsLiteral {
|
|
11
|
+
kind: 'literal';
|
|
12
|
+
value: EnumValue;
|
|
13
|
+
}
|
|
14
|
+
export interface TsNamed {
|
|
15
|
+
kind: 'named';
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TsRef {
|
|
19
|
+
kind: 'ref';
|
|
20
|
+
id: ModelId;
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TsArray {
|
|
24
|
+
kind: 'array';
|
|
25
|
+
items: TsType;
|
|
26
|
+
generic: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface TsRecord {
|
|
29
|
+
kind: 'record';
|
|
30
|
+
values: TsType;
|
|
31
|
+
}
|
|
32
|
+
export interface TsObject {
|
|
33
|
+
kind: 'object';
|
|
34
|
+
properties: TsProperty[];
|
|
35
|
+
}
|
|
36
|
+
export interface TsProperty {
|
|
37
|
+
name: string;
|
|
38
|
+
optional: boolean;
|
|
39
|
+
type: TsType;
|
|
40
|
+
}
|
|
41
|
+
export interface TsUnion {
|
|
42
|
+
kind: 'union';
|
|
43
|
+
members: TsType[];
|
|
44
|
+
}
|
|
45
|
+
export interface TsIntersection {
|
|
46
|
+
kind: 'intersection';
|
|
47
|
+
members: TsType[];
|
|
48
|
+
}
|
|
49
|
+
export interface TsWidened {
|
|
50
|
+
kind: 'widened';
|
|
51
|
+
as: TsType;
|
|
52
|
+
values: EnumValue[];
|
|
53
|
+
}
|
|
54
|
+
export interface TsConstRef {
|
|
55
|
+
kind: 'const';
|
|
56
|
+
name: string;
|
|
57
|
+
members: ConstMember[];
|
|
58
|
+
}
|
|
59
|
+
export interface TsEnumRef {
|
|
60
|
+
kind: 'enum';
|
|
61
|
+
id: ModelId;
|
|
62
|
+
name: string;
|
|
63
|
+
members: ConstMember[];
|
|
64
|
+
}
|
|
65
|
+
export declare const keyword: (name: TsKeywordName, source?: TypeNode) => TsKeyword;
|
|
66
|
+
export declare const literalType: (value: EnumValue) => TsLiteral;
|
|
67
|
+
export declare const record: (values: TsType) => TsRecord;
|
|
68
|
+
export declare function union(members: TsType[]): TsType;
|
|
69
|
+
export declare function intersection(members: TsType[]): TsType;
|
|
70
|
+
export declare function printTsType(type: TsType): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.record = exports.literalType = exports.keyword = void 0;
|
|
4
|
+
exports.union = union;
|
|
5
|
+
exports.intersection = intersection;
|
|
6
|
+
exports.printTsType = printTsType;
|
|
7
|
+
const naming_1 = require("./naming");
|
|
8
|
+
const keyword = (name, source) => (source ? { kind: 'keyword', name, source } : { kind: 'keyword', name });
|
|
9
|
+
exports.keyword = keyword;
|
|
10
|
+
const literalType = (value) => ({ kind: 'literal', value });
|
|
11
|
+
exports.literalType = literalType;
|
|
12
|
+
const record = (values) => ({ kind: 'record', values });
|
|
13
|
+
exports.record = record;
|
|
14
|
+
function union(members) {
|
|
15
|
+
return members.length === 1 ? members[0] : { kind: 'union', members };
|
|
16
|
+
}
|
|
17
|
+
function intersection(members) {
|
|
18
|
+
return members.length === 1 ? members[0] : { kind: 'intersection', members };
|
|
19
|
+
}
|
|
20
|
+
const atom = (text) => ({ text, prec: 2 });
|
|
21
|
+
function printTsType(type) {
|
|
22
|
+
return render(type).text;
|
|
23
|
+
}
|
|
24
|
+
function render(type) {
|
|
25
|
+
switch (type.kind) {
|
|
26
|
+
case 'keyword':
|
|
27
|
+
return atom(type.name);
|
|
28
|
+
case 'literal':
|
|
29
|
+
return atom((0, naming_1.literal)(type.value));
|
|
30
|
+
case 'named':
|
|
31
|
+
case 'ref':
|
|
32
|
+
case 'enum':
|
|
33
|
+
return atom(type.name);
|
|
34
|
+
case 'array': {
|
|
35
|
+
const element = render(type.items);
|
|
36
|
+
if (type.generic || element.prec === 0)
|
|
37
|
+
return atom(`Array<${element.text}>`);
|
|
38
|
+
return atom(`${paren(element, 2)}[]`);
|
|
39
|
+
}
|
|
40
|
+
case 'record':
|
|
41
|
+
return atom(`Record<string, ${render(type.values).text}>`);
|
|
42
|
+
case 'object': {
|
|
43
|
+
const members = type.properties.map((p) => `${(0, naming_1.propertyKey)(p.name)}${p.optional ? '?' : ''}: ${render(p.type).text};`);
|
|
44
|
+
return atom(`{ ${members.join(' ')} }`);
|
|
45
|
+
}
|
|
46
|
+
case 'union':
|
|
47
|
+
if (type.members.length === 1)
|
|
48
|
+
return render(type.members[0]);
|
|
49
|
+
return { text: type.members.map((m) => render(m).text).join(' | '), prec: 0 };
|
|
50
|
+
case 'intersection':
|
|
51
|
+
if (type.members.length === 1)
|
|
52
|
+
return render(type.members[0]);
|
|
53
|
+
return { text: type.members.map((m) => paren(render(m), 1)).join(' & '), prec: 1 };
|
|
54
|
+
case 'widened':
|
|
55
|
+
return render(type.as);
|
|
56
|
+
case 'const':
|
|
57
|
+
return atom(`(typeof ${type.name})[keyof typeof ${type.name}]`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function paren(printed, min) {
|
|
61
|
+
return printed.prec < min ? `(${printed.text})` : printed.text;
|
|
62
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ModelId, TypeNode } from '../../ir/types';
|
|
2
|
+
import type { ImportCollector } from './imports';
|
|
3
|
+
import { type TsType } from './ts-type';
|
|
4
|
+
export interface PrintOptions {
|
|
5
|
+
arrayStyle: 'brackets' | 'generic';
|
|
6
|
+
untyped: 'unknown' | 'any' | 'object';
|
|
7
|
+
nestedArrays: 'preserve' | 'any';
|
|
8
|
+
nullable: 'ignore' | 'union' | 'property';
|
|
9
|
+
enums: 'union' | 'base';
|
|
10
|
+
objects: 'literal' | 'object';
|
|
11
|
+
typeImports: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PrintContext {
|
|
14
|
+
imports: ImportCollector;
|
|
15
|
+
options: PrintOptions;
|
|
16
|
+
selfId?: ModelId;
|
|
17
|
+
}
|
|
18
|
+
export type TypePosition = 'top' | 'nested';
|
|
19
|
+
export declare function printType(node: TypeNode, ctx: PrintContext): string;
|
|
20
|
+
export declare function resolveType(node: TypeNode, ctx: PrintContext, position?: TypePosition): TsType;
|
|
21
|
+
export declare function propertyType(node: TypeNode, type: TsType, options: PrintOptions): TsType;
|