Skip to content

Commit

Permalink
Minor change to Helidon version handling allowing snapshot versions (O…
Browse files Browse the repository at this point in the history
…penAPITools#19320)

* Minor change to Helidon version handling

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>

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

Co-authored-by: martin-mfg <2026226+martin-mfg@users.noreply.github.com>

* Review comments: fix typo in comment

---------

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
Co-authored-by: martin-mfg <2026226+martin-mfg@users.noreply.github.com>
  • Loading branch information
tjquinno and martin-mfg authored Aug 9, 2024
1 parent ad7acc3 commit 07baddf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private HashMap<String, String> loadKnownHttpStatusMap() {
}

private void setHelidonVersion(String version) {
helidonVersion = VersionUtil.instance().chooseVersion(version);
helidonVersion = VersionUtil.instance().chooseVersionBestMatchOrSelf(version);
setParentVersion(helidonVersion);
helidonMajorVersion = VersionUtil.majorVersion(helidonVersion);
}
Expand Down Expand Up @@ -769,6 +769,30 @@ String chooseVersion(String requestedVersion) {
return chooseVersion(requestedVersion, versions);
}

/**
* Returns either the best match version or, if there is none, the requested version itself to allow references to
* unpublished releases such as snapshots.
*
* @param requestedVersion version to search for
* @return either the best match or, if none, the requested version itself
*/
String chooseVersionBestMatchOrSelf(String requestedVersion) {
return chooseVersionBestMatchOrSelf(requestedVersion, versions);
}

/**
* Returns either the best match version or, if there is none, the requested version itself to allow references to
* unpublished releases such as snapshots.
*
* @param requestedVersion version to search for
* @param candidateVersions releases to consider
* @return either the best match or, if none, the requested version itself
*/
String chooseVersionBestMatchOrSelf(String requestedVersion, List<String> candidateVersions) {
String bestMatch = chooseVersion(requestedVersion, candidateVersions);
return bestMatch != null ? bestMatch : requestedVersion;
}

/**
* Returns the version that is the "closest" match to the requested version expression from among the provided
* releases, where the expression expression is one of the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ void testVersionNotInDefaultListWithNoNetwork() {
}



@Test void checkUseOfUnpublishedRelease() {
assertThat(test.chooseVersionBestMatchOrSelf("4.0.11-SNAPSHOT",
List.of("4.0.10", "3.2.1", "3.2.0", "2.0.4", "1.2.3", "1.2.2", "1.1.0")))
.isEqualTo("4.0.11-SNAPSHOT");
}
}

0 comments on commit 07baddf

Please sign in to comment.