Skip to content

Commit 5bda581

Browse files
authored
feat: update transformer
feat: update transformer
2 parents 4601396 + d7ef06b commit 5bda581

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

packages/generators-v2/src/transformer.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,30 @@ export function transformSchema(schema, options) {
3535
codeSample = codeSamples.customSample(options);
3636
}
3737

38-
if (codeSample) {
39-
Object.entries(updatedSchema.paths).map(([path, operation]) => {
40-
if (operation.post) {
38+
Object.entries(updatedSchema.paths).map(([path, operation]) => {
39+
if (operation.post) {
40+
if (codeSample) {
4141
updatedSchema.paths[path].post['x-codeSamples'] = codeSample;
4242
}
43-
});
44-
}
43+
if (options.models?.length) {
44+
const newModels = [
45+
...new Set([
46+
...(updatedSchema.paths[path]?.post?.requestBody?.content[
47+
'application/json'
48+
]?.schema?.properties?.model?.enum || []),
49+
...options.models,
50+
]),
51+
];
52+
try {
53+
updatedSchema.paths[path].post.requestBody.content[
54+
'application/json'
55+
].schema.properties.model.enum = newModels;
56+
} catch (e) {
57+
console.error(e);
58+
}
59+
}
60+
}
61+
});
4562

4663
return updatedSchema;
4764
}

0 commit comments

Comments
 (0)