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
move api/v2/version endpoint to OPTIONS /api #8506
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8506 +/- ##
==========================================
+ Coverage 62.4% 62.4% +<.1%
- Complexity 8122 8130 +8
==========================================
Files 1316 1319 +3
Lines 38638 38651 +13
Branches 3865 3865
==========================================
+ Hits 24119 24131 +12
- Misses 12829 12830 +1
Partials 1690 1690
Continue to review full report at Codecov.
|
molgenis-api-data/src/main/java/org/molgenis/api/data/v2/RestControllerV2.java
Show resolved
Hide resolved
@@ -55,6 +55,7 @@ | |||
import static org.testng.reporters.Files.readFile; | |||
|
|||
import com.google.common.collect.Sets; | |||
import java.text.ParseException; |
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.
Is suggest not to change any tests (see comment in RestControllerV2).
@@ -17,7 +17,7 @@ | |||
*/ | |||
public ApiController(String apiId, Integer apiVersion) { | |||
requireNonNull(apiId); | |||
if (!API_ID_PATTERN.matcher(apiId).matches()) { | |||
if (!apiId.isEmpty() && !API_ID_PATTERN.matcher(apiId).matches()) { |
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.
Add a unit test for empty apiId
@@ -0,0 +1,8 @@ | |||
package org.molgenis.api; | |||
|
|||
public class VersionApiNamespace { |
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.
We agreed on OPTIONS /api
to expose the application version, right? That would make this class unnecessary.
|
||
@RestController | ||
@RequestMapping(API_PATH) | ||
public class VersionController extends ApiController { |
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.
How about renaming this class to RootApiController so we can extend it with other planned endpoints such as listing all apis with their versions?
|
||
@Autowired | ||
@RequestMapping(method = OPTIONS) | ||
public VersionResponse getVersion() throws ParseException { |
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.
I suggest storing the version information under the app key.
{
"app": {
"version": "...",
"buildDate": "..."
},
"apis": []
}
The apis key could be added in the future.
.andReturn(); | ||
String actual = result.getResponse().getContentAsString(); | ||
String expected = | ||
"{\"molgenisVersion\":\"versionString\",\"buildDate\":\"2019-05-21T10:32:00Z\"}"; |
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.
I think that it is a good idea to use one format for date-times in JSON requests/responses everywhere. Did you look into adding milliseconds? It would make sense considering the places where we use datetimes.
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.
Response object contains an Instant, the conversion to json is than done centrally by the application right?
@AutoGson(autoValueClass = AutoValue_VersionResponse.class) | ||
@SuppressWarnings("squid:S1610") | ||
public abstract class VersionResponse { | ||
public abstract String getMolgenisVersion(); |
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.
getVersion
instead of getMolgenisVersion
new VersionController("versionString", "2019-05-21 10:32 UTC"); | ||
mockMvc = | ||
MockMvcBuilders.standaloneSetup(versionController) | ||
.setMessageConverters(new FormHttpMessageConverter(), gsonHttpMessageConverter) |
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.
I suspect you don't need a FormHttpMessageConverter here.
ce6268f
to
681e992
Compare
@TestExecutionListeners(listeners = WithSecurityContextTestExecutionListener.class) | ||
@TestPropertySource(properties = {"molgenis.version = 10.3.8"}) | ||
@ContextConfiguration(classes = {GsonConfig.class}) | ||
public class VersionControllerTest extends AbstractTestNGSpringContextTests { |
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.
Rename to RootApiControllerTest
|
||
@RestController | ||
@RequestMapping(API_PATH) | ||
public class RootApiController extends ApiController { |
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.
Add swagger annotations
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.
swagger not working yet
@AutoValue | ||
@AutoGson(autoValueClass = AutoValue_VersionResponse.class) | ||
@SuppressWarnings("squid:S1610") | ||
public abstract class VersionResponse { |
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.
Rename to something like OptionsResponse/ApiOptionsResponse
|
||
@Autowired | ||
@RequestMapping(method = OPTIONS) | ||
public VersionResponse getVersion() throws ParseException { |
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.
Deprecate /api/v2 version endpoint and refer to this endpoint
Checklist