Skip to content

Commit 652b6a7

Browse files
committed
Minor change to Helidon version handling
Signed-off-by: Tim Quinn <[email protected]>
1 parent 4b49335 commit 652b6a7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaHelidonCommonCodegen.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private HashMap<String, String> loadKnownHttpStatusMap() {
483483
}
484484

485485
private void setHelidonVersion(String version) {
486-
helidonVersion = VersionUtil.instance().chooseVersion(version);
486+
helidonVersion = VersionUtil.instance().chooseVersionBestMatchOrSelf(version);
487487
setParentVersion(helidonVersion);
488488
helidonMajorVersion = VersionUtil.majorVersion(helidonVersion);
489489
}
@@ -769,6 +769,30 @@ String chooseVersion(String requestedVersion) {
769769
return chooseVersion(requestedVersion, versions);
770770
}
771771

772+
/**
773+
* Returns either the best match version of, if there is none, the requested version itself to allow references to
774+
* unpublished releases such as snapshots.
775+
*
776+
* @param requestedVersion version to search for
777+
* @return either the best match or, if none, the requested version itself
778+
*/
779+
String chooseVersionBestMatchOrSelf(String requestedVersion) {
780+
return chooseVersionBestMatchOrSelf(requestedVersion, versions);
781+
}
782+
783+
/**
784+
* Returns either the best match version of, if there is none, the requested version itself to allow references to
785+
* unpublished releases such as snapshots.
786+
*
787+
* @param requestedVersion version to search for
788+
* @param candidateVersions releases to consider
789+
* @return either the best match or, if none, the requested version itself
790+
*/
791+
String chooseVersionBestMatchOrSelf(String requestedVersion, List<String> candidateVersions) {
792+
String bestMatch = chooseVersion(requestedVersion, candidateVersions);
793+
return bestMatch != null ? bestMatch : requestedVersion;
794+
}
795+
772796
/**
773797
* Returns the version that is the "closest" match to the requested version expression from among the provided
774798
* releases, where the expression expression is one of the following:

modules/openapi-generator/src/test/java/org/openapitools/codegen/languages/HelidonCommonCodegenTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@ void testVersionNotInDefaultListWithNoNetwork() {
4848
}
4949

5050

51+
52+
@Test void checkUseOfUnpublishedRelease() {
53+
assertThat(test.chooseVersionBestMatchOrSelf("4.0.11-SNAPSHOT",
54+
List.of("4.0.10", "3.2.1", "3.2.0", "2.0.4", "1.2.3", "1.2.2", "1.1.0")))
55+
.isEqualTo("4.0.11-SNAPSHOT");
56+
}
5157
}

0 commit comments

Comments
 (0)