Skip to content

Commit fbada6e

Browse files
committed
Merge branch 'java_fix_apiclient' of https://github.com/wing328/swagger-codegen into wing328-java_fix_apiclient
2 parents bd7904d + 9e0c865 commit fbada6e

File tree

29 files changed

+1446
-0
lines changed

29 files changed

+1446
-0
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ public void processOpts() {
117117

118118
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
119119
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
120+
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
121+
// guess from api package
122+
String derviedInvokerPackage = deriveInvokerPackageName((String)additionalProperties.get(CodegenConstants.API_PACKAGE));
123+
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
124+
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
125+
LOGGER.info("Invoker Package Name, originally not set, is now dervied from api package name: " + derviedInvokerPackage);
126+
} else if (additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
127+
// guess from model package
128+
String derviedInvokerPackage = deriveInvokerPackageName((String)additionalProperties.get(CodegenConstants.MODEL_PACKAGE));
129+
this.additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, derviedInvokerPackage);
130+
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
131+
LOGGER.info("Invoker Package Name, originally not set, is now dervied from model package name: " + derviedInvokerPackage);
120132
} else {
121133
//not set, use default to be passed to template
122134
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
@@ -845,4 +857,23 @@ public String escapeUnsafeCharacters(String input) {
845857
return input.replace("*/", "*_/").replace("/*", "/_*");
846858
}
847859

860+
/*
861+
* Derive invoker package name based on the input
862+
* e.g. foo.bar.model => foo.bar
863+
*
864+
* @param input API package/model name
865+
* @return Derived invoker package name based on API package/model name
866+
*/
867+
private String deriveInvokerPackageName(String input) {
868+
String[] parts = input.split(Pattern.quote(".")); // Split on period.
869+
870+
StringBuilder sb = new StringBuilder();
871+
String delim = "";
872+
for (String p : Arrays.copyOf(parts, parts.length-1)) {
873+
sb.append(delim).append(p);
874+
delim = ".";
875+
}
876+
return sb.toString();
877+
}
878+
848879
}

samples/client/petstore/java/feign/src/main/java/io/swagger/client/api/FakeApi.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.swagger.client.ApiClient;
44

5+
import io.swagger.client.model.Client;
56
import org.joda.time.LocalDate;
67
import org.joda.time.DateTime;
78
import java.math.BigDecimal;
@@ -16,6 +17,19 @@
1617
public interface FakeApi extends ApiClient.Api {
1718

1819

20+
/**
21+
* To test \"client\" model
22+
*
23+
* @param body client model (required)
24+
* @return Client
25+
*/
26+
@RequestLine("PATCH /fake")
27+
@Headers({
28+
"Content-type: application/json",
29+
"Accept: application/json",
30+
})
31+
Client testClientModel(Client body);
32+
1933
/**
2034
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
2135
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Swagger Petstore
3+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator program.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
25+
26+
package io.swagger.client.model;
27+
28+
import java.util.Objects;
29+
import com.fasterxml.jackson.annotation.JsonProperty;
30+
import io.swagger.annotations.ApiModel;
31+
import io.swagger.annotations.ApiModelProperty;
32+
33+
34+
/**
35+
* Client
36+
*/
37+
38+
public class Client {
39+
@JsonProperty("client")
40+
private String client = null;
41+
42+
public Client client(String client) {
43+
this.client = client;
44+
return this;
45+
}
46+
47+
/**
48+
* Get client
49+
* @return client
50+
**/
51+
@ApiModelProperty(example = "null", value = "")
52+
public String getClient() {
53+
return client;
54+
}
55+
56+
public void setClient(String client) {
57+
this.client = client;
58+
}
59+
60+
61+
@Override
62+
public boolean equals(java.lang.Object o) {
63+
if (this == o) {
64+
return true;
65+
}
66+
if (o == null || getClass() != o.getClass()) {
67+
return false;
68+
}
69+
Client client = (Client) o;
70+
return Objects.equals(this.client, client.client);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(client);
76+
}
77+
78+
@Override
79+
public String toString() {
80+
StringBuilder sb = new StringBuilder();
81+
sb.append("class Client {\n");
82+
83+
sb.append(" client: ").append(toIndentedString(client)).append("\n");
84+
sb.append("}");
85+
return sb.toString();
86+
}
87+
88+
/**
89+
* Convert the given object to string with each line indented by 4 spaces
90+
* (except the first line).
91+
*/
92+
private String toIndentedString(java.lang.Object o) {
93+
if (o == null) {
94+
return "null";
95+
}
96+
return o.toString().replace("\n", "\n ");
97+
}
98+
}
99+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Client
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**client** | **String** | | [optional]
8+
9+
10+

samples/client/petstore/java/jersey1/docs/FakeApi.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,54 @@ All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**testClientModel**](FakeApi.md#testClientModel) | **PATCH** /fake | To test \"client\" model
78
[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
89
[**testEnumQueryParameters**](FakeApi.md#testEnumQueryParameters) | **GET** /fake | To test enum query parameters
910

1011

12+
<a name="testClientModel"></a>
13+
# **testClientModel**
14+
> Client testClientModel(body)
15+
16+
To test \&quot;client\&quot; model
17+
18+
### Example
19+
```java
20+
// Import classes:
21+
//import io.swagger.client.ApiException;
22+
//import io.swagger.client.api.FakeApi;
23+
24+
25+
FakeApi apiInstance = new FakeApi();
26+
Client body = new Client(); // Client | client model
27+
try {
28+
Client result = apiInstance.testClientModel(body);
29+
System.out.println(result);
30+
} catch (ApiException e) {
31+
System.err.println("Exception when calling FakeApi#testClientModel");
32+
e.printStackTrace();
33+
}
34+
```
35+
36+
### Parameters
37+
38+
Name | Type | Description | Notes
39+
------------- | ------------- | ------------- | -------------
40+
**body** | [**Client**](Client.md)| client model |
41+
42+
### Return type
43+
44+
[**Client**](Client.md)
45+
46+
### Authorization
47+
48+
No authorization required
49+
50+
### HTTP request headers
51+
52+
- **Content-Type**: application/json
53+
- **Accept**: application/json
54+
1155
<a name="testEndpointParameters"></a>
1256
# **testEndpointParameters**
1357
> testEndpointParameters(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password)

samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/api/FakeApi.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.swagger.client.model.*;
3333
import io.swagger.client.Pair;
3434

35+
import io.swagger.client.model.Client;
3536
import org.joda.time.LocalDate;
3637
import org.joda.time.DateTime;
3738
import java.math.BigDecimal;
@@ -62,6 +63,47 @@ public void setApiClient(ApiClient apiClient) {
6263
this.apiClient = apiClient;
6364
}
6465

66+
/**
67+
* To test \&quot;client\&quot; model
68+
*
69+
* @param body client model (required)
70+
* @return Client
71+
* @throws ApiException if fails to make API call
72+
*/
73+
public Client testClientModel(Client body) throws ApiException {
74+
Object localVarPostBody = body;
75+
76+
// verify the required parameter 'body' is set
77+
if (body == null) {
78+
throw new ApiException(400, "Missing the required parameter 'body' when calling testClientModel");
79+
}
80+
81+
// create path and map variables
82+
String localVarPath = "/fake".replaceAll("\\{format\\}","json");
83+
84+
// query params
85+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
86+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
87+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
88+
89+
90+
91+
92+
final String[] localVarAccepts = {
93+
"application/json"
94+
};
95+
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
96+
97+
final String[] localVarContentTypes = {
98+
"application/json"
99+
};
100+
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
101+
102+
String[] localVarAuthNames = new String[] { };
103+
104+
GenericType<Client> localVarReturnType = new GenericType<Client>() {};
105+
return apiClient.invokeAPI(localVarPath, "PATCH", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
106+
}
65107
/**
66108
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
67109
* Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* Swagger Petstore
3+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
*
5+
* OpenAPI spec version: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by the swagger code generator program.
9+
* https://github.com/swagger-api/swagger-codegen.git
10+
* Do not edit the class manually.
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
25+
26+
package io.swagger.client.model;
27+
28+
import java.util.Objects;
29+
import com.fasterxml.jackson.annotation.JsonProperty;
30+
import io.swagger.annotations.ApiModel;
31+
import io.swagger.annotations.ApiModelProperty;
32+
33+
34+
/**
35+
* Client
36+
*/
37+
38+
public class Client {
39+
@JsonProperty("client")
40+
private String client = null;
41+
42+
public Client client(String client) {
43+
this.client = client;
44+
return this;
45+
}
46+
47+
/**
48+
* Get client
49+
* @return client
50+
**/
51+
@ApiModelProperty(example = "null", value = "")
52+
public String getClient() {
53+
return client;
54+
}
55+
56+
public void setClient(String client) {
57+
this.client = client;
58+
}
59+
60+
61+
@Override
62+
public boolean equals(java.lang.Object o) {
63+
if (this == o) {
64+
return true;
65+
}
66+
if (o == null || getClass() != o.getClass()) {
67+
return false;
68+
}
69+
Client client = (Client) o;
70+
return Objects.equals(this.client, client.client);
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(client);
76+
}
77+
78+
@Override
79+
public String toString() {
80+
StringBuilder sb = new StringBuilder();
81+
sb.append("class Client {\n");
82+
83+
sb.append(" client: ").append(toIndentedString(client)).append("\n");
84+
sb.append("}");
85+
return sb.toString();
86+
}
87+
88+
/**
89+
* Convert the given object to string with each line indented by 4 spaces
90+
* (except the first line).
91+
*/
92+
private String toIndentedString(java.lang.Object o) {
93+
if (o == null) {
94+
return "null";
95+
}
96+
return o.toString().replace("\n", "\n ");
97+
}
98+
}
99+

0 commit comments

Comments
 (0)