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,447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_POSITIONS = void 0;
|
|
4
|
+
exports.createEnv = createEnv;
|
|
5
|
+
exports.createScope = createScope;
|
|
6
|
+
exports.kindOf = kindOf;
|
|
7
|
+
exports.groupResources = groupResources;
|
|
8
|
+
exports.inScope = inScope;
|
|
9
|
+
exports.buildModelView = buildModelView;
|
|
10
|
+
exports.resourceNames = resourceNames;
|
|
11
|
+
exports.buildResourceView = buildResourceView;
|
|
12
|
+
exports.applyComputed = applyComputed;
|
|
13
|
+
exports.dependenciesOf = dependenciesOf;
|
|
14
|
+
const graph_1 = require("../../ir/graph");
|
|
15
|
+
const grouping_1 = require("../../ir/operations/grouping");
|
|
16
|
+
const naming_1 = require("../../ir/operations/naming");
|
|
17
|
+
const naming_2 = require("./naming");
|
|
18
|
+
const types_1 = require("./types");
|
|
19
|
+
exports.DEFAULT_POSITIONS = {
|
|
20
|
+
property: { spells: ['property', 'alias'] },
|
|
21
|
+
param: { spells: ['param', 'body'] },
|
|
22
|
+
return: { spells: ['response'] },
|
|
23
|
+
};
|
|
24
|
+
const PRIMARY = { property: 'property', alias: 'property', param: 'param', body: 'param', response: 'return' };
|
|
25
|
+
function resolvePositions(config) {
|
|
26
|
+
var _a;
|
|
27
|
+
const positions = Object.assign({}, exports.DEFAULT_POSITIONS);
|
|
28
|
+
for (const [name, spec] of Object.entries((_a = config.positions) !== null && _a !== void 0 ? _a : {}))
|
|
29
|
+
positions[name] = Object.assign(Object.assign({}, positions[name]), spec);
|
|
30
|
+
const chains = new Map();
|
|
31
|
+
for (const name of Object.keys(positions)) {
|
|
32
|
+
const chain = [name];
|
|
33
|
+
for (let next = positions[name].inherits; next !== undefined; next = positions[next].inherits) {
|
|
34
|
+
if (!positions[next])
|
|
35
|
+
throw new Error(`positions.${chain[chain.length - 1]}.inherits: unknown position "${next}" (have ${Object.keys(positions).join(', ')})`);
|
|
36
|
+
if (chain.includes(next))
|
|
37
|
+
throw new Error(`positions: inherits cycle ${[...chain, next].join(' → ')}`);
|
|
38
|
+
chain.push(next);
|
|
39
|
+
}
|
|
40
|
+
chains.set(name, chain);
|
|
41
|
+
}
|
|
42
|
+
const byElement = new Map();
|
|
43
|
+
for (const element of Object.keys(PRIMARY)) {
|
|
44
|
+
const names = Object.keys(positions).filter((n) => { var _a; return (_a = positions[n].spells) === null || _a === void 0 ? void 0 : _a.includes(element); });
|
|
45
|
+
const primary = PRIMARY[element];
|
|
46
|
+
byElement.set(element, [primary, ...names.filter((n) => n !== primary)]);
|
|
47
|
+
}
|
|
48
|
+
return { chain: (position) => { var _a; return (_a = chains.get(position)) !== null && _a !== void 0 ? _a : [position]; }, byElement };
|
|
49
|
+
}
|
|
50
|
+
function createEnv(api, options, config, extensions, templates, log) {
|
|
51
|
+
var _a;
|
|
52
|
+
var _b;
|
|
53
|
+
const modelsById = new Map(api.models.map((m) => [m.id, m]));
|
|
54
|
+
const graph = new Map();
|
|
55
|
+
for (const model of api.models)
|
|
56
|
+
graph.set(model.id, dependenciesOf(model).filter((id) => modelsById.has(id)));
|
|
57
|
+
let order;
|
|
58
|
+
let sccs;
|
|
59
|
+
let cyclicSet;
|
|
60
|
+
let groups;
|
|
61
|
+
const positions = resolvePositions(config);
|
|
62
|
+
const namespaces = new Map();
|
|
63
|
+
const env = {
|
|
64
|
+
api,
|
|
65
|
+
options,
|
|
66
|
+
config,
|
|
67
|
+
extensions,
|
|
68
|
+
templates,
|
|
69
|
+
log,
|
|
70
|
+
typeNames: new Map(),
|
|
71
|
+
modelsById,
|
|
72
|
+
scope: newScope(),
|
|
73
|
+
namer: undefined,
|
|
74
|
+
speller: undefined,
|
|
75
|
+
dependencyOrder: () => (order !== null && order !== void 0 ? order : (order = dependencyOrder(api.models, graph, modelsById))),
|
|
76
|
+
cycles: () => (sccs !== null && sccs !== void 0 ? sccs : (sccs = stronglyConnected(api.models.map((m) => m.id), graph).filter((c) => c.length > 1 || graph.get(c[0]).includes(c[0])))),
|
|
77
|
+
cyclic: () => (cyclicSet !== null && cyclicSet !== void 0 ? cyclicSet : (cyclicSet = new Set(env.cycles().flat()))),
|
|
78
|
+
resources: () => { var _a, _b, _c; var _d, _e, _f, _g, _h; return (groups !== null && groups !== void 0 ? groups : (groups = groupResources(api.operations, {
|
|
79
|
+
by: (_e = (_d = options.groupBy) !== null && _d !== void 0 ? _d : (_a = config.resources) === null || _a === void 0 ? void 0 : _a.by) !== null && _e !== void 0 ? _e : 'path',
|
|
80
|
+
stripPrefixes: (_g = (_f = options.stripPrefixes) !== null && _f !== void 0 ? _f : (_b = config.resources) === null || _b === void 0 ? void 0 : _b.stripPrefixes) !== null && _g !== void 0 ? _g : [],
|
|
81
|
+
folders: (_h = (_c = config.resources) === null || _c === void 0 ? void 0 : _c.folders) !== null && _h !== void 0 ? _h : false,
|
|
82
|
+
}))); },
|
|
83
|
+
positionsFor: (element) => positions.byElement.get(element),
|
|
84
|
+
namespace(raw) {
|
|
85
|
+
const key = raw.join('\u0000');
|
|
86
|
+
let named = namespaces.get(key);
|
|
87
|
+
if (!named)
|
|
88
|
+
namespaces.set(key, (named = env.namer.namespace(raw)));
|
|
89
|
+
return named;
|
|
90
|
+
},
|
|
91
|
+
context(scope = env.scope) {
|
|
92
|
+
return {
|
|
93
|
+
api,
|
|
94
|
+
options,
|
|
95
|
+
log,
|
|
96
|
+
naming: (kind, raw) => env.namer.name(kind, raw),
|
|
97
|
+
spell: (node, position = 'property') => env.speller.spell(node, position, scope.imports).text,
|
|
98
|
+
imports: { add: (spec) => scope.imports.add(spec) },
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const skip = new Set((_b = (_a = config.imports) === null || _a === void 0 ? void 0 : _a.skip) !== null && _b !== void 0 ? _b : ['declared', 'inlined']);
|
|
103
|
+
function newScope(declared = [], namespace) {
|
|
104
|
+
const scope = Object.assign({ declared: new Set(declared), imports: undefined }, (namespace ? { namespace } : {}));
|
|
105
|
+
scope.imports = new types_1.ImportSet((id, set, info) => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
var _c;
|
|
108
|
+
const spec = (_a = config.imports) === null || _a === void 0 ? void 0 : _a.ref;
|
|
109
|
+
const veto = (_b = extensions.imports) === null || _b === void 0 ? void 0 : _b.ref;
|
|
110
|
+
if (!spec && !veto)
|
|
111
|
+
return;
|
|
112
|
+
const model = modelsById.get(id);
|
|
113
|
+
const facts = {
|
|
114
|
+
declared: scope.declared.has(id),
|
|
115
|
+
inlined: Boolean(info.inlined),
|
|
116
|
+
sameNamespace: scope.namespace !== undefined && scope.namespace.join('.') === model.namespace.join('.'),
|
|
117
|
+
};
|
|
118
|
+
const data = Object.assign(Object.assign({ name: env.typeNames.get(id), wireName: model.name, namespace: env.namespace(model.namespace), wireNamespace: model.namespace, id, kind: kindOf(model) }, facts), { options });
|
|
119
|
+
const skipped = Object.keys(facts).some((k) => facts[k] && skip.has(k));
|
|
120
|
+
let line = null;
|
|
121
|
+
if (spec && !skipped) {
|
|
122
|
+
line = typeof spec === 'string' ? templates.render(spec, data) : Object.assign({ module: templates.render(spec.module, data) }, (spec.name ? { name: templates.render(spec.name, data) } : {}));
|
|
123
|
+
}
|
|
124
|
+
if (veto)
|
|
125
|
+
line = (_c = veto(data, env.context(scope), line)) !== null && _c !== void 0 ? _c : null;
|
|
126
|
+
if (line)
|
|
127
|
+
set.add(line);
|
|
128
|
+
});
|
|
129
|
+
return scope;
|
|
130
|
+
}
|
|
131
|
+
scopeFactory.set(env, newScope);
|
|
132
|
+
env.namer = (0, naming_2.createNamingEngine)({
|
|
133
|
+
naming: config.naming,
|
|
134
|
+
templates,
|
|
135
|
+
options,
|
|
136
|
+
extensions: extensions.naming,
|
|
137
|
+
context: () => env.context(),
|
|
138
|
+
avoidSets: { '@models': () => new Set(env.typeNames.values()) },
|
|
139
|
+
});
|
|
140
|
+
env.speller = (0, types_1.createSpeller)({
|
|
141
|
+
types: config.types,
|
|
142
|
+
literals: config.literals,
|
|
143
|
+
aliases: config.aliases,
|
|
144
|
+
positionChain: positions.chain,
|
|
145
|
+
templates,
|
|
146
|
+
options,
|
|
147
|
+
extensions: extensions.types,
|
|
148
|
+
context: (sink) => (Object.assign(Object.assign({}, env.context()), { imports: { add: (spec) => sink.add(spec) } })),
|
|
149
|
+
refModel: (id) => {
|
|
150
|
+
const model = modelsById.get(id);
|
|
151
|
+
return model ? { name: env.typeNames.get(id), namespace: env.namespace(model.namespace), id, kind: kindOf(model), type: model.type } : undefined;
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
env.typeNames = env.namer.typeNames(api.models);
|
|
155
|
+
return env;
|
|
156
|
+
}
|
|
157
|
+
const scopeFactory = new WeakMap();
|
|
158
|
+
function createScope(env, declared = [], namespace) {
|
|
159
|
+
return scopeFactory.get(env)(declared, namespace);
|
|
160
|
+
}
|
|
161
|
+
function kindOf(model) {
|
|
162
|
+
return model.type.kind === 'object' ? 'object' : model.type.kind === 'enum' ? 'enum' : 'alias';
|
|
163
|
+
}
|
|
164
|
+
function groupResources(operations, options) {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
if (options.by === 'path')
|
|
167
|
+
return (0, grouping_1.groupOperations)(operations, options);
|
|
168
|
+
const groups = new Map();
|
|
169
|
+
for (const op of operations) {
|
|
170
|
+
let resource;
|
|
171
|
+
if (options.by === 'tag')
|
|
172
|
+
resource = op.tags[0] || 'default';
|
|
173
|
+
else {
|
|
174
|
+
const m = /^([^_./:]+)[_./:]/.exec((_a = op.operationId) !== null && _a !== void 0 ? _a : '');
|
|
175
|
+
resource = (_b = m === null || m === void 0 ? void 0 : m[1]) !== null && _b !== void 0 ? _b : (0, grouping_1.groupOperations)([op], options)[0].resource;
|
|
176
|
+
}
|
|
177
|
+
const key = resource.toLowerCase();
|
|
178
|
+
let group = groups.get(key);
|
|
179
|
+
if (!group)
|
|
180
|
+
groups.set(key, (group = { key: resource, folder: '', resource, operations: [] }));
|
|
181
|
+
group.operations.push(op);
|
|
182
|
+
}
|
|
183
|
+
return [...groups.values()];
|
|
184
|
+
}
|
|
185
|
+
function inScope(env, scope, fn) {
|
|
186
|
+
const previous = env.scope;
|
|
187
|
+
env.scope = scope;
|
|
188
|
+
try {
|
|
189
|
+
return fn();
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
env.scope = previous;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function buildModelView(env, model) {
|
|
196
|
+
var _a;
|
|
197
|
+
const type = model.type;
|
|
198
|
+
const kind = kindOf(model);
|
|
199
|
+
const refIds = dependenciesOf(model).filter((id) => env.modelsById.has(id));
|
|
200
|
+
const view = {
|
|
201
|
+
name: env.typeNames.get(model.id),
|
|
202
|
+
wireName: model.name,
|
|
203
|
+
id: model.id,
|
|
204
|
+
namespace: env.namespace(model.namespace),
|
|
205
|
+
wireNamespace: model.namespace,
|
|
206
|
+
kind,
|
|
207
|
+
valueType: type.kind === 'enum' ? (0, types_1.valueTypeOf)(type.values) : null,
|
|
208
|
+
doc: model.description || null,
|
|
209
|
+
deprecated: Boolean(model.deprecated),
|
|
210
|
+
properties: [],
|
|
211
|
+
members: [],
|
|
212
|
+
type: null,
|
|
213
|
+
types: {},
|
|
214
|
+
typeComment: null,
|
|
215
|
+
typeNode: type,
|
|
216
|
+
additionalProperties: type.kind === 'object' && Boolean(type.additionalProperties),
|
|
217
|
+
refs: refIds.map((id) => env.typeNames.get(id)),
|
|
218
|
+
refIds,
|
|
219
|
+
cyclic: env.cyclic().has(model.id),
|
|
220
|
+
raw: model.raw,
|
|
221
|
+
computed: {},
|
|
222
|
+
};
|
|
223
|
+
const sink = env.scope.imports;
|
|
224
|
+
if (type.kind === 'object') {
|
|
225
|
+
const used = new Set();
|
|
226
|
+
view.properties = type.properties.map((p) => buildPropertyView(env, p, used, sink));
|
|
227
|
+
}
|
|
228
|
+
else if (type.kind === 'enum') {
|
|
229
|
+
const used = new Set();
|
|
230
|
+
view.members = type.values.map((value) => ({
|
|
231
|
+
key: env.namer.unique('enumKey', env.namer.enumKey(value), used),
|
|
232
|
+
value,
|
|
233
|
+
literal: env.speller.literal(value),
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
for (const position of env.positionsFor('alias')) {
|
|
238
|
+
const spelled = env.speller.spell(type, position, sink);
|
|
239
|
+
view.types[position] = spelled.text;
|
|
240
|
+
if (view.type === null) {
|
|
241
|
+
view.type = spelled.text;
|
|
242
|
+
view.typeComment = (_a = spelled.comment) !== null && _a !== void 0 ? _a : null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
applyComputed(env, 'model', view);
|
|
247
|
+
return view;
|
|
248
|
+
}
|
|
249
|
+
function spellAll(env, element, node, required, sink) {
|
|
250
|
+
const types = {};
|
|
251
|
+
let primary;
|
|
252
|
+
for (const position of env.positionsFor(element)) {
|
|
253
|
+
const spelled = env.speller.spell(node, position, sink);
|
|
254
|
+
const typed = required ? spelled : env.speller.optional(node, spelled, position, sink);
|
|
255
|
+
types[position] = typed.text;
|
|
256
|
+
primary !== null && primary !== void 0 ? primary : (primary = { spelled, typed });
|
|
257
|
+
}
|
|
258
|
+
return Object.assign({ types }, primary);
|
|
259
|
+
}
|
|
260
|
+
function buildPropertyView(env, p, used, sink) {
|
|
261
|
+
var _a, _b, _c, _d;
|
|
262
|
+
const { spelled, typed, types } = spellAll(env, 'property', p.type, p.required, sink);
|
|
263
|
+
const view = {
|
|
264
|
+
name: env.namer.unique('property', env.namer.name('property', p.name), used),
|
|
265
|
+
wireName: p.name,
|
|
266
|
+
type: typed.text,
|
|
267
|
+
baseType: spelled.text,
|
|
268
|
+
types,
|
|
269
|
+
typeComment: (_a = typed.comment) !== null && _a !== void 0 ? _a : null,
|
|
270
|
+
typeNode: p.type,
|
|
271
|
+
required: p.required,
|
|
272
|
+
nullable: Boolean(p.type.nullable),
|
|
273
|
+
optional: !p.required,
|
|
274
|
+
default: (_b = p.type.default) !== null && _b !== void 0 ? _b : null,
|
|
275
|
+
doc: p.description || null,
|
|
276
|
+
readOnly: Boolean(p.type.readOnly),
|
|
277
|
+
writeOnly: Boolean(p.type.writeOnly),
|
|
278
|
+
deprecated: Boolean(p.type.deprecated),
|
|
279
|
+
format: p.type.kind === 'primitive' ? (_c = p.type.format) !== null && _c !== void 0 ? _c : null : null,
|
|
280
|
+
raw: (_d = p.type.raw) !== null && _d !== void 0 ? _d : null,
|
|
281
|
+
computed: {},
|
|
282
|
+
};
|
|
283
|
+
applyComputed(env, 'property', view);
|
|
284
|
+
return view;
|
|
285
|
+
}
|
|
286
|
+
function resourceNames(env) {
|
|
287
|
+
const used = new Set();
|
|
288
|
+
return new Map(env.resources().map((g) => [g, env.namer.unique('resource', env.namer.name('resource', g.resource), used)]));
|
|
289
|
+
}
|
|
290
|
+
function buildResourceView(env, group, name) {
|
|
291
|
+
var _a;
|
|
292
|
+
var _b;
|
|
293
|
+
const strategy = (_b = (_a = env.config.resources) === null || _a === void 0 ? void 0 : _a.naming) !== null && _b !== void 0 ? _b : 'operation-id';
|
|
294
|
+
const used = new Set();
|
|
295
|
+
const view = {
|
|
296
|
+
name,
|
|
297
|
+
wireName: group.resource,
|
|
298
|
+
folder: group.folder,
|
|
299
|
+
key: group.key,
|
|
300
|
+
operations: group.operations.map((op) => buildOperationView(env, op, env.namer.unique('operation', env.namer.name('operation', (0, naming_1.operationName)(op, strategy)), used))),
|
|
301
|
+
computed: {},
|
|
302
|
+
};
|
|
303
|
+
applyComputed(env, 'resource', view);
|
|
304
|
+
return view;
|
|
305
|
+
}
|
|
306
|
+
function buildOperationView(env, op, name) {
|
|
307
|
+
var _a;
|
|
308
|
+
var _b, _c, _d;
|
|
309
|
+
const sink = env.scope.imports;
|
|
310
|
+
const usedParams = new Set();
|
|
311
|
+
const params = op.parameters.map((p) => buildParamView(env, p, usedParams, sink));
|
|
312
|
+
const content = (_a = op.requestBody) === null || _a === void 0 ? void 0 : _a.contents[0];
|
|
313
|
+
const responses = op.responses.map((r) => {
|
|
314
|
+
var _a, _b;
|
|
315
|
+
const first = r.contents[0];
|
|
316
|
+
const types = first ? spellAll(env, 'response', first.type, true, sink).types : {};
|
|
317
|
+
return {
|
|
318
|
+
status: r.status,
|
|
319
|
+
type: first ? types[env.positionsFor('response')[0]] : null,
|
|
320
|
+
types,
|
|
321
|
+
typeNode: (_a = first === null || first === void 0 ? void 0 : first.type) !== null && _a !== void 0 ? _a : null,
|
|
322
|
+
contentType: (_b = first === null || first === void 0 ? void 0 : first.mediaType) !== null && _b !== void 0 ? _b : null,
|
|
323
|
+
doc: r.description || null,
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
const view = {
|
|
327
|
+
id: op.id,
|
|
328
|
+
operationId: (_b = op.operationId) !== null && _b !== void 0 ? _b : null,
|
|
329
|
+
name,
|
|
330
|
+
method: op.method,
|
|
331
|
+
path: op.path,
|
|
332
|
+
summary: op.summary || null,
|
|
333
|
+
doc: op.description || op.summary || null,
|
|
334
|
+
deprecated: Boolean(op.deprecated),
|
|
335
|
+
tags: op.tags,
|
|
336
|
+
params,
|
|
337
|
+
pathParams: params.filter((p) => p.in === 'path'),
|
|
338
|
+
queryParams: params.filter((p) => p.in === 'query'),
|
|
339
|
+
headerParams: params.filter((p) => p.in === 'header'),
|
|
340
|
+
cookieParams: params.filter((p) => p.in === 'cookie'),
|
|
341
|
+
body: op.requestBody && content
|
|
342
|
+
? Object.assign(Object.assign({}, bodyTypes(env, content.type, sink)), { typeNode: content.type, contentType: content.mediaType, required: op.requestBody.required, contentTypes: op.requestBody.contents.map((c) => c.mediaType) }) : null,
|
|
343
|
+
responses,
|
|
344
|
+
success: (_d = (_c = responses.find((r) => /^2/.test(r.status))) !== null && _c !== void 0 ? _c : responses.find((r) => r.status === 'default')) !== null && _d !== void 0 ? _d : null,
|
|
345
|
+
raw: op.raw,
|
|
346
|
+
computed: {},
|
|
347
|
+
};
|
|
348
|
+
applyComputed(env, 'operation', view);
|
|
349
|
+
return view;
|
|
350
|
+
}
|
|
351
|
+
function bodyTypes(env, node, sink) {
|
|
352
|
+
const { types, spelled } = spellAll(env, 'body', node, true, sink);
|
|
353
|
+
return { type: spelled.text, types };
|
|
354
|
+
}
|
|
355
|
+
function buildParamView(env, p, used, sink) {
|
|
356
|
+
const { spelled, typed, types } = spellAll(env, 'param', p.type, p.required, sink);
|
|
357
|
+
return {
|
|
358
|
+
name: env.namer.unique('param', env.namer.name('param', p.name), used),
|
|
359
|
+
wireName: p.name,
|
|
360
|
+
in: p.in,
|
|
361
|
+
type: typed.text,
|
|
362
|
+
baseType: spelled.text,
|
|
363
|
+
types,
|
|
364
|
+
typeNode: p.type,
|
|
365
|
+
required: p.required,
|
|
366
|
+
doc: p.description || null,
|
|
367
|
+
deprecated: Boolean(p.deprecated),
|
|
368
|
+
raw: p.raw,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
function applyComputed(env, kind, view) {
|
|
372
|
+
var _a;
|
|
373
|
+
const fns = (_a = env.extensions.computed) === null || _a === void 0 ? void 0 : _a[kind];
|
|
374
|
+
if (!fns)
|
|
375
|
+
return;
|
|
376
|
+
const ctx = env.context();
|
|
377
|
+
for (const [name, fn] of Object.entries(fns)) {
|
|
378
|
+
const value = fn(view, ctx);
|
|
379
|
+
view.computed[name] = value === undefined ? null : value;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function dependenciesOf(model) {
|
|
383
|
+
const type = model.type;
|
|
384
|
+
if (type.kind !== 'object')
|
|
385
|
+
return (0, graph_1.referencedIds)(type);
|
|
386
|
+
const out = [];
|
|
387
|
+
for (const p of type.properties)
|
|
388
|
+
for (const id of (0, graph_1.referencedIds)(p.type))
|
|
389
|
+
if (!out.includes(id))
|
|
390
|
+
out.push(id);
|
|
391
|
+
return out;
|
|
392
|
+
}
|
|
393
|
+
function dependencyOrder(models, graph, byId) {
|
|
394
|
+
const state = new Map();
|
|
395
|
+
const out = [];
|
|
396
|
+
const visit = (id) => {
|
|
397
|
+
var _a;
|
|
398
|
+
if (state.has(id))
|
|
399
|
+
return;
|
|
400
|
+
state.set(id, 'visiting');
|
|
401
|
+
for (const dep of (_a = graph.get(id)) !== null && _a !== void 0 ? _a : [])
|
|
402
|
+
visit(dep);
|
|
403
|
+
state.set(id, 'done');
|
|
404
|
+
out.push(byId.get(id));
|
|
405
|
+
};
|
|
406
|
+
for (const m of models)
|
|
407
|
+
visit(m.id);
|
|
408
|
+
return out;
|
|
409
|
+
}
|
|
410
|
+
function stronglyConnected(ids, graph) {
|
|
411
|
+
let index = 0;
|
|
412
|
+
const idx = new Map();
|
|
413
|
+
const low = new Map();
|
|
414
|
+
const stack = [];
|
|
415
|
+
const onStack = new Set();
|
|
416
|
+
const out = [];
|
|
417
|
+
const position = new Map(ids.map((id, i) => [id, i]));
|
|
418
|
+
const strong = (v) => {
|
|
419
|
+
var _a;
|
|
420
|
+
idx.set(v, index);
|
|
421
|
+
low.set(v, index++);
|
|
422
|
+
stack.push(v);
|
|
423
|
+
onStack.add(v);
|
|
424
|
+
for (const w of (_a = graph.get(v)) !== null && _a !== void 0 ? _a : []) {
|
|
425
|
+
if (!idx.has(w)) {
|
|
426
|
+
strong(w);
|
|
427
|
+
low.set(v, Math.min(low.get(v), low.get(w)));
|
|
428
|
+
}
|
|
429
|
+
else if (onStack.has(w))
|
|
430
|
+
low.set(v, Math.min(low.get(v), idx.get(w)));
|
|
431
|
+
}
|
|
432
|
+
if (low.get(v) === idx.get(v)) {
|
|
433
|
+
const scc = [];
|
|
434
|
+
let w;
|
|
435
|
+
do {
|
|
436
|
+
w = stack.pop();
|
|
437
|
+
onStack.delete(w);
|
|
438
|
+
scc.push(w);
|
|
439
|
+
} while (w !== v);
|
|
440
|
+
out.push(scc.sort((a, b) => position.get(a) - position.get(b)));
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
for (const id of ids)
|
|
444
|
+
if (!idx.has(id))
|
|
445
|
+
strong(id);
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Python (pydantic v2) — only what target.json can't say. Everything here is
|
|
5
|
+
* Python- or pydantic-specific; the engine does naming, spelling, imports and
|
|
6
|
+
* dependency order.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const pydantic = (name) => ({ module: 'pydantic', name });
|
|
10
|
+
|
|
11
|
+
/** Field names must not shadow a name the module's annotations use (pydantic resolves annotations in the class body). */
|
|
12
|
+
const symbolsByApi = new WeakMap();
|
|
13
|
+
function annotationSymbols(api) {
|
|
14
|
+
let symbols = symbolsByApi.get(api);
|
|
15
|
+
if (symbols) return symbols;
|
|
16
|
+
symbols = new Set();
|
|
17
|
+
if (api.models.some((m) => m.type.kind === 'object')) ['BaseModel', 'ConfigDict', 'Field'].forEach((n) => symbols.add(n));
|
|
18
|
+
if (api.models.some((m) => m.type.kind === 'enum')) symbols.add('Enum');
|
|
19
|
+
for (const m of api.models) collect(m.type, symbols);
|
|
20
|
+
symbolsByApi.set(api, symbols);
|
|
21
|
+
return symbols;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const PRIMITIVE = { 'date-time': 'datetime', date: 'date', uuid: 'UUID', binary: 'bytes' };
|
|
25
|
+
const SCALAR = { integer: 'int', number: 'float', boolean: 'bool', null: 'None' };
|
|
26
|
+
const literalSymbol = (v) =>
|
|
27
|
+
typeof v === 'string' ? 'str' : typeof v === 'number' ? (Number.isInteger(v) ? 'int' : 'float') : typeof v === 'boolean' ? 'bool' : v === null ? 'None' : undefined;
|
|
28
|
+
|
|
29
|
+
function collect(node, out) {
|
|
30
|
+
const add = (...names) => names.forEach((n) => n && out.add(n));
|
|
31
|
+
if (node.nullable) add('None');
|
|
32
|
+
switch (node.kind) {
|
|
33
|
+
case 'primitive':
|
|
34
|
+
return add(node.type === 'string' ? PRIMITIVE[node.format] || 'str' : SCALAR[node.type]);
|
|
35
|
+
case 'any':
|
|
36
|
+
return add('Any');
|
|
37
|
+
case 'array':
|
|
38
|
+
add('list');
|
|
39
|
+
return collect(node.items, out);
|
|
40
|
+
case 'map':
|
|
41
|
+
add('dict', 'str');
|
|
42
|
+
return collect(node.values, out);
|
|
43
|
+
case 'object':
|
|
44
|
+
if (!node.properties.length) add('dict', 'str', 'Any');
|
|
45
|
+
node.properties.forEach((p) => collect(p.type, out));
|
|
46
|
+
return node.additionalProperties && collect(node.additionalProperties, out);
|
|
47
|
+
case 'enum':
|
|
48
|
+
return add('Literal', node.base === 'integer' ? 'int' : 'str');
|
|
49
|
+
case 'union':
|
|
50
|
+
return node.variants.forEach((v) => collect(v, out));
|
|
51
|
+
case 'intersection':
|
|
52
|
+
add('Any');
|
|
53
|
+
return node.members.forEach((m) => collect(m, out));
|
|
54
|
+
case 'literal':
|
|
55
|
+
return add('Literal', literalSymbol(node.value));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const aliased = (p, ctx) => p.name !== p.wireName || ctx.options.fieldNames === 'snake';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* How the transport reads the success response (`HttpRequest.response_type`). ENGINE GAP: language-neutral,
|
|
63
|
+
* belongs on the operation view (e.g. `success.kind`).
|
|
64
|
+
*/
|
|
65
|
+
function responseType(success) {
|
|
66
|
+
if (!success || !success.contentType || !success.typeNode) return 'json';
|
|
67
|
+
const lower = success.contentType.toLowerCase();
|
|
68
|
+
if (lower.includes('json')) return 'json';
|
|
69
|
+
if (lower.startsWith('text/') || lower.includes('xml')) return 'text';
|
|
70
|
+
const node = success.typeNode;
|
|
71
|
+
const binary = node.kind === 'primitive' && node.type === 'string' && node.format === 'binary';
|
|
72
|
+
if (lower === '*/*' || lower === 'application/*') return binary ? 'bytes' : 'json';
|
|
73
|
+
return 'bytes';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Non-nullable `$ref` to an object model (a pydantic `BaseModel` subclass). */
|
|
77
|
+
function isModelRef(node, ctx) {
|
|
78
|
+
if (!node || node.kind !== 'ref' || node.nullable || node.unresolved) return false;
|
|
79
|
+
const model = ctx.api.models.find((m) => m.id === node.id);
|
|
80
|
+
return Boolean(model && model.type.kind === 'object');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** pydantic validation of `response.data`, decided from the type node (the spelled type is only pasted in). */
|
|
84
|
+
function returnExpression(op, ctx) {
|
|
85
|
+
const success = op.success;
|
|
86
|
+
if (!success || !success.typeNode) return 'None';
|
|
87
|
+
const kind = responseType(success);
|
|
88
|
+
const node = success.typeNode;
|
|
89
|
+
if (kind === 'bytes' || (node.kind === 'any' && !node.nullable)) return 'response.data';
|
|
90
|
+
if (kind === 'text' && success.type === 'str') return 'response.data';
|
|
91
|
+
if (isModelRef(node, ctx)) return `${success.type}.model_validate(response.data)`;
|
|
92
|
+
return `_runtime.validate(${success.type}, response.data)`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
/** Option `transport: "none"` drops the default httpx adapter. ENGINE GAP: file rules can't be conditional on an option. */
|
|
97
|
+
files(plan, ctx) {
|
|
98
|
+
return ctx.options.transport === 'none' ? plan.filter((entry) => entry.path !== 'httpx_transport.py') : plan;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
naming: {
|
|
102
|
+
property(raw, fallback, ctx) {
|
|
103
|
+
const taken = annotationSymbols(ctx.api);
|
|
104
|
+
let name = fallback;
|
|
105
|
+
while (taken.has(name)) name = `${name}_`;
|
|
106
|
+
return name;
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
computed: {
|
|
111
|
+
operation: {
|
|
112
|
+
responseType: (op) => responseType(op.success),
|
|
113
|
+
returnType(op) {
|
|
114
|
+
if (!op.success || !op.success.typeNode) return 'None';
|
|
115
|
+
return responseType(op.success) === 'bytes' ? 'bytes' : op.success.type;
|
|
116
|
+
},
|
|
117
|
+
returnExpression,
|
|
118
|
+
},
|
|
119
|
+
property: {
|
|
120
|
+
/** `= None`, `= Field(..., alias=…, description=…)` or nothing. */
|
|
121
|
+
default(p, ctx) {
|
|
122
|
+
const args = [];
|
|
123
|
+
if (aliased(p, ctx)) args.push(`alias=${JSON.stringify(p.wireName)}`);
|
|
124
|
+
if (p.doc) args.push(`description=${JSON.stringify(p.doc)}`);
|
|
125
|
+
if (!args.length) return p.required ? null : 'None';
|
|
126
|
+
ctx.imports.add(pydantic('Field'));
|
|
127
|
+
return `Field(${[p.required ? '...' : 'None', ...args].join(', ')})`;
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
model: {
|
|
131
|
+
/** Enum class bases: `str, Enum` / `int, Enum` / `Enum`. */
|
|
132
|
+
bases(m, ctx) {
|
|
133
|
+
if (m.kind !== 'enum') return null;
|
|
134
|
+
ctx.imports.add({ module: 'enum', name: 'Enum' });
|
|
135
|
+
const node = m.typeNode;
|
|
136
|
+
const base = node.base === 'integer' ? 'int' : node.base === 'string' || node.values.every((v) => typeof v === 'string') ? 'str' : null;
|
|
137
|
+
return base ? `${base}, Enum` : 'Enum';
|
|
138
|
+
},
|
|
139
|
+
/** `ConfigDict(…)` for aliased fields / additionalProperties. */
|
|
140
|
+
config(m, ctx) {
|
|
141
|
+
if (m.kind !== 'object') return null;
|
|
142
|
+
ctx.imports.add(pydantic('BaseModel'));
|
|
143
|
+
const args = [];
|
|
144
|
+
if (m.properties.some((p) => p.name !== p.wireName || (p.computed.default || '').includes('alias='))) args.push('populate_by_name=True');
|
|
145
|
+
if (m.additionalProperties) args.push("extra='allow'");
|
|
146
|
+
if (!args.length) return null;
|
|
147
|
+
ctx.imports.add(pydantic('ConfigDict'));
|
|
148
|
+
return `ConfigDict(${args.join(', ')})`;
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
};
|