From b22f250d43f2c9022992b15d7f57de69f7fab3f3 Mon Sep 17 00:00:00 2001
From: TetianaServirog <tetiana.servirog@gmail.com>
Date: Tue, 28 Apr 2020 19:56:52 +0300
Subject: [PATCH 1/4] [BUG][MARKDOWN] fix parameter and property names (#6089)

---
 .../MarkdownDocumentationCodegen.java         | 52 +++++++++++++++----
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
index d0985397042..c61c5cbac94 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
@@ -1,21 +1,18 @@
 package org.openapitools.codegen.languages;
 
-import org.openapitools.codegen.*;
-import io.swagger.models.properties.ArrayProperty;
-import io.swagger.models.properties.MapProperty;
-import io.swagger.models.properties.Property;
-import io.swagger.models.parameters.Parameter;
-
-import java.io.File;
-import java.util.*;
-
-import org.apache.commons.lang3.StringUtils;
-
+import org.openapitools.codegen.CodegenConfig;
+import org.openapitools.codegen.CodegenType;
+import org.openapitools.codegen.DefaultCodegen;
+import org.openapitools.codegen.SupportingFile;
 import org.openapitools.codegen.meta.GeneratorMetadata;
 import org.openapitools.codegen.meta.Stability;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
+
+import static org.openapitools.codegen.utils.StringUtils.escape;
+
 public class MarkdownDocumentationCodegen extends DefaultCodegen implements CodegenConfig {
     public static final String PROJECT_NAME = "projectName";
 
@@ -49,4 +46,37 @@ public class MarkdownDocumentationCodegen extends DefaultCodegen implements Code
         supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
         // TODO: Fill this out.
     }
+
+    @Override
+    protected void initalizeSpecialCharacterMapping() {
+        // escape only those symbols that can mess up markdown
+        specialCharReplacements.put("\\", "\\\\");
+        specialCharReplacements.put("/", "\\/");
+        specialCharReplacements.put("`", "\\`");
+        specialCharReplacements.put("*", "\\*");
+        specialCharReplacements.put("_", "\\_");
+        specialCharReplacements.put("[", "\\[");
+        specialCharReplacements.put("]", "\\]");
+
+        // todo Current markdown api and model mustache templates display properties and parameters in tables. It can be
+        // commonly escaped with a backslash (e.g. GFM supports this). However, in some cases it may be necessary to
+        // choose a different approach.
+        specialCharReplacements.put("|", "\\|");
+    }
+
+    /**
+     * Works identically to {@link DefaultCodegen#toParamName(String)} but doesn't camelize.
+     *
+     * @param name Codegen property object
+     * @return the sanitized parameter name
+     */
+    @Override
+    public String toParamName(String name) {
+        if (reservedWords.contains(name)) {
+            return escapeReservedWord(name);
+        } else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains("" + ((char) character)))) {
+            return escape(name, specialCharReplacements, null, null);
+        }
+        return name;
+    }
 }
-- 
GitLab


From ef79f703a226f094cbb13fa621133c585d0f9607 Mon Sep 17 00:00:00 2001
From: TetianaServirog <tetiana.servirog@gmail.com>
Date: Wed, 29 Apr 2020 10:29:14 +0300
Subject: [PATCH 2/4] Update Petstore samples for markdown

---
 samples/documentation/markdown/.openapi-generator/VERSION | 2 +-
 samples/documentation/markdown/Apis/PetApi.md             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/samples/documentation/markdown/.openapi-generator/VERSION b/samples/documentation/markdown/.openapi-generator/VERSION
index 58592f031f6..b5d898602c2 100644
--- a/samples/documentation/markdown/.openapi-generator/VERSION
+++ b/samples/documentation/markdown/.openapi-generator/VERSION
@@ -1 +1 @@
-4.2.3-SNAPSHOT
\ No newline at end of file
+4.3.1-SNAPSHOT
\ No newline at end of file
diff --git a/samples/documentation/markdown/Apis/PetApi.md b/samples/documentation/markdown/Apis/PetApi.md
index 591d7c0d312..74b3c455c58 100644
--- a/samples/documentation/markdown/Apis/PetApi.md
+++ b/samples/documentation/markdown/Apis/PetApi.md
@@ -41,7 +41,7 @@ null (empty response body)
 
 <a name="deletePet"></a>
 # **deletePet**
-> deletePet(petId, apiKey)
+> deletePet(petId, api\_key)
 
 Deletes a pet
 
@@ -50,7 +50,7 @@ Deletes a pet
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
  **petId** | **Long**| Pet id to delete | [default to null]
- **apiKey** | **String**|  | [optional] [default to null]
+ **api\_key** | **String**|  | [optional] [default to null]
 
 ### Return type
 
-- 
GitLab


From 9af374e44ef9fdd0826517cad767af7db07d3e86 Mon Sep 17 00:00:00 2001
From: TetianaServirog <tetiana.servirog@gmail.com>
Date: Wed, 29 Apr 2020 10:51:17 +0300
Subject: [PATCH 3/4] Fix comment

---
 .../codegen/languages/MarkdownDocumentationCodegen.java     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
index c61c5cbac94..1d76b22cbda 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/MarkdownDocumentationCodegen.java
@@ -58,9 +58,9 @@ public class MarkdownDocumentationCodegen extends DefaultCodegen implements Code
         specialCharReplacements.put("[", "\\[");
         specialCharReplacements.put("]", "\\]");
 
-        // todo Current markdown api and model mustache templates display properties and parameters in tables. It can be
-        // commonly escaped with a backslash (e.g. GFM supports this). However, in some cases it may be necessary to
-        // choose a different approach.
+        // todo Current markdown api and model mustache templates display properties and parameters in tables. Pipe
+        //  symbol in a table can be commonly escaped with a backslash (e.g. GFM supports this). However, in some cases
+        //  it may be necessary to choose a different approach.
         specialCharReplacements.put("|", "\\|");
     }
 
-- 
GitLab


From 1382bb2ba72f4f76805f08c40d14a38079a59dc3 Mon Sep 17 00:00:00 2001
From: Jim Schubert <james.schubert@gmail.com>
Date: Sat, 1 Aug 2020 17:20:15 -0400
Subject: [PATCH 4/4] Regenerate markdown sample

---
 .../markdown/.openapi-generator/FILES         | 12 ++++++++
 .../markdown/.openapi-generator/VERSION       |  2 +-
 samples/documentation/markdown/Apis/PetApi.md |  8 +++---
 .../documentation/markdown/Apis/StoreApi.md   |  4 +--
 .../documentation/markdown/Apis/UserApi.md    | 28 +++++++++----------
 samples/documentation/markdown/README.md      |  7 -----
 6 files changed, 33 insertions(+), 28 deletions(-)
 create mode 100644 samples/documentation/markdown/.openapi-generator/FILES

diff --git a/samples/documentation/markdown/.openapi-generator/FILES b/samples/documentation/markdown/.openapi-generator/FILES
new file mode 100644
index 00000000000..53bf49ac0cf
--- /dev/null
+++ b/samples/documentation/markdown/.openapi-generator/FILES
@@ -0,0 +1,12 @@
+Apis/PetApi.md
+Apis/StoreApi.md
+Apis/UserApi.md
+Models/ApiResponse.md
+Models/Category.md
+Models/InlineObject.md
+Models/InlineObject1.md
+Models/Order.md
+Models/Pet.md
+Models/Tag.md
+Models/User.md
+README.md
diff --git a/samples/documentation/markdown/.openapi-generator/VERSION b/samples/documentation/markdown/.openapi-generator/VERSION
index 71d2eb1c7fc..d99e7162d01 100644
--- a/samples/documentation/markdown/.openapi-generator/VERSION
+++ b/samples/documentation/markdown/.openapi-generator/VERSION
@@ -1 +1 @@
-5.0.0-SNAPSHOT
+5.0.0-SNAPSHOT
\ No newline at end of file
diff --git a/samples/documentation/markdown/Apis/PetApi.md b/samples/documentation/markdown/Apis/PetApi.md
index b2c016637ee..956077f32ee 100644
--- a/samples/documentation/markdown/Apis/PetApi.md
+++ b/samples/documentation/markdown/Apis/PetApi.md
@@ -16,7 +16,7 @@ Method | HTTP request | Description
 
 <a name="addPet"></a>
 # **addPet**
-> Pet addPet(pet)
+> Pet addPet(Pet)
 
 Add a new pet to the store
 
@@ -24,7 +24,7 @@ Add a new pet to the store
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **pet** | [**Pet**](..//Models/Pet.md)| Pet object that needs to be added to the store |
+ **Pet** | [**Pet**](..//Models/Pet.md)| Pet object that needs to be added to the store |
 
 ### Return type
 
@@ -148,7 +148,7 @@ Name | Type | Description  | Notes
 
 <a name="updatePet"></a>
 # **updatePet**
-> Pet updatePet(pet)
+> Pet updatePet(Pet)
 
 Update an existing pet
 
@@ -156,7 +156,7 @@ Update an existing pet
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **pet** | [**Pet**](..//Models/Pet.md)| Pet object that needs to be added to the store |
+ **Pet** | [**Pet**](..//Models/Pet.md)| Pet object that needs to be added to the store |
 
 ### Return type
 
diff --git a/samples/documentation/markdown/Apis/StoreApi.md b/samples/documentation/markdown/Apis/StoreApi.md
index b6d71962894..9c1dd2b588e 100644
--- a/samples/documentation/markdown/Apis/StoreApi.md
+++ b/samples/documentation/markdown/Apis/StoreApi.md
@@ -90,7 +90,7 @@ No authorization required
 
 <a name="placeOrder"></a>
 # **placeOrder**
-> Order placeOrder(order)
+> Order placeOrder(Order)
 
 Place an order for a pet
 
@@ -98,7 +98,7 @@ Place an order for a pet
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **order** | [**Order**](..//Models/Order.md)| order placed for purchasing the pet |
+ **Order** | [**Order**](..//Models/Order.md)| order placed for purchasing the pet |
 
 ### Return type
 
diff --git a/samples/documentation/markdown/Apis/UserApi.md b/samples/documentation/markdown/Apis/UserApi.md
index 071091c7416..01aaf35f4f4 100644
--- a/samples/documentation/markdown/Apis/UserApi.md
+++ b/samples/documentation/markdown/Apis/UserApi.md
@@ -16,7 +16,7 @@ Method | HTTP request | Description
 
 <a name="createUser"></a>
 # **createUser**
-> createUser(user)
+> createUser(User)
 
 Create user
 
@@ -26,7 +26,7 @@ Create user
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **user** | [**User**](..//Models/User.md)| Created user object |
+ **User** | [**User**](..//Models/User.md)| Created user object |
 
 ### Return type
 
@@ -34,7 +34,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
@@ -43,7 +43,7 @@ null (empty response body)
 
 <a name="createUsersWithArrayInput"></a>
 # **createUsersWithArrayInput**
-> createUsersWithArrayInput(user)
+> createUsersWithArrayInput(User)
 
 Creates list of users with given input array
 
@@ -51,7 +51,7 @@ Creates list of users with given input array
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **user** | [**List**](..//Models/User.md)| List of user object |
+ **User** | [**List**](..//Models/User.md)| List of user object |
 
 ### Return type
 
@@ -59,7 +59,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
@@ -68,7 +68,7 @@ null (empty response body)
 
 <a name="createUsersWithListInput"></a>
 # **createUsersWithListInput**
-> createUsersWithListInput(user)
+> createUsersWithListInput(User)
 
 Creates list of users with given input array
 
@@ -76,7 +76,7 @@ Creates list of users with given input array
 
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
- **user** | [**List**](..//Models/User.md)| List of user object |
+ **User** | [**List**](..//Models/User.md)| List of user object |
 
 ### Return type
 
@@ -84,7 +84,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
@@ -111,7 +111,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
@@ -184,7 +184,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
@@ -193,7 +193,7 @@ null (empty response body)
 
 <a name="updateUser"></a>
 # **updateUser**
-> updateUser(username, user)
+> updateUser(username, User)
 
 Updated user
 
@@ -204,7 +204,7 @@ Updated user
 Name | Type | Description  | Notes
 ------------- | ------------- | ------------- | -------------
  **username** | **String**| name that need to be deleted | [default to null]
- **user** | [**User**](..//Models/User.md)| Updated user object |
+ **User** | [**User**](..//Models/User.md)| Updated user object |
 
 ### Return type
 
@@ -212,7 +212,7 @@ null (empty response body)
 
 ### Authorization
 
-[auth_cookie](../README.md#auth_cookie)
+[api_key](../README.md#api_key)
 
 ### HTTP request headers
 
diff --git a/samples/documentation/markdown/README.md b/samples/documentation/markdown/README.md
index 0ceb7bae32d..b40f7e919cd 100644
--- a/samples/documentation/markdown/README.md
+++ b/samples/documentation/markdown/README.md
@@ -52,13 +52,6 @@ Class | Method | HTTP request | Description
 - **API key parameter name**: api_key
 - **Location**: HTTP header
 
-<a name="auth_cookie"></a>
-### auth_cookie
-
-- **Type**: API key
-- **API key parameter name**: AUTH_KEY
-- **Location**: 
-
 <a name="petstore_auth"></a>
 ### petstore_auth
 
-- 
GitLab