@@ -71,20 +71,30 @@ module.exports = {
71
71
}
72
72
}
73
73
74
- // This renames schema objects ensuring they're proper Java class names.
74
+ // This renames schema objects ensuring they're proper Java class names. It also removes files that are schemas of simple types.
75
75
76
76
const schemas = asyncapi . components ( ) . schemas ( ) ;
77
77
//console.log("schemas: " + JSON.stringify(schemas));
78
78
79
79
for ( const schema in schemas ) {
80
- let javaName = _ . camelCase ( schema ) ;
81
- javaName = _ . upperFirst ( javaName ) ;
82
-
83
- if ( javaName !== schema ) {
84
- const oldPath = path . resolve ( sourcePath , `${ schema } .java` ) ;
85
- const newPath = path . resolve ( sourcePath , `${ javaName } .java` ) ;
86
- fs . renameSync ( oldPath , newPath ) ;
87
- // console.log("Renamed class file " + schema + " to " + javaName);
80
+
81
+ let schemaObj = schemas [ schema ] ;
82
+ let type = schemaObj . type ( ) ;
83
+ const oldPath = path . resolve ( sourcePath , `${ schema } .java` ) ;
84
+
85
+ //console.log(`postprocess schema ${schema} ${type}`);
86
+
87
+ if ( type === 'object' || type === 'enum' ) {
88
+ let javaName = _ . camelCase ( schema ) ;
89
+ javaName = _ . upperFirst ( javaName ) ;
90
+
91
+ if ( javaName !== schema ) {
92
+ const newPath = path . resolve ( sourcePath , `${ javaName } .java` ) ;
93
+ fs . renameSync ( oldPath , newPath ) ;
94
+ // console.log("Renamed class file " + schema + " to " + javaName);
95
+ }
96
+ } else {
97
+ fs . unlinkSync ( oldPath ) ;
88
98
}
89
99
}
90
100
0 commit comments