-
Notifications
You must be signed in to change notification settings - Fork 545
RESTWS-980: Initial implementation of OpenAPI Generator Maven Plugin with JavaParser integration #657
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
base: master
Are you sure you want to change the base?
Conversation
|
||
<groupId>org.openmrs.plugin</groupId> | ||
<artifactId>openapi-generator-maven-plugin</artifactId> | ||
<version>1.0-SNAPSHOT</version> |
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.
@capernix i know this is still in draft but have a look at how versioning is done in OpenMRS, -> https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477712/Versioning
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'll take a look thanks
About the Commit: Enhanced the Plugin to invoke the required function and parse representations Created a Maven Plugin that currently sets up the URLClassLoader, tests if Rest Constants are accessible, loads the specific resources and invokes getRepresentationDescription() to gather all the properties of the resource. |
@Parameter(defaultValue = "${project}", required = true, readonly = true) | ||
private MavenProject project; @Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
getLog().info("=== OPENAPI GENERATION STARTED ==="); |
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 would prefer you declaring something like private static final Logger logger = LoggerFactory.getLogger(OpenAPIMojo.class);
and replace this line with something like logger.info(.....);
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.
Do the same for all your logging needs
tools/openapi-generator-maven-plugin/src/main/java/org/openmrs/plugin/OpenAPIMojo.java
Outdated
Show resolved
Hide resolved
omod-1.8/pom.xml
Outdated
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<configuration> | ||
<artifactId>license-maven-plugin</artifactId> <configuration> |
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 this change part of your plugin implementation?
omod-1.8/pom.xml
Outdated
<plugin> | ||
<groupId>org.openmrs.plugin</groupId> | ||
<artifactId>openapi-generator-maven-plugin</artifactId> | ||
<version>1.0-SNAPSHOT</version> |
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.
This versioning doesnt match openmrs' style of versioning, look at https://openmrs.atlassian.net/wiki/spaces/docs/pages/25477712/Versioning
...a/org/openmrs/module/webservices/rest/web/v1_0/controller/SchemaIntrospectionController.java
Outdated
Show resolved
Hide resolved
|
||
<dependencies> | ||
<!-- Maven Plugin API --> | ||
<dependency> |
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 see classLoader.loadClass
used quite a bit to load classes from the rest module. Does it make sense to just make it a dependency so we can use those classes directly?
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'll try this out and get back
} | ||
|
||
} catch (Exception e) { | ||
getLog().error("Method invocation failed: " + e.getMessage()); |
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.
Avoid this catch-and-log pattern. It hides the stack trace. If the error is unrecoverable, just let it be thrown without catching.
Also, try to avoid catching Exception
, as it is too general. You might mask genuine coding errors like IndexOutOfBoundsException
.
Class<?> resourceClazz = loadClass(TARGET_CLASS_NAME); | ||
|
||
// Test PatientResource instance creation | ||
testPatientResourceInstantiation(resourceClazz); |
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.
Are we ready to make this work for all Resources classes?
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.
According to my observations and testing, almost all of the resource files are working perfectly.
But an exception I found was ConceptResource1_8 that has it's full representation in a different method than getRepresentationDescription(), and it has additional representations such as fullchildren which I am working on to be taken into consideration.
…ntations # Conflicts: # omod-1.8/pom.xml
…rsioning number, removed unnecessary comments
…ved all general Exception handling
582488f
to
afd8d00
Compare
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.
@capernix , have you seen the build failure. Can you investigate it?
...a/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java
Show resolved
Hide resolved
import java.util.Map; | ||
|
||
@Mojo(name = "openapi", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.RUNTIME) | ||
public class OpenAPIMojo extends AbstractMojo { |
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.
public class OpenAPIMojo extends AbstractMojo { | |
public class OpenmrsOpenApiSpecMojo extends AbstractMojo { |
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 name makes more sense
return new URLClassLoader(urls.toArray(new URL[0]), Thread.currentThread().getContextClassLoader()); | ||
|
||
} catch (java.net.MalformedURLException e) { | ||
throw new RuntimeException("Invalid URL in classpath elements: " + e.getMessage(), e); |
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.
shouldn't we prefer throwing MojoExecutionException
or MojoFailureException
for plugin errors, as Maven will display these more clearly?
Description of what I changed
Introduced a new OpenAPI Generator Maven Plugin that integrates JavaParser to extract Javadoc from OpenMRS REST resource classes. This initial implementation serves as a proof-of-concept for enhancing OpenAPI documentation with descriptive information from source code.
Key Implementation Details:
PatientResource1_8
classunpack-dependencies
goal fromgenerate-resources
toprepare-package
phaseThis implementation provides the foundation for programmatically enhancing API documentation by leveraging the existing Javadoc in the codebase.
PS: I also pushed the code for the schema introspector alongside so the work can be combined in future commits.
Issue I worked on
https://openmrs.atlassian.net/browse/RESTWS-980
Checklist: I completed these to help reviewers :)
[
x
] My IDE is configured to follow the code style of this project.No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
[] I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
[
x
] I ranmvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
[
x
] All new and existing tests passed.No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
[
x
] My pull request is based on the latest changes of the master branch.No? Unsure? -> execute command
git pull --rebase upstream master