Skip to content

Commit 58d64c2

Browse files
committed
Fix oneOf schema display in HTML2 generator
Convert technical 'oneOf<type1,type2>' format to readable 'Type1 or Type2' for better HTML documentation display. Fixes #4431
1 parent 37cac71 commit 58d64c2

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticHtml2Generator.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import static org.openapitools.codegen.utils.StringUtils.*;
4141

42-
public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfig {
42+
public class StaticHtml2Generator extends DefaultCodegen {
4343
private final Logger LOGGER = LoggerFactory.getLogger(StaticHtml2Generator.class);
4444

4545
protected String invokerPackage = "org.openapitools.client"; // default for Java and Android
@@ -141,6 +141,8 @@ public String getTypeDeclaration(Schema p) {
141141
return super.getTypeDeclaration(p);
142142
}
143143

144+
145+
144146
@Override
145147
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
146148
OperationMap operations = objs.getOperations();
@@ -288,6 +290,44 @@ public String escapeUnsafeCharacters(String input) {
288290
return input;
289291
}
290292

293+
@Override
294+
public String getSchemaType(Schema p) {
295+
String schemaType = super.getSchemaType(p);
296+
297+
// For oneOf schemas, provide a more human-readable format for HTML display
298+
if (schemaType != null && schemaType.startsWith("oneOf<") && schemaType.endsWith(">")) {
299+
// Extract the types inside oneOf<...> and format them as "Type1 or Type2"
300+
String innerTypes = schemaType.substring(6, schemaType.length() - 1);
301+
String[] types = innerTypes.split(",");
302+
List<String> formattedTypes = new ArrayList<>();
303+
304+
for (String type : types) {
305+
String trimmedType = type.trim();
306+
// Convert technical names to more readable ones
307+
if ("object".equals(trimmedType)) {
308+
formattedTypes.add("Object");
309+
} else if ("string".equals(trimmedType)) {
310+
formattedTypes.add("String");
311+
} else if ("integer".equals(trimmedType)) {
312+
formattedTypes.add("Integer");
313+
} else if ("number".equals(trimmedType)) {
314+
formattedTypes.add("Number");
315+
} else if ("boolean".equals(trimmedType)) {
316+
formattedTypes.add("Boolean");
317+
} else if ("array".equals(trimmedType)) {
318+
formattedTypes.add("Array");
319+
} else {
320+
// Capitalize first letter for other types
321+
formattedTypes.add(trimmedType.substring(0, 1).toUpperCase() + trimmedType.substring(1));
322+
}
323+
}
324+
325+
return String.join(" or ", formattedTypes);
326+
}
327+
328+
return schemaType;
329+
}
330+
291331
@Override
292332
public GeneratorLanguage generatorLanguage() {
293333
return null;

0 commit comments

Comments
 (0)