@@ -107,20 +107,29 @@ public ModelsMap postProcessModels(ModelsMap objs) {
107107 }
108108
109109 // fill src/main/resources/body/*.java to the body of the class.
110- try (InputStream inputStream = getClass ().getClassLoader ()
111- .getResourceAsStream ("body/" + codegenModel .name + ".java" )) {
112- if (inputStream != null ) {
113- String src = new String (inputStream .readAllBytes (), StandardCharsets .UTF_8 );
114- codegenModel .vendorExtensions .put ("x-body" , indent4 (src ));
115- }
116- } catch (IOException e ) {
117- // do nothing.
118- }
110+ String body = readPartialBody ("body/model/" + codegenModel .name + ".java" );
111+ codegenModel .vendorExtensions .put ("x-body" , body );
119112 }
120113
121114 return modelsMap ;
122115 }
123116
117+ private String readPartialBody (String path ) {
118+ // fill src/main/resources/body/*.java to the body of the class.
119+ try (InputStream inputStream = getClass ().getClassLoader ()
120+ .getResourceAsStream (path )) {
121+ if (inputStream != null ) {
122+ System .out .println ("Partial body file found: " + path );
123+ String src = new String (inputStream .readAllBytes (), StandardCharsets .UTF_8 );
124+ return indent4 (src );
125+ }
126+ } catch (IOException e ) {
127+ // do nothing.
128+ }
129+ System .out .println ("Partial body file NOT found: " + path );
130+ return null ;
131+ }
132+
124133 @ Override
125134 public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > objs ) {
126135 final Map <String , ModelsMap > processed = super .postProcessAllModels (objs );
@@ -203,6 +212,13 @@ protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
203212 .replace ("Client" , "" )
204213 + "ExceptionBuilder"
205214 );
215+ })
216+ .put ("injectbody" , (fragment , writer ) -> {
217+ String text = fragment .execute ();
218+ String body = readPartialBody ("body/api/" + text + ".java" );
219+ if (body != null ) {
220+ writer .write (body );
221+ }
206222 });
207223 }
208224
0 commit comments