Skip to content

Commit 1147af7

Browse files
authored
feat: update transformer
feat: update transformer
2 parents 88dd2c1 + 84039f1 commit 1147af7

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

packages/generators-v2/src/transformer.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as codeSamples from './code-samples/index.js';
22

33
export function transformSchema(schema, options) {
4+
options.name = options.models?.[0] || options.name;
45
const updatedSchema = { ...schema };
56
if (!updatedSchema.components) {
67
updatedSchema.components = {};
@@ -54,21 +55,24 @@ export function transformSchema(schema, options) {
5455
if (updatedSchema.paths?.['/responses']) {
5556
delete updatedSchema.paths['/responses'];
5657
}
58+
if (updatedSchema.paths?.['/images/generations']) {
59+
delete updatedSchema.paths['/images/generations'];
60+
}
5761

5862
Object.entries(updatedSchema.paths).map(([path, operation]) => {
5963
if (operation.post) {
6064
if (codeSample) {
6165
updatedSchema.paths[path].post['x-codeSamples'] = codeSample;
6266
}
6367
if (options.models?.length) {
64-
const newModels = [
65-
...new Set([
66-
...(updatedSchema.paths[path]?.post?.requestBody?.content[
67-
'application/json'
68-
]?.schema?.properties?.model?.enum || []),
69-
...options.models,
70-
]),
71-
];
68+
let newModels = options.models;
69+
const defaultModel =
70+
updatedSchema?.paths?.[path]?.post?.requestBody?.content?.[
71+
'application/json'
72+
]?.schema?.properties?.model?.enum?.[0];
73+
if (defaultModel && !newModels.includes(defaultModel)) {
74+
newModels = [defaultModel, ...newModels];
75+
}
7276
try {
7377
updatedSchema.paths[path].post.requestBody.content[
7478
'application/json'

0 commit comments

Comments
 (0)