-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/gradle plugin 0 7 0 #54
base: main
Are you sure you want to change the base?
Feature/gradle plugin 0 7 0 #54
Conversation
…pshot.ts pass and fail valid/invalid schemas as expected.
…ividually as a replacement into the valid record.
…absent from the generated schema.
|
||
// Skip processing | ||
private boolean skip = false; | ||
private List<String> optionalAnnotations = Collections.emptyList(); |
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 love to find a way that we can share the definition of accepted parameters between this and the Maven plugin. Will Gradle allow these configuration parameters to be public? I think if that is the case, these could both extend an abstract class with all of the public properties, commented for Gradle, and annotated for Maven. See the Maven mojo: https://github.com/ivangreene/java-to-zod/blob/main/java-to-zod-maven-plugin/src/main/java/sh/ivan/zod/GenerateZodSchemasMojo.java
parameters.isClassNameExcluded = settings.getExcludeFilter(); | ||
parameters.classLoader = classLoader; | ||
parameters.scanningAcceptedPackages = scanningAcceptedPackages; | ||
parameters.debug = loggingLevel == Logger.Level.Debug; |
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.
And we can probably share all of this config/setup once we have an abstract class for all the params
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, dateOfBirth, fName, lName); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) return true; | ||
if (obj == null || obj.getClass() != this.getClass()) return false; | ||
var that = (TestPersonClass) obj; | ||
return Objects.equals(this.id, that.id) && | ||
Objects.equals(this.dateOfBirth, that.dateOfBirth) && | ||
Objects.equals(this.fName, that.fName) && | ||
Objects.equals(this.lName, that.lName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "(" + | ||
"party_id = " + id + ", " + | ||
"dateOfBirth = " + dateOfBirth + ", " + | ||
"fName = " + fName + ", " + | ||
"lName = " + lName + ")"; | ||
} | ||
|
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.
Please use Lombok for this
We'll also want to publish the Gradle plugin to Maven central. Here's an answer that has a bit of info about that: https://stackoverflow.com/questions/67393965/gradle-how-to-publish-a-gradle-plugin-to-maven-central Regarding the JS tests. I think we should create a new submodule that is POJOs to share between the two plugin-testing modules. We run generate on those with the different plugins, and exec the JS tests against that. That way, we have the exact same coverage of both plugins, and no extra code. Thoughts? |
Yes agreed about param sharing... I would normally prefer to use a delegate
field rather than extending an abstract for Maven/Gradle, but in this
instance I think that would make it significantly more verbose to achieve
the same injection API?
Agree also about keeping a single shared POJO set for all implementation
tests. It was quicker for me here to just build a Gradle test suite from
scratch with the cases I immediately had in mind, but yes moving towards
one shared pool of POJOs would be better.
How did you set up the JS tests? Did you generate the static set of schemas
using the plugin, then build the Jest tests around them? I was trying to
find a way that the entire suite would run E2E: build classes -> generate
schemas -> test by validating with zod. However, I couldn't get the node.js
stage to work directly from gradle, hence leaving as 1) a test that
confirms the snapshot matches, 2) a test that confirms the snapshot works
with zod.
Will
…On Sun, 29 Sept 2024, 20:56 Ivan Greene, ***@***.***> wrote:
We'll also want to publish the Gradle plugin to Maven central. Here's an
answer that has a bit of info about that:
https://stackoverflow.com/questions/67393965/gradle-how-to-publish-a-gradle-plugin-to-maven-central
Regarding the JS tests. I think we should create a new submodule that is
POJOs to share between the two plugin-testing modules. We run generate on
those with the different plugins, and exec the JS tests against that. That
way, we have the exact same coverage of both plugins, and no extra code.
Thoughts?
—
Reply to this email directly, view it on GitHub
<#54 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BBL2M6MFFQTVIHZU45ZUMYLZZBLQNAVCNFSM6AAAAABPBYAQEGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBRGU4DENZZG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
I've gone back over the Gradle plugin implementation and stripped it down to just this:
I think this is about the minimum that is feasible, because in order to leverage the Gradle API certain things have to be directly in this class. This still passes all the tests though, so it's functionally equivalent to my previous iteration. I need to test tomorrow (Monday) whether the same approach could be applied to Maven. I don't see any reason why it wouldn't - it uses different annotations and also supports nested params. The main drawback is that this may be a breaking change in that all the settings have been push one level deeper, so in Gradle:
Instead of:
I tried a couple of other approaches, but this looks like the only way we could re-use the same parameters object across both Maven and Gradle. FWIW, the TypescriptGenerator code actually seems to verbosely duplicate the exact code for the Maven/Gradle versions, without any shared intermediary. I don't know whether the author used a generative approach for this, or simply accepted that as the cost of supporting both platforms identically. IMO, a documented breaking change like this in order to simplify the design, and make it more maintainable long-term, is an acceptable outcome, but I don't know how many people already use your package? Is there a way the Maven plugin could flatten the parameters while still using the shared internal class? (I.e. keep the same API but refactor the code.) |
I've applied the same approach to the Maven plugin and that also works, with the proviso that all the parameters apart from outputFile need wrapping in an additional tag:
I don't think there's any other way to use the same code across both plugins, because they both need to extend the abstract class of the plugin's API package. They are happy to co-annotate the same delegate though, so that is the point where they intersect. The PluginParameters object itself I put in the core module, so that neither plugin is depending on the other - they both already depend on the core module. The final complication is that the Gradle Api isn't itself on Maven Central, so the simplest way to supply it to the Maven build (for the core module) was to use an environment variable pointed directly at the jar in my local machine's Gradle cache:
This was a fiddly solution to put together, but I think it's a good one, because both plugins are now very lean, and all the parameters are shared apart from the outputFile, which depends on the surrounding build tool context.
|
The main thing missing is that I haven't added the tests to your existing pipeline, as I wasn't sure how to do that part. I.e. there is a manual Gradle test, and manual Jest test, which both pass and cover the core behaviour of the Gradle plugin, matching the Maven plugin.
I used a very small test sample, as I thought it seemed unnecessarily redundant to perform all the battery of tests as the Maven plugin. The JavaToZod core is the same, so there shouldn't be any divergence in the behaviour. This seemed better than bloating the Gradle test with repetition.