File tree Expand file tree Collapse file tree
meta_configurator/src/utility Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99export const SUPPORTED_LANGUAGES = [
1010 'python' ,
11+ 'python (pydantic)' ,
1112 'typescript' ,
1213 'javascript' ,
1314 'rust' ,
@@ -62,7 +63,8 @@ export async function quicktypeJSONSchema(
6263
6364 return await quicktype ( {
6465 inputData,
65- lang : targetLanguage ,
66+ lang : removeParametersFromLanguage ( targetLanguage ) ,
67+ rendererOptions : getRendererOptions ( targetLanguage ) ,
6668 } ) ;
6769}
6870
@@ -71,8 +73,8 @@ export async function generateValidationCode(
7173 schemaFileName : string ,
7274 instanceFileName : string
7375) {
74- const languageAlphaNumerical = formatLanguagesToOnlyAlphaNumerical ( language ) ;
75- const template = await loadValidationTemplate ( languageAlphaNumerical ) ;
76+ const languageId = formatLanguagesToOnlyAlphaNumerical ( removeParametersFromLanguage ( language ) ) ;
77+ const template = await loadValidationTemplate ( languageId ) ;
7678 if ( ! template ) {
7779 return undefined ;
7880 }
@@ -100,3 +102,20 @@ function formatLanguagesToOnlyAlphaNumerical(language: string): string {
100102 // replace C++ with cpp
101103 return language . toLowerCase ( ) . replace ( / c \+ \+ / , 'cpp' ) ;
102104}
105+
106+ function removeParametersFromLanguage ( language : string ) : string {
107+ // remove everything after the first space
108+ const index = language . indexOf ( ' ' ) ;
109+ if ( index !== - 1 ) {
110+ return language . substring ( 0 , index ) ;
111+ }
112+ return language ;
113+ }
114+
115+ function getRendererOptions ( language : string ) : any {
116+ const rendererOptions : any = { } ;
117+ if ( language . includes ( 'pydantic' ) ) {
118+ rendererOptions [ 'pydantic-base-model' ] = true ;
119+ }
120+ return rendererOptions ;
121+ }
You can’t perform that action at this time.
0 commit comments