@@ -116,9 +116,14 @@ private void flattenBody(String pathname, RequestBody body) {
116116 if (model .getProperties () != null && !model .getProperties ().isEmpty ()) {
117117 flattenProperties (model .getProperties (), pathname );
118118 String modelName = resolveModelName (model .getTitle (), genericName );
119- mediaType .setSchema (new Schema ().$ref (modelName ));
120- addGenerated (modelName , model );
121- openAPI .getComponents ().addSchemas (modelName , model );
119+ String existing = matchGenerated (model );
120+ if (existing != null ) {
121+ mediaType .setSchema (new Schema ().$ref (existing ));
122+ } else {
123+ mediaType .setSchema (new Schema ().$ref (modelName ));
124+ addGenerated (modelName , model );
125+ openAPI .getComponents ().addSchemas (modelName , model );
126+ }
122127 } else if (model instanceof ComposedSchema composedSchema ) {
123128 flattenComposedSchema (composedSchema , pathname );
124129 if (model .get$ref () == null ) {
@@ -170,9 +175,14 @@ private void flattenParams(String pathname, List<Parameter> parameters) {
170175 if (model .getProperties () != null && !model .getProperties ().isEmpty ()) {
171176 flattenProperties (model .getProperties (), pathname );
172177 String modelName = resolveModelName (model .getTitle (), parameter .getName ());
173- parameter .setSchema (new Schema ().$ref (modelName ));
174- addGenerated (modelName , model );
175- openAPI .getComponents ().addSchemas (modelName , model );
178+ String existing = matchGenerated (model );
179+ if (existing != null ) {
180+ parameter .setSchema (new Schema ().$ref (existing ));
181+ } else {
182+ parameter .setSchema (new Schema ().$ref (modelName ));
183+ addGenerated (modelName , model );
184+ openAPI .getComponents ().addSchemas (modelName , model );
185+ }
176186 }
177187 }
178188 } else if (model instanceof ComposedSchema ) {
0 commit comments