Skip to content
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

Better handling of operationID starting with numbers #691

Merged
merged 12 commits into from
Aug 1, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ public String toOperationId(String operationId) {
operationId = "call_" + operationId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not sanitizing here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm

}

// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not sanitizing here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand, this is just about adding the call_ prefix. The value will be sanitized on line 612: return camelize(sanitizeName(operationId));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my bad, didnt see that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmini is correct. It was already sanitized a few lines above and that's the reason why I didn't call the function sanitize again when the operationId starts with a number.

}

return camelize(sanitizeName(operationId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(sanitizedOperationId)) {
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to "
+ camelize("call_" + operationId));
+ camelize("call_" + sanitizedOperationId));
sanitizedOperationId = "call_" + sanitizedOperationId;
}

// operationId starts with a number
if (sanitizedOperationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + sanitizedOperationId));
sanitizedOperationId = "call_" + sanitizedOperationId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,12 @@ public String toOperationId(String operationId) {
return newOperationId;
}

// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
operationId = camelize("call_" + operationId, true);
}

return operationId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,14 @@ public String toOperationId(String operationId) {

// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
return underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
return underscore(sanitizeName("call_" + operationId));
}

// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not sanitizing here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt see sanitization on returning value

}

//return underscore(operationId).replaceAll("[^A-Za-z0-9_]", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public String toOperationId(String operationId) {
operationId = "call_" + operationId;
}

// model name starts with a number
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not sanitizing here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,8 @@ paths:
tags:
- "$another-fake?"
summary: To test special tags
description: To test special tags
operationId: test_special_tags
description: To test special tags and operation ID starting with number
operationId: 123_test_@#$%_special_tags
consumes:
- application/json
produces:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ paths:
tags:
- $another-fake?
summary: To test special tags
description: To test special tags
operationId: test_special_tags
description: To test special tags and operation ID starting with number
operationId: 123_test_@#$%_special_tags
responses:
'200':
description: successful operation
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.1-SNAPSHOT
3.2.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **Patch** /another-fake/dummy | To test special tags
*AnotherFakeApi* | [**Call123TestSpecialTags**](docs/AnotherFakeApi.md#call123testspecialtags) | **Patch** /another-fake/dummy | To test special tags
*FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **Post** /fake/outer/boolean |
*FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **Post** /fake/outer/composite |
*FakeApi* | [**FakeOuterNumberSerialize**](docs/FakeApi.md#fakeouternumberserialize) | **Post** /fake/outer/number |
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/go/go-petstore/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ paths:
- fake
/another-fake/dummy:
patch:
description: To test special tags
operationId: test_special_tags
description: To test special tags and operation ID starting with number
operationId: 123_test_@#$%_special_tags
requestBody:
content:
application/json:
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/go/go-petstore/api_another_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type AnotherFakeApiService service

/*
AnotherFakeApiService To test special tags
To test special tags
To test special tags and operation ID starting with number
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param client client model
@return Client
*/
func (a *AnotherFakeApiService) TestSpecialTags(ctx context.Context, client Client) (Client, *http.Response, error) {
func (a *AnotherFakeApiService) Call123TestSpecialTags(ctx context.Context, client Client) (Client, *http.Response, error) {
var (
localVarHttpMethod = strings.ToUpper("Patch")
localVarPostBody interface{}
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/go/go-petstore/docs/AnotherFakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**TestSpecialTags**](AnotherFakeApi.md#TestSpecialTags) | **Patch** /another-fake/dummy | To test special tags
[**Call123TestSpecialTags**](AnotherFakeApi.md#Call123TestSpecialTags) | **Patch** /another-fake/dummy | To test special tags


# **TestSpecialTags**
> Client TestSpecialTags(ctx, client)
# **Call123TestSpecialTags**
> Client Call123TestSpecialTags(ctx, client)
To test special tags

To test special tags
To test special tags and operation ID starting with number

### Required Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface AnotherFakeApi extends ApiClient.Api {

/**
* To test special tags
* To test special tags
* To test special tags and operation ID starting with number
* @param client client model (required)
* @return Client
*/
Expand All @@ -26,5 +26,5 @@ public interface AnotherFakeApi extends ApiClient.Api {
"Content-Type: application/json",
"Accept: application/json",
})
Client testSpecialTags(Client client);
Client call123testSpecialTags(Client client);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**testSpecialTags**](AnotherFakeApi.md#testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags
[**call123testSpecialTags**](AnotherFakeApi.md#call123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags


<a name="testSpecialTags"></a>
# **testSpecialTags**
> Client testSpecialTags(client)
<a name="call123testSpecialTags"></a>
# **call123testSpecialTags**
> Client call123testSpecialTags(client)

To test special tags

To test special tags
To test special tags and operation ID starting with number

### Example
```java
Expand All @@ -25,10 +25,10 @@ To test special tags
AnotherFakeApi apiInstance = new AnotherFakeApi();
Client client = new Client(); // Client | client model
try {
Client result = apiInstance.testSpecialTags(client);
Client result = apiInstance.call123testSpecialTags(client);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnotherFakeApi#testSpecialTags");
System.err.println("Exception when calling AnotherFakeApi#call123testSpecialTags");
e.printStackTrace();
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ public void setApiClient(ApiClient apiClient) {

/**
* To test special tags
* To test special tags
* To test special tags and operation ID starting with number
* <p><b>200</b> - successful operation
* @param client client model
* @return Client
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Client testSpecialTags(Client client) throws IOException {
HttpResponse response = testSpecialTagsForHttpResponse(client);
public Client call123testSpecialTags(Client client) throws IOException {
HttpResponse response = call123testSpecialTagsForHttpResponse(client);
TypeReference typeRef = new TypeReference<Client>() {};
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}

/**
* To test special tags
* To test special tags
* To test special tags and operation ID starting with number
* <p><b>200</b> - successful operation
* @param client client model
* @param params Map of query params. A collection will be interpreted as passing in multiple instances of the same query param.
* @return Client
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Client testSpecialTags(Client client, Map<String, Object> params) throws IOException {
HttpResponse response = testSpecialTagsForHttpResponse(client, params);
public Client call123testSpecialTags(Client client, Map<String, Object> params) throws IOException {
HttpResponse response = call123testSpecialTagsForHttpResponse(client, params);
TypeReference typeRef = new TypeReference<Client>() {};
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
}

public HttpResponse testSpecialTagsForHttpResponse(Client client) throws IOException {
public HttpResponse call123testSpecialTagsForHttpResponse(Client client) throws IOException {
// verify the required parameter 'client' is set
if (client == null) {
throw new IllegalArgumentException("Missing the required parameter 'client' when calling testSpecialTags");
throw new IllegalArgumentException("Missing the required parameter 'client' when calling call123testSpecialTags");
}
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/another-fake/dummy");

Expand All @@ -83,10 +83,10 @@ public HttpResponse testSpecialTagsForHttpResponse(Client client) throws IOExcep
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute();
}

public HttpResponse testSpecialTagsForHttpResponse(java.io.InputStream client, String mediaType) throws IOException {
public HttpResponse call123testSpecialTagsForHttpResponse(java.io.InputStream client, String mediaType) throws IOException {
// verify the required parameter 'client' is set
if (client == null) {
throw new IllegalArgumentException("Missing the required parameter 'client' when calling testSpecialTags");
throw new IllegalArgumentException("Missing the required parameter 'client' when calling call123testSpecialTags");
}
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/another-fake/dummy");

Expand All @@ -99,10 +99,10 @@ apiClient.new JacksonJsonHttpContent(null) :
return apiClient.getHttpRequestFactory().buildRequest(HttpMethods.PATCH, genericUrl, content).execute();
}

public HttpResponse testSpecialTagsForHttpResponse(Client client, Map<String, Object> params) throws IOException {
public HttpResponse call123testSpecialTagsForHttpResponse(Client client, Map<String, Object> params) throws IOException {
// verify the required parameter 'client' is set
if (client == null) {
throw new IllegalArgumentException("Missing the required parameter 'client' when calling testSpecialTags");
throw new IllegalArgumentException("Missing the required parameter 'client' when calling call123testSpecialTags");
}
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/another-fake/dummy");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class AnotherFakeApiTest {
/**
* To test special tags
*
* To test special tags
* To test special tags and operation ID starting with number
*
* @throws IOException
* if the Api call fails
*/
@Test
public void testSpecialTagsTest() throws IOException {
public void call123testSpecialTagsTest() throws IOException {
Client client = null;
Client response = api.testSpecialTags(client);
Client response = api.call123testSpecialTags(client);

// TODO: test validations
}
Expand Down
14 changes: 7 additions & 7 deletions samples/client/petstore/java/jersey1/docs/AnotherFakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**testSpecialTags**](AnotherFakeApi.md#testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags
[**call123testSpecialTags**](AnotherFakeApi.md#call123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags


<a name="testSpecialTags"></a>
# **testSpecialTags**
> Client testSpecialTags(client)
<a name="call123testSpecialTags"></a>
# **call123testSpecialTags**
> Client call123testSpecialTags(client)

To test special tags

To test special tags
To test special tags and operation ID starting with number

### Example
```java
Expand All @@ -25,10 +25,10 @@ To test special tags
AnotherFakeApi apiInstance = new AnotherFakeApi();
Client client = new Client(); // Client | client model
try {
Client result = apiInstance.testSpecialTags(client);
Client result = apiInstance.call123testSpecialTags(client);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnotherFakeApi#testSpecialTags");
System.err.println("Exception when calling AnotherFakeApi#call123testSpecialTags");
e.printStackTrace();
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public void setApiClient(ApiClient apiClient) {

/**
* To test special tags
* To test special tags
* To test special tags and operation ID starting with number
* @param client client model (required)
* @return Client
* @throws ApiException if fails to make API call
*/
public Client testSpecialTags(Client client) throws ApiException {
public Client call123testSpecialTags(Client client) throws ApiException {
Object localVarPostBody = client;

// verify the required parameter 'client' is set
if (client == null) {
throw new ApiException(400, "Missing the required parameter 'client' when calling testSpecialTags");
throw new ApiException(400, "Missing the required parameter 'client' when calling call123testSpecialTags");
}

// create path and map variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public class AnotherFakeApiTest {
/**
* To test special tags
*
* To test special tags
* To test special tags and operation ID starting with number
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void testSpecialTagsTest() throws ApiException {
public void call123testSpecialTagsTest() throws ApiException {
Client client = null;
Client response = api.testSpecialTags(client);
Client response = api.call123testSpecialTags(client);

// TODO: test validations
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*

Method | HTTP request | Description
------------- | ------------- | -------------
[**testSpecialTags**](AnotherFakeApi.md#testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags
[**call123testSpecialTags**](AnotherFakeApi.md#call123testSpecialTags) | **PATCH** /another-fake/dummy | To test special tags


<a name="testSpecialTags"></a>
# **testSpecialTags**
> Client testSpecialTags(client)
<a name="call123testSpecialTags"></a>
# **call123testSpecialTags**
> Client call123testSpecialTags(client)

To test special tags

To test special tags
To test special tags and operation ID starting with number

### Example
```java
Expand All @@ -25,10 +25,10 @@ To test special tags
AnotherFakeApi apiInstance = new AnotherFakeApi();
Client client = new Client(); // Client | client model
try {
Client result = apiInstance.testSpecialTags(client);
Client result = apiInstance.call123testSpecialTags(client);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AnotherFakeApi#testSpecialTags");
System.err.println("Exception when calling AnotherFakeApi#call123testSpecialTags");
e.printStackTrace();
}
```
Expand Down
Loading