Skip to content

Commit 0adabcb

Browse files
JFCotewing328
andauthored
Fix Jspecify nullable issue with spring boot 4 (#23649)
* Fix jspecify nullable with springboot 4 * Remove useless empty line * add tests --------- Co-authored-by: William Cheng <wing328hk@gmail.com>
1 parent 5589824 commit 0adabcb

20 files changed

Lines changed: 771 additions & 25 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isPathParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{>paramDoc}} @PathVariable("{{baseName}}"){{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>optionalDataType}} {{paramName}}{{/isPathParam}}
1+
{{#isPathParam}}{{#vendorExtensions.x-field-extra-annotation}}{{{.}}} {{/vendorExtensions.x-field-extra-annotation}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}}{{>paramDoc}} @PathVariable("{{baseName}}"){{>dateTimeParam}}{{#isDeprecated}} @Deprecated{{/isDeprecated}} {{>nullableAnnotation}}{{>optionalDataType}} {{paramName}}{{/isPathParam}}

modules/openapi-generator/src/test/resources/3_0/java/jspecify.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ paths:
4747
default:
4848
description: ok
4949

50+
/file/{id}:
51+
get:
52+
parameters:
53+
- in: path
54+
name: id
55+
required: true
56+
schema:
57+
type: string
58+
responses:
59+
'200':
60+
description: ok
61+
5062
components:
5163
schemas:
5264
Foo:

samples/client/petstore/java/native-jackson3-jspecify/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ public class DefaultApiExample {
8585
// Configure clients using the `defaultClient` object, such as
8686
// overriding the host and port, timeout, etc.
8787
DefaultApi apiInstance = new DefaultApi(defaultClient);
88-
java.time.Instant dtParam = new java.time.Instant(); // java.time.Instant |
89-
java.time.Instant dtQuery = new java.time.Instant(); // java.time.Instant |
90-
java.time.Instant dtCookie = new java.time.Instant(); // java.time.Instant |
88+
String id = "id_example"; // String |
9189
try {
92-
Foo result = apiInstance.fooDtParamGet(dtParam, dtQuery, dtCookie);
93-
System.out.println(result);
90+
apiInstance.fileIdGet(id);
9491
} catch (ApiException e) {
95-
System.err.println("Exception when calling DefaultApi#fooDtParamGet");
92+
System.err.println("Exception when calling DefaultApi#fileIdGet");
9693
System.err.println("Status code: " + e.getCode());
9794
System.err.println("Reason: " + e.getResponseBody());
9895
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -109,6 +106,8 @@ All URIs are relative to *http://localhost*
109106

110107
Class | Method | HTTP request | Description
111108
------------ | ------------- | ------------- | -------------
109+
*DefaultApi* | [**fileIdGet**](docs/DefaultApi.md#fileIdGet) | **GET** /file/{id} |
110+
*DefaultApi* | [**fileIdGetWithHttpInfo**](docs/DefaultApi.md#fileIdGetWithHttpInfo) | **GET** /file/{id} |
112111
*DefaultApi* | [**fooDtParamGet**](docs/DefaultApi.md#fooDtParamGet) | **GET** /foo/{dtParam} |
113112
*DefaultApi* | [**fooDtParamGetWithHttpInfo**](docs/DefaultApi.md#fooDtParamGetWithHttpInfo) | **GET** /foo/{dtParam} |
114113
*DefaultApi* | [**uploadPost**](docs/DefaultApi.md#uploadPost) | **POST** /upload |

samples/client/petstore/java/native-jackson3-jspecify/api/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ paths:
5656
x-content-type: multipart/form-data
5757
x-accepts:
5858
- application/json
59+
/file/{id}:
60+
get:
61+
parameters:
62+
- explode: false
63+
in: path
64+
name: id
65+
required: true
66+
schema:
67+
type: string
68+
style: simple
69+
responses:
70+
"200":
71+
description: ok
72+
x-accepts:
73+
- application/json
5974
components:
6075
schemas:
6176
Foo:

samples/client/petstore/java/native-jackson3-jspecify/docs/DefaultApi.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,143 @@ All URIs are relative to *http://localhost*
44

55
| Method | HTTP request | Description |
66
|------------- | ------------- | -------------|
7+
| [**fileIdGet**](DefaultApi.md#fileIdGet) | **GET** /file/{id} | |
8+
| [**fileIdGetWithHttpInfo**](DefaultApi.md#fileIdGetWithHttpInfo) | **GET** /file/{id} | |
79
| [**fooDtParamGet**](DefaultApi.md#fooDtParamGet) | **GET** /foo/{dtParam} | |
810
| [**fooDtParamGetWithHttpInfo**](DefaultApi.md#fooDtParamGetWithHttpInfo) | **GET** /foo/{dtParam} | |
911
| [**uploadPost**](DefaultApi.md#uploadPost) | **POST** /upload | |
1012
| [**uploadPostWithHttpInfo**](DefaultApi.md#uploadPostWithHttpInfo) | **POST** /upload | |
1113

1214

1315

16+
## fileIdGet
17+
18+
> void fileIdGet(id)
19+
20+
21+
22+
### Example
23+
24+
```java
25+
// Import classes:
26+
import org.openapitools.client.ApiClient;
27+
import org.openapitools.client.ApiException;
28+
import org.openapitools.client.Configuration;
29+
import org.openapitools.client.models.*;
30+
import org.openapitools.client.api.DefaultApi;
31+
32+
public class Example {
33+
public static void main(String[] args) {
34+
ApiClient defaultClient = Configuration.getDefaultApiClient();
35+
defaultClient.setBasePath("http://localhost");
36+
37+
DefaultApi apiInstance = new DefaultApi(defaultClient);
38+
String id = "id_example"; // String |
39+
try {
40+
apiInstance.fileIdGet(id);
41+
} catch (ApiException e) {
42+
System.err.println("Exception when calling DefaultApi#fileIdGet");
43+
System.err.println("Status code: " + e.getCode());
44+
System.err.println("Reason: " + e.getResponseBody());
45+
System.err.println("Response headers: " + e.getResponseHeaders());
46+
e.printStackTrace();
47+
}
48+
}
49+
}
50+
```
51+
52+
### Parameters
53+
54+
55+
| Name | Type | Description | Notes |
56+
|------------- | ------------- | ------------- | -------------|
57+
| **id** | **String**| | |
58+
59+
### Return type
60+
61+
62+
null (empty response body)
63+
64+
### Authorization
65+
66+
No authorization required
67+
68+
### HTTP request headers
69+
70+
- **Content-Type**: Not defined
71+
- **Accept**: Not defined
72+
73+
### HTTP response details
74+
| Status code | Description | Response headers |
75+
|-------------|-------------|------------------|
76+
| **200** | ok | - |
77+
78+
## fileIdGetWithHttpInfo
79+
80+
> ApiResponse<Void> fileIdGetWithHttpInfo(id)
81+
82+
83+
84+
### Example
85+
86+
```java
87+
// Import classes:
88+
import org.openapitools.client.ApiClient;
89+
import org.openapitools.client.ApiException;
90+
import org.openapitools.client.ApiResponse;
91+
import org.openapitools.client.Configuration;
92+
import org.openapitools.client.models.*;
93+
import org.openapitools.client.api.DefaultApi;
94+
95+
public class Example {
96+
public static void main(String[] args) {
97+
ApiClient defaultClient = Configuration.getDefaultApiClient();
98+
defaultClient.setBasePath("http://localhost");
99+
100+
DefaultApi apiInstance = new DefaultApi(defaultClient);
101+
String id = "id_example"; // String |
102+
try {
103+
ApiResponse<Void> response = apiInstance.fileIdGetWithHttpInfo(id);
104+
System.out.println("Status code: " + response.getStatusCode());
105+
System.out.println("Response headers: " + response.getHeaders());
106+
} catch (ApiException e) {
107+
System.err.println("Exception when calling DefaultApi#fileIdGet");
108+
System.err.println("Status code: " + e.getCode());
109+
System.err.println("Response headers: " + e.getResponseHeaders());
110+
System.err.println("Reason: " + e.getResponseBody());
111+
e.printStackTrace();
112+
}
113+
}
114+
}
115+
```
116+
117+
### Parameters
118+
119+
120+
| Name | Type | Description | Notes |
121+
|------------- | ------------- | ------------- | -------------|
122+
| **id** | **String**| | |
123+
124+
### Return type
125+
126+
127+
ApiResponse<Void>
128+
129+
### Authorization
130+
131+
No authorization required
132+
133+
### HTTP request headers
134+
135+
- **Content-Type**: Not defined
136+
- **Accept**: Not defined
137+
138+
### HTTP response details
139+
| Status code | Description | Response headers |
140+
|-------------|-------------|------------------|
141+
| **200** | ok | - |
142+
143+
14144
## fooDtParamGet
15145

16146
> Foo fooDtParamGet(dtParam, dtQuery, dtCookie)

samples/client/petstore/java/native-jackson3-jspecify/src/main/java/org/openapitools/client/api/DefaultApi.java

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,110 @@ private File prepareDownloadFile(HttpResponse<InputStream> response) throws IOEx
172172
return file;
173173
}
174174

175+
/**
176+
*
177+
*
178+
* @param id (required)
179+
* @throws ApiException if fails to make API call
180+
*/
181+
public void fileIdGet(String id) throws ApiException {
182+
fileIdGet(id, null);
183+
}
184+
185+
/**
186+
*
187+
*
188+
* @param id (required)
189+
* @param headers Optional headers to include in the request
190+
* @throws ApiException if fails to make API call
191+
*/
192+
public void fileIdGet(String id, Map<String, String> headers) throws ApiException {
193+
fileIdGetWithHttpInfo(id, headers);
194+
}
195+
196+
/**
197+
*
198+
*
199+
* @param id (required)
200+
* @return ApiResponse&lt;Void&gt;
201+
* @throws ApiException if fails to make API call
202+
*/
203+
public ApiResponse<Void> fileIdGetWithHttpInfo(String id) throws ApiException {
204+
return fileIdGetWithHttpInfo(id, null);
205+
}
206+
207+
/**
208+
*
209+
*
210+
* @param id (required)
211+
* @param headers Optional headers to include in the request
212+
* @return ApiResponse&lt;Void&gt;
213+
* @throws ApiException if fails to make API call
214+
*/
215+
public ApiResponse<Void> fileIdGetWithHttpInfo(String id, Map<String, String> headers) throws ApiException {
216+
HttpRequest.Builder localVarRequestBuilder = fileIdGetRequestBuilder(id, headers);
217+
try {
218+
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
219+
localVarRequestBuilder.build(),
220+
HttpResponse.BodyHandlers.ofInputStream());
221+
if (memberVarResponseInterceptor != null) {
222+
memberVarResponseInterceptor.accept(localVarResponse);
223+
}
224+
InputStream localVarResponseBody = null;
225+
try {
226+
if (localVarResponse.statusCode()/ 100 != 2) {
227+
throw getApiException("fileIdGet", localVarResponse);
228+
}
229+
localVarResponseBody = ApiClient.getResponseBody(localVarResponse);
230+
if (localVarResponseBody != null) {
231+
localVarResponseBody.readAllBytes();
232+
}
233+
return new ApiResponse<>(
234+
localVarResponse.statusCode(),
235+
localVarResponse.headers().map(),
236+
null
237+
);
238+
} finally {
239+
if (localVarResponseBody != null) {
240+
localVarResponseBody.close();
241+
}
242+
}
243+
} catch (IOException e) {
244+
throw new ApiException(e);
245+
}
246+
catch (InterruptedException e) {
247+
Thread.currentThread().interrupt();
248+
throw new ApiException(e);
249+
}
250+
}
251+
252+
private HttpRequest.Builder fileIdGetRequestBuilder(String id, Map<String, String> headers) throws ApiException {
253+
// verify the required parameter 'id' is set
254+
if (id == null) {
255+
throw new ApiException(400, "Missing the required parameter 'id' when calling fileIdGet");
256+
}
257+
258+
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
259+
260+
String localVarPath = "/file/{id}"
261+
.replace("{id}", ApiClient.urlEncode(id.toString()));
262+
263+
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
264+
265+
localVarRequestBuilder.header("Accept", "application/json");
266+
267+
localVarRequestBuilder.method("GET", HttpRequest.BodyPublishers.noBody());
268+
if (memberVarReadTimeout != null) {
269+
localVarRequestBuilder.timeout(memberVarReadTimeout);
270+
}
271+
// Add custom headers if provided
272+
localVarRequestBuilder = HttpRequestBuilderExtensions.withAdditionalHeaders(localVarRequestBuilder, headers);
273+
if (memberVarInterceptor != null) {
274+
memberVarInterceptor.accept(localVarRequestBuilder);
275+
}
276+
return localVarRequestBuilder;
277+
}
278+
175279
/**
176280
*
177281
*

samples/client/petstore/java/restclient-springBoot4-jackson3-jspecify/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,11 @@ public class DefaultApiExample {
9393
defaultClient.setBasePath("http://localhost");
9494

9595
DefaultApi apiInstance = new DefaultApi(defaultClient);
96-
java.time.Instant dtParam = new java.time.Instant(); // java.time.Instant |
97-
java.time.Instant dtQuery = new java.time.Instant(); // java.time.Instant |
98-
java.time.Instant dtCookie = new java.time.Instant(); // java.time.Instant |
96+
String id = "id_example"; // String |
9997
try {
100-
Foo result = apiInstance.fooDtParamGet(dtParam, dtQuery, dtCookie);
101-
System.out.println(result);
98+
apiInstance.fileIdGet(id);
10299
} catch (HttpStatusCodeException e) {
103-
System.err.println("Exception when calling DefaultApi#fooDtParamGet");
100+
System.err.println("Exception when calling DefaultApi#fileIdGet");
104101
System.err.println("Status code: " + e.getStatusCode().value());
105102
System.err.println("Reason: " + e.getResponseBodyAsString());
106103
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -117,6 +114,7 @@ All URIs are relative to *http://localhost*
117114

118115
Class | Method | HTTP request | Description
119116
------------ | ------------- | ------------- | -------------
117+
*DefaultApi* | [**fileIdGet**](docs/DefaultApi.md#fileIdGet) | **GET** /file/{id} |
120118
*DefaultApi* | [**fooDtParamGet**](docs/DefaultApi.md#fooDtParamGet) | **GET** /foo/{dtParam} |
121119
*DefaultApi* | [**uploadPost**](docs/DefaultApi.md#uploadPost) | **POST** /upload |
122120

samples/client/petstore/java/restclient-springBoot4-jackson3-jspecify/api/openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ paths:
5656
x-content-type: multipart/form-data
5757
x-accepts:
5858
- application/json
59+
/file/{id}:
60+
get:
61+
parameters:
62+
- explode: false
63+
in: path
64+
name: id
65+
required: true
66+
schema:
67+
type: string
68+
style: simple
69+
responses:
70+
"200":
71+
description: ok
72+
x-accepts:
73+
- application/json
5974
components:
6075
schemas:
6176
Foo:

0 commit comments

Comments
 (0)