File tree Expand file tree Collapse file tree
packages/generators-v2/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import * as codeSamples from './code-samples/index.js' ;
22
33export 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'
You can’t perform that action at this time.
0 commit comments