-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[java][resttemplate] Fix missing javax validation imports with list validation #18332
Conversation
thanks for the PR. can you please follow step 3 to update the samples so that the CI can verify the change? |
apologies, issue with newline fixed now, samples should match |
not sure what is missing, just rebased and reran step 3 and diff is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing the changes to resttemplate
with the below input specification, I noticed that the imports are also missing in the generated UserApiTest.java.
Could you please also test the same for apache-httpclient
and webclient
? And also if these generators have the javax
related problem mentioned in my other comment? Thanks!
openapi: 3.0.3
info:
title: issue-17485
version: 0.1.0
servers:
- url: http://api.example.xyz/v1
paths:
/user:
get:
tags:
- user
parameters:
- name: username
in: path
required: true
description: The name of the user
schema:
type: array
items:
type: string
pattern: "^[a-zA-Z0-9]$"
responses:
"200":
description: OK
@@ -13,6 +13,11 @@ import java.util.Locale; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
|
|||
{{#useBeanValidation}} | |||
import {{javaxPackage}}.validation.constraints.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pom.xml generated for resttemplate always includes the jakarta
dependency and never the javax
dependency. But {{javaxPackage}}
used in this line by default refers to javax. So please either change the pom.xml or hard-code jakarta here.
I tried re-generating samples and can confirm that it doesn't generate any changes. |
I tested the changes against the yaml from #17485 and got the below: package org.openapitools.client.api;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestClientException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for UserApi
*/
@Disabled
class UserApiTest {
private final UserApi api = new UserApi();
/**
*
*
*
*
* @throws RestClientException
* if the Api call fails
*/
@Test
void userGetTest() {
List<String> username = null;
api.userGet(username);
// TODO: test validations
}
} The API tests don't seem to need jakarta validation imports. Also, addressed the javax/jakarta issue. The |
Hi @horaceli, using the [...]
package org.openapitools.client.api;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestClientException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for UserApi
*/
@Disabled
class UserApiTest {
private final UserApi api = new UserApi();
/**
*
*
*
*
* @throws RestClientException
* if the Api call fails
*/
@Test
void userGetTest() {
List<@Pattern(regexp = "^[a-zA-Z0-9]$")String> username = null;
api.userGet(username);
// TODO: test validations
}
} This uses
Why? |
Thanks for the review. Re the This is the same point as you made earlier in #18332 (comment), but I was just applying to all the other generators under Re the generated API tests, I'll check again and get back to you. |
Oh, I wasn't aware the javax problem affects so many different libraries. Good to have it fixed everywhere!
Great. |
Managed to reproduce the issue for API tests, maybe it was a bad cache, apologies. I've made the changes now for all the generators I've touched, and added a sample/test with the swagger we've been testing with. Let me know your thoughts. |
@@ -0,0 +1,11 @@ | |||
generatorName: java | |||
outputDir: samples/client/petstore/java/resttemplate-list-schema-validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add the output folder to .github/workflows/samples-java-client-jdk11.yaml
so that the CI will test it moving forward?
Thanks for the PR, which has been merged. CI failure fixed via 8860537 |
Related fix for #17485 which was a regression in 7.2.0 after #17165. That change did not add the necessary imports to the generated API when bean validation was enabled and the schema contained an array that had item level validation.
#17857 only fixed the issue for java native client, this is a similar fix for java resttemplate client.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@nbruno
@cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg