From b006b1b128697e644a3d0aa888c73839e24c56c5 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 19 Aug 2023 10:20:02 +0800 Subject: [PATCH] Improve documentations (#16346) * improve doc * update urls --- .../README.adoc | 15 ++++++++++ .../openapi-generator-maven-plugin/README.md | 3 ++ .../codegen/InlineModelResolver.java | 2 +- .../codegen/InlineModelResolverTest.java | 2 +- .../3_0/invalid_ref_request_body.yaml | 30 +++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 modules/openapi-generator/src/test/resources/3_0/invalid_ref_request_body.yaml diff --git a/modules/openapi-generator-gradle-plugin/README.adoc b/modules/openapi-generator-gradle-plugin/README.adoc index 6088f97b7b6..3b75426d361 100644 --- a/modules/openapi-generator-gradle-plugin/README.adoc +++ b/modules/openapi-generator-gradle-plugin/README.adoc @@ -239,6 +239,21 @@ apply plugin: 'org.openapi.generator' |None |specifies mappings between the schema and the new name in the format of schema_a=Cat,schema_b=Bird. https://openapi-generator.tech/docs/customization/#schema-mapping +|nameMappings +|Map(String,String) +|None +|specifies mappings between the property name and the new name in the format of property_a=firstProperty,property_b=secondProperty. https://openapi-generator.tech/docs/customization/#name-mapping + +|modelNameMappings +|Map(String,String) +|None +|specifies mappings between the model name and the new name in the format of model_a=FirstModel,property_b=SecondModel. https://openapi-generator.tech/docs/customization/#name-mapping + +|parameterNameMappings +|Map(String,String) +|None +|specifies mappings between the parameter name and the new name in the format of parameter_a=firstParameter,parameter_b=secondParameter. https://openapi-generator.tech/docs/customization/#name-mapping + |inlineSchemaNameMappings |Map(String,String) |None diff --git a/modules/openapi-generator-maven-plugin/README.md b/modules/openapi-generator-maven-plugin/README.md index 02341e78ee4..15b47ba991f 100644 --- a/modules/openapi-generator-maven-plugin/README.md +++ b/modules/openapi-generator-maven-plugin/README.md @@ -86,6 +86,9 @@ mvn clean compile | `importMappings` | `openapi.generator.maven.plugin.importMappings` | specifies mappings between a given class and the import that should be used for that class in the format of type=import,type=import. You can also have multiple occurrences of this option | `typeMappings` | `openapi.generator.maven.plugin.typeMappings` | sets mappings between OpenAPI spec types and generated code types in the format of OpenAPIType=generatedType,OpenAPIType=generatedType. For example: `array=List,map=Map,string=String`. You can also have multiple occurrences of this option. To map a specified format, use type+format, e.g. string+password=EncryptedString will map `type: string, format: password` to `EncryptedString`. | `schemaMappings` | `openapi.generator.maven.plugin.schemaMappings` | specifies mappings between the schema and the new name in the format of schema_a=Cat,schema_b=Bird. https://openapi-generator.tech/docs/customization/#schema-mapping +| `nameMappings` | `openapi.generator.maven.plugin.nameMappings` | specifies mappings between the property name and the new name in the format of property_a=firstProperty,property_b=secondProperty. https://openapi-generator.tech/docs/customization/#name-mapping +| `modelNameMappings` | `openapi.generator.maven.plugin.modelNameMappings` | specifies mappings between the model name and the new name in the format of model_a=FirstModel,model_b=SecondModel. https://openapi-generator.tech/docs/customization/#name-mapping +| `parameterNameMappings` | `openapi.generator.maven.plugin.parameterNameMappings` | specifies mappings between the parameter name and the new name in the format of param_a=first_parameter,param_b=second_parameter. https://openapi-generator.tech/docs/customization/#name-mapping | `inlineSchemaNameMappings` | `openapi.generator.maven.plugin.inlineSchemaNameMappings` | specifies mappings between the inline schema name and the new name in the format of inline_object_2=Cat,inline_object_5=Bird. | `inlineSchemaOptions` | `openapi.generator.maven.plugin.inlineSchemaOptions` | specifies the options used when naming inline schema in inline model resolver | `languageSpecificPrimitives` | `openapi.generator.maven.plugin.languageSpecificPrimitives` | specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: `String,boolean,Boolean,Double`. You can also have multiple occurrences of this option 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 94b686f7c8d..cf920ddfde7 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 @@ -963,7 +963,7 @@ public class InlineModelResolver { addGenerated(name, schema); openAPI.getComponents().addSchemas(name, schema); if (!name.equals(schema.getTitle()) && !inlineSchemaNameMappingValues.contains(name)) { - LOGGER.info("Inline schema created as {}. To have complete control of the model name, set the `title` field or use the inlineSchemaNameMapping option (--inline-schema-name-mappings in CLI).", name); + LOGGER.info("Inline schema created as {}. To have complete control of the model name, set the `title` field or use the modelNameMapping option (e.g. --model-name-mappings {}=NewModel,ModelA=NewModelA in CLI) or inlineSchemaNameMapping option (--inline-schema-name-mappings {}=NewModel,ModelA=NewModelA in CLI).", name, name, name); } uniqueNames.add(name); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java index 69d04cf3da8..98ebf7b333f 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/InlineModelResolverTest.java @@ -354,7 +354,7 @@ public class InlineModelResolverTest { @Test public void resolveRequestBodyInvalidRef() { - OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/inline_model_resolver.yaml"); + OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/invalid_ref_request_body.yaml"); new InlineModelResolver().flatten(openAPI); RequestBody requestBodyReference = openAPI diff --git a/modules/openapi-generator/src/test/resources/3_0/invalid_ref_request_body.yaml b/modules/openapi-generator/src/test/resources/3_0/invalid_ref_request_body.yaml new file mode 100644 index 00000000000..f571d109b33 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/invalid_ref_request_body.yaml @@ -0,0 +1,30 @@ +openapi: 3.0.1 +info: + version: 1.0.0 + title: Example + license: + name: MIT +servers: + - url: http://api.example.xyz/v1 +paths: + /resolve_request_body_invalid_ref: + post: + requestBody: + $ref: '#/components/schemas/Invalid' + operationId: resolveRequestBodyInvalidRef + responses: + '200': + description: OK +components: + requestBodies: {} + schemas: + Users: + type: array + items: + title: User + type: object + properties: + street: + type: string + city: + type: string