File tree Expand file tree Collapse file tree 4 files changed +763
-737
lines changed
Expand file tree Collapse file tree 4 files changed +763
-737
lines changed Original file line number Diff line number Diff line change 1- import type { IRSchemaObject } from './ir' ;
1+ import type { IRParameterObject , IRSchemaObject } from './ir' ;
22
33/**
44 * Ensure we don't produce redundant types, e.g. string | string.
@@ -64,3 +64,38 @@ export const deduplicateSchema = <T extends IRSchemaObject>({
6464
6565 return schema ;
6666} ;
67+
68+ export const irParametersToIrSchema = ( {
69+ parameters,
70+ } : {
71+ parameters : Record < string , IRParameterObject > ;
72+ } ) : IRSchemaObject => {
73+ const irSchema : IRSchemaObject = {
74+ type : 'object' ,
75+ } ;
76+
77+ if ( parameters ) {
78+ const properties : Record < string , IRSchemaObject > = { } ;
79+ const required : Array < string > = [ ] ;
80+
81+ for ( const name in parameters ) {
82+ const parameter = parameters [ name ] ;
83+
84+ properties [ name ] = deduplicateSchema ( {
85+ schema : parameter . schema ,
86+ } ) ;
87+
88+ if ( parameter . required ) {
89+ required . push ( name ) ;
90+ }
91+ }
92+
93+ irSchema . properties = properties ;
94+
95+ if ( required . length ) {
96+ irSchema . required = required ;
97+ }
98+ }
99+
100+ return irSchema ;
101+ } ;
You can’t perform that action at this time.
0 commit comments