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

Fix initialization of SpringDoc so that it does not use null servername and null version #7575

Merged
merged 2 commits into from
Jan 2, 2024

Conversation

ianwallen
Copy link
Contributor

@ianwallen ianwallen commented Dec 21, 2023

Fix initialization of SpringDoc so that it does not use null servername and null version

Before this fix. The initial deployment of geonetwork in a new database would cause Spring Doc api to look like the following

image

Also if checking the yaml api on https://editor.swagger.io/, we would see the following error because the version was not set.
image

The issue was mostly caused by 2 contexts being used.
JeevesApplicationContext was being loaded first and at that time, the database was not initialized with the data and ended up returning a null servername and null version from the settings manager.

Then it would later initialize WebApplicationContext and this would initialized the correct version. But when going to /doc/api/ it was using the JeevesApplicationContext version which was incorrect.

This fix modified OpenApi object so that it is a static object that is shared with all context. This helped fix initial api setting so that it was not set to null://null:80/geonetwork/srv/api

After this fix, a new installation of geonetwork will show the following:

image

Also as part of this fix, SiteApi was updated so that if the server url is changed then it will update the static OpenApi object without requiring an application restart.

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

…me and null version

Modified OpenApi object so that it is a static object that is shared with all context.  This helped fix initial api setting so that it was not set to null://null:80/geonetwork/srv/api
Also update SiteApi so that if the server properties are changed then it will update the OpenApi object without requiring an application restart.
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.

The only concern is about initialising static fields in a non-static method. Not sure if can lead to any issue in certain cases, or doesn't apply in this case.

Other than that looks solving the issue.

… no static values are changed directly in the bean.
@ianwallen
Copy link
Contributor Author

@josegar74

The only concern is about initialising static fields in a non-static method. Not sure if can lead to any issue in certain cases, or doesn't apply in this case.

I update the code so that the bean called the static method to make the changes.

@fxprunayre fxprunayre merged commit 1068a6c into geonetwork:main Jan 2, 2024
6 checks passed
josegar74 pushed a commit that referenced this pull request Jan 2, 2024
…vername and null version (#7575)

* Fix initialization of SpringDoc so that it does not use null servername and null version
Modified OpenApi object so that it is a static object that is shared with all context.  This helped fix initial api setting so that it was not set to null://null:80/geonetwork/srv/api
Also update SiteApi so that if the server properties are changed then it will update the OpenApi object without requiring an application restart.

* Update OpenAPI bean so that it calls the static method to ensure that no static values are changed directly in the bean.
@ianwallen ianwallen deleted the springdoc_initilization_fix branch January 2, 2024 11:04
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.

3 participants