From d46cabcd4f7aa9b33dd526af0e6224670031e93e Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 31 Jul 2019 13:50:29 +0800 Subject: [PATCH] Better handling of dot in inline model name (#3498) * better handling of dot in inline model name * do nothing if title is present * add comment --- .../openapitools/codegen/InlineModelResolver.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 5ea4a08a1a34..4ed482f4b8fd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -407,9 +407,19 @@ public class InlineModelResolver { } } + /** + * Generates a unique model name. Non-alphanumeric characters will be replaced + * with underscores + * + * @param title String title field in the schema if present + * @param key String model name + */ private String resolveModelName(String title, String key) { if (title == null) { - return uniqueName(key); + // for auto-generated schema name, replace non-alphanumeric characters with underscore + // to avoid bugs with schema look up with inline schema created on the fly + // e.g. io.schema.User_name => io_schema_User_name + return uniqueName(key).replaceAll("[^A-Za-z0-9]", "_"); } else { return uniqueName(title); } @@ -589,4 +599,4 @@ public class InlineModelResolver { target.addExtension(extName, vendorExtensions.get(extName)); } } -} \ No newline at end of file +}