Add validate Mojo to Maven Plugin#23911
Open
verhasi wants to merge 4 commits into
Open
Conversation
…ion with the Maven plugin Add validation harness both unit and integration tests for the 'validate' goal
Contributor
There was a problem hiding this comment.
2 issues found across 26 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
added 2 commits
June 1, 2026 09:38
… ordering in ValidateMojo to fix "Skip flags are checked too late; input validation should come after the skip check." issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a new
validateMojo to theopenapi-generator-maven-plugin.Historically, validating an OpenAPI specification within a Maven workflow required running the full
generategoal, or relying on external plugins. As teams move toward centralized "API Contract" design modules (where specs are bundled without immediate code generation), there is a critical need to validate these descriptors independently and efficiently.This new goal isolates the modern, rule-based
OpenApiEvaluatorlogic (extracted from the CLI'svalidatecommand) and wraps it in a lightweight Maven lifecycle component.The README of the
openapi-generator-maven-pluginhas been updated accordingly.Key Changes
New Mojo (
ValidateMojo.java): Added thevalidategoal bound by default to the validate lifecycle phase.Modern Rule Evaluation: Leverages
OpenApiEvaluatorandRuleConfigurationto execute deep structural and semantic spec validation.Fail-Fast Engine: Configured to fail the build immediately with actionable error logs if the spec violates OpenAPI specifications, while remaining silent and non-blocking on soft recommendations.
m2e Integration: Updated
lifecycle-mapping-metadata.xmlto ensure Eclipse/m2e environments can seamlessly run incremental validation on workspace file changes.Configuration & Usage
Single File Validation (Standard)
For validating a single targeted OpenAPI specification file:
Bulk Validation & Directory Aggregation (Future-Proofing)
inputSpecRootDirectory) that automatically aggregates and iterates through all discovered OpenAPI specification documents within a target folder, perfectly mirroring how the existinggenerategoal handles directory inputs.generategoal currently handlesinputSpec.validategoal can natively scale to support modular, split-spec environments and multi-API repositories without requiring separate execution blocks for every file. Crucially, this allows users to capture all validation issues across their entire spec ecosystem in a single pass, completely eliminating the need to fix errors one-by-one through repeated, slow Maven iterations.Technical Benefits
Fail-Fast CI/CD: Shifts API validation to the very beginning of the build sequence. Broken specs halt the pipeline in seconds rather than waiting minutes for downstream code generation or compilation failures.
Resource Optimization: No unnecessary I/O file writing or code generation steps are performed when a user only wants to sanity-check a contract change.
Verification Results
Tested locally against a suite of valid OpenAPI 3.0.x/3.1.x schemas (Build passes successfully).
Tested against intentionally malformed/invalid specs (Build accurately throws
MojoFailureExceptionand outputs specific syntax/structural errors cleanly to the console logs).PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds a new
validategoal to theopenapi-generator-maven-pluginto validate OpenAPI specs early in the Maven lifecycle without generating code. It uses the rule-based engine, fails the build on errors, and now correctly handles skip checks and m2e integration.New Features
ValidateMojobound tovalidate; runsOpenApiEvaluatorwithRuleConfiguration(fail-fast on errors; recommendations are non-blocking).inputSpec, XML list, comma-separated CLI override, andinputSpecRootDirectoryscan.Bug Fixes
validategoal to m2e lifecycle mapping.ValidateMojoexecution so skip flags are checked before input validation.Written for commit 5629dd3. Summary will update on new commits.