forked from loafle/openapi-generator-original
better inline schema naming for double byte characters
This commit is contained in:
@@ -306,7 +306,8 @@ public class InlineModelResolver {
|
||||
if (schema.getAdditionalProperties() != null) {
|
||||
if (schema.getAdditionalProperties() instanceof Schema) {
|
||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||
String schemaName = resolveModelName(schema.getTitle(), modelPrefix + this.inlineSchemaNameDefaults.get("mapItemSuffix"));
|
||||
String schemaName = resolveModelName
|
||||
(schema.getTitle(), modelPrefix + this.inlineSchemaNameDefaults.get("mapItemSuffix"));
|
||||
// Recurse to create $refs for inner models
|
||||
gatherInlineModels(inner, schemaName);
|
||||
if (isModelNeeded(inner)) {
|
||||
@@ -679,7 +680,7 @@ public class InlineModelResolver {
|
||||
* @return if provided the sanitized {@code title}, else the sanitized {@code key}
|
||||
*/
|
||||
private String resolveModelName(String title, String modelName) {
|
||||
if (title == null) {
|
||||
if (title == null || "".equals(sanitizeName(title).replace("_", ""))) {
|
||||
if (modelName == null) {
|
||||
return uniqueName("inline_object");
|
||||
}
|
||||
|
||||
@@ -411,6 +411,16 @@ public class InlineModelResolverTest {
|
||||
requestBodyReference.getContent().get("application/json").getSchema().get$ref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveInlineRequestBodyWithTitleInChinese() {
|
||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
|
||||
RequestBody requestBodyReference = openAPI.getPaths().get("/resolve_inline_request_body_with_title_in_chinese").getPost().getRequestBody();
|
||||
assertEquals("#/components/schemas/resolveInlineRequestBodyWithRequired_request_1",
|
||||
requestBodyReference.getContent().get("application/json").getSchema().get$ref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonModelRequestBody() {
|
||||
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml");
|
||||
|
||||
@@ -64,6 +64,21 @@ paths:
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
/resolve_inline_request_body_with_title_in_chinese:
|
||||
post:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
title: 服務條款和私隱政策
|
||||
type: object
|
||||
properties:
|
||||
just_property:
|
||||
type: string
|
||||
operationId: resolveInlineRequestBodyWithRequired
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
/non_model_request_body:
|
||||
post:
|
||||
requestBody:
|
||||
|
||||
Reference in New Issue
Block a user