@@ -144,10 +144,8 @@ export default class Rust extends CodeGen {
144
144
isRequired = s . required . indexOf ( key ) !== - 1 ;
145
145
}
146
146
147
- const refTitle = this . refToTitle ( propSchema ) ;
148
- let typeName = this . getSafeTitle ( refTitle ) ;
149
- const isCycle = refTitle === s . title ;
150
- if ( isCycle ) {
147
+ let typeName = this . getSafeTitle ( this . refToTitle ( propSchema ) ) ;
148
+ if ( propSchema !== false && propSchema !== true && propSchema . isCycle ) {
151
149
typeName = `Box<${ typeName } >` ;
152
150
}
153
151
@@ -215,8 +213,7 @@ export default class Rust extends CodeGen {
215
213
216
214
protected handleUntypedObject ( s : JSONSchemaObject ) : TypeIntermediateRepresentation {
217
215
if ( s . additionalProperties ) {
218
- const refTitle = this . refToTitle ( s . additionalProperties ) ;
219
- const typeName = this . getSafeTitle ( refTitle ) ;
216
+ const typeName = this . getSafeTitle ( this . refToTitle ( s . additionalProperties ) ) ;
220
217
const propertyTypings = [
221
218
"#[serde(flatten)]" ,
222
219
`pub additional_properties: Option<${ typeName } >`
@@ -273,20 +270,25 @@ export default class Rust extends CodeGen {
273
270
}
274
271
275
272
private buildEnum ( s : JSONSchema [ ] ) : TypeIntermediateRepresentation {
273
+ const typeLines = s
274
+ . map ( ( enumItem ) => {
275
+ const typeName = this . getSafeTitle ( this . refToTitle ( enumItem ) ) ;
276
+ let rhsTypeName = typeName ;
277
+ if ( enumItem !== false && enumItem !== true && enumItem . isCycle ) {
278
+ rhsTypeName = `Box<${ typeName } >` ;
279
+ }
280
+ return `${ typeName } (${ rhsTypeName } )` ;
281
+ } )
282
+ . map ( ( l ) => ` ${ l } ,` )
283
+ . join ( "\n" ) ;
284
+
276
285
return {
277
286
macros : [
278
287
"#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]" ,
279
288
"#[serde(untagged)]"
280
289
] . join ( "\n" ) ,
281
290
prefix : "enum" ,
282
- typing : [
283
- "{" ,
284
- this . getJoinedSafeTitles ( s , "\n" )
285
- . split ( "\n" )
286
- . map ( ( l ) => ` ${ l } (${ l } ),` )
287
- . join ( "\n" ) ,
288
- "}" ,
289
- ] . join ( "\n" ) ,
291
+ typing : [ "{" , typeLines , "}" ] . join ( "\n" ) ,
290
292
imports : [
291
293
"use serde::{Serialize, Deserialize};" ,
292
294
]
0 commit comments