Skip to content

[MARKDOWN] fix property and parameter names #6105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -49,4 +46,37 @@ public MarkdownDocumentationCodegen() {
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. 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("|", "\\|");
}

/**
* 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;
}
}
12 changes: 12 additions & 0 deletions samples/documentation/markdown/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions samples/documentation/markdown/Apis/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Method | HTTP request | Description

<a name="addPet"></a>
# **addPet**
> Pet addPet(pet)
> Pet addPet(Pet)

Add a new pet to the store

### Parameters

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

Expand All @@ -41,7 +41,7 @@ Name | Type | Description | Notes

<a name="deletePet"></a>
# **deletePet**
> deletePet(petId, apiKey)
> deletePet(petId, api\_key)

Deletes a pet

Expand All @@ -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

Expand Down Expand Up @@ -148,15 +148,15 @@ Name | Type | Description | Notes

<a name="updatePet"></a>
# **updatePet**
> Pet updatePet(pet)
> Pet updatePet(Pet)

Update an existing pet

### Parameters

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

Expand Down
4 changes: 2 additions & 2 deletions samples/documentation/markdown/Apis/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ No authorization required

<a name="placeOrder"></a>
# **placeOrder**
> Order placeOrder(order)
> Order placeOrder(Order)

Place an order for a pet

### Parameters

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

Expand Down
28 changes: 14 additions & 14 deletions samples/documentation/markdown/Apis/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Method | HTTP request | Description

<a name="createUser"></a>
# **createUser**
> createUser(user)
> createUser(User)

Create user

Expand All @@ -26,15 +26,15 @@ Create user

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**User**](..//Models/User.md)| Created user object |
**User** | [**User**](..//Models/User.md)| Created user object |

### Return type

null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand All @@ -43,23 +43,23 @@ null (empty response body)

<a name="createUsersWithArrayInput"></a>
# **createUsersWithArrayInput**
> createUsersWithArrayInput(user)
> createUsersWithArrayInput(User)

Creates list of users with given input array

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**List**](..//Models/User.md)| List of user object |
**User** | [**List**](..//Models/User.md)| List of user object |

### Return type

null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand All @@ -68,23 +68,23 @@ null (empty response body)

<a name="createUsersWithListInput"></a>
# **createUsersWithListInput**
> createUsersWithListInput(user)
> createUsersWithListInput(User)

Creates list of users with given input array

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**user** | [**List**](..//Models/User.md)| List of user object |
**User** | [**List**](..//Models/User.md)| List of user object |

### Return type

null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand All @@ -111,7 +111,7 @@ null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand Down Expand Up @@ -184,7 +184,7 @@ null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand All @@ -193,7 +193,7 @@ null (empty response body)

<a name="updateUser"></a>
# **updateUser**
> updateUser(username, user)
> updateUser(username, User)

Updated user

Expand All @@ -204,15 +204,15 @@ 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

null (empty response body)

### Authorization

[auth_cookie](../README.md#auth_cookie)
[api_key](../README.md#api_key)

### HTTP request headers

Expand Down
7 changes: 0 additions & 7 deletions samples/documentation/markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down