Skip to content
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

Update SpringDoc json/yaml generator to make the results more deterministic. #7574

Merged
merged 2 commits into from
Jan 3, 2024

Conversation

ianwallen
Copy link
Contributor

@ianwallen ianwallen commented Dec 21, 2023

Update SpringDoc json/yaml generator to make the results more deterministic.

This will make it easier to compare different versions between gn releases.

These are the properties that were enabled.

springdoc.writer-with-order-by-keys=true
springdoc.writer-with-default-pretty-printer=true

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests)
  • User documentation provided for new features or enhancements in mannual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

…nistic.

This will make it easier to compare different versions between gn releases.

These are the properties that were enabled.

   springdoc.writer-with-order-by-keys=true
   springdoc.writer-with-default-pretty-printer=true
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianwallen tested and looks working fine, but please check the comments added.

@@ -47,6 +47,8 @@
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;

import javax.servlet.http.HttpServletRequest;

import java.nio.charset.StandardCharsets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianwallen there are 2 unused imports, not related to the pull request, but would be good to clean up:

import org.springframework.core.annotation.AnnotationUtils;
...
import org.springframework.web.bind.annotation.ResponseBody;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -180,9 +189,14 @@ protected boolean isRestController(Map<String, Object> restControllers,
|| !ModelAndView.class.isAssignableFrom(handlerMethod.getMethod().getReturnType()));
}

protected void calculateServerUrl(HttpServletRequest request, String apiDocsUrl) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe a bit the changes related to calculateServerUrl / getServerBaseUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I noticed that calculateServerUrl was not only calculating a url, it was calculating a url and then setting the serverBaseUrl. I would have expected that calculateServerUrl would have returned a value but it was setting a value so I changed it to setServerBaseUrl to make it clearer.

I was also working on some other code and I needed to call the functionality from getServerBaseUrl in a couple places so I separated the function to avoid duplicate code.

I no longer needed to call getServerBaseUrl in multiple places but thought it was still good to keep it separated.

If you want I can merge the code back into a calculateServerUrl function?

this.openAPIService.setServerBaseUrl(calculatedUrl);
private String getServerBaseUrl(HttpServletRequest request) {
String contextPath = request.getContextPath();
StringBuffer requestURL = request.getRequestURL();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous code it was used with decode, was not really required?

Copy link
Contributor Author

@ianwallen ianwallen Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old logic did not make any sense to me.

It was using the requestUrl and then subtracting the apiDocsUrl which has no relationship to the current url.
i.e.
requestUrl was http://localhost:8080/geonetwork/srv/api/doc
apiDocsUrl was based on @value(API_DOCS_URL) which was "/v3/api-docs"

It was subtracting the length of "/v3/api-docs" which just happened to be the same length as "/srv/api/doc" which was just luck that this did not fail?

It looked to me like it was just trying to get the base URL and content path from the URL. So the new logic achieves that correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianwallen thanks for the clarification. Please update the PR to remove the unused imports, it's all fine for me.

@ianwallen ianwallen merged commit 9285136 into geonetwork:main Jan 3, 2024
6 checks passed
@ianwallen ianwallen deleted the spring_doc_deterministic branch January 3, 2024 14:06
ianwallen added a commit that referenced this pull request Jan 3, 2024
…terministic. (#7574)

* Update SpringDoc json/yaml generator to make the results more deterministic.
This will make it easier to compare different versions between gn releases.

These are the properties that were enabled.

   springdoc.writer-with-order-by-keys=true
   springdoc.writer-with-default-pretty-printer=true

* Cleanup imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants