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 @@ -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}
You can’t perform that action at this time.
0 commit comments