Skip to content

Commit 5cdc493

Browse files
verhasiistvan.verhas
andauthored
Add validate Mojo to Maven Plugin (#23911)
* Add ValidateMojo as a new target to enable OpenAPI definition validation with the Maven plugin Add validation harness both unit and integration tests for the 'validate' goal * Add missing 'validate' goal to lifecycle mapping and refine execution ordering in ValidateMojo to fix "Skip flags are checked too late; input validation should come after the skip check." issue --------- Co-authored-by: istvan.verhas <istvan.verhas@meta-inf.hu>
1 parent 719aaed commit 5cdc493

27 files changed

Lines changed: 1330 additions & 73 deletions

File tree

modules/openapi-generator-maven-plugin/README.md

Lines changed: 135 additions & 72 deletions
Large diffs are not rendered by default.

modules/openapi-generator-maven-plugin/pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<version>${maven.version}</version>
3131
<scope>provided</scope>
3232
</dependency>
33+
<dependency>
34+
<groupId>org.apache.maven.shared</groupId>
35+
<artifactId>maven-shared-utils</artifactId>
36+
<version>3.3.4</version>
37+
</dependency>
3338
<dependency>
3439
<groupId>org.apache.maven</groupId>
3540
<artifactId>maven-artifact</artifactId>
@@ -102,7 +107,12 @@
102107
<version>4.8.0</version>
103108
<scope>test</scope>
104109
</dependency>
105-
110+
<dependency>
111+
<groupId>org.mockito</groupId>
112+
<artifactId>mockito-core</artifactId>
113+
<version>${mockito.version}</version>
114+
<scope>test</scope>
115+
</dependency>
106116
</dependencies>
107117
<build>
108118
<pluginManagement>
@@ -174,6 +184,10 @@
174184
<failIfNoProjects>true</failIfNoProjects>
175185
<postBuildHookScript>verify</postBuildHookScript>
176186
<streamLogsOnFailures>true</streamLogsOnFailures>
187+
<pomIncludes>
188+
<pomInclude>*/pom.xml</pomInclude>
189+
<pomInclude>validate-harness/*/pom.xml</pomInclude>
190+
</pomIncludes>
177191
</configuration>
178192
<dependencies>
179193
<dependency>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
invoker.goals = validate
2+
invoker.systemProperties = openapi.generator.inputSpec=valid_api.yaml,unused_model_api.yaml
3+
invoker.buildResult = success
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.openapitools.it</groupId>
6+
<artifactId>cli-comma-separated-override</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>org.openapitools</groupId>
12+
<artifactId>openapi-generator-maven-plugin</artifactId>
13+
<version>@project.version@</version>
14+
</plugin>
15+
</plugins>
16+
</build>
17+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
openapi: 3.0.3
2+
info:
3+
title: API with Style Recommendations
4+
version: 1.0.0
5+
description: Valid spec syntax, but contains an isolated component model that triggers an unused schema warning.
6+
paths:
7+
/users:
8+
get:
9+
summary: Get active users
10+
operationId: getUsers
11+
responses:
12+
'200':
13+
description: Success
14+
content:
15+
application/json:
16+
schema:
17+
type: array
18+
items:
19+
type: string
20+
components:
21+
schemas:
22+
UnusedModel:
23+
type: object
24+
properties:
25+
legacyField:
26+
type: integer
27+
description: This model is declared but never referenced anywhere in any operation or path parameter.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Healthy Test API
4+
version: 1.0.0
5+
description: A completely valid specification with no errors or recommendations.
6+
paths:
7+
/ping:
8+
get:
9+
summary: Simple healthcheck endpoint
10+
operationId: pingCheck
11+
responses:
12+
'200':
13+
description: Server is operational
14+
content:
15+
application/json:
16+
schema:
17+
$ref: '#/components/schemas/Pong'
18+
components:
19+
schemas:
20+
Pong:
21+
type: object
22+
properties:
23+
status:
24+
type: string
25+
example: healthy
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = validate
2+
invoker.buildResult = success
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.openapitools.it</groupId>
6+
<artifactId>input-directory-merge</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<build>
9+
<plugins>
10+
<plugin>
11+
<groupId>org.openapitools</groupId>
12+
<artifactId>openapi-generator-maven-plugin</artifactId>
13+
<version>@project.version@</version>
14+
<executions>
15+
<execution>
16+
<phase>validate</phase>
17+
<goals>
18+
<goal>validate</goal>
19+
</goals>
20+
<configuration>
21+
<inputSpecRootDirectory>${project.basedir}/specs</inputSpecRootDirectory>
22+
</configuration>
23+
</execution>
24+
</executions>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Part 1
4+
version: 1.0.0
5+
paths:
6+
/part1:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Part 2
4+
version: 1.0.0
5+
paths:
6+
/part2:
7+
get:
8+
responses:
9+
'200':
10+
description: OK

0 commit comments

Comments
 (0)