Skip to content

Commit 0babc5d

Browse files
mwoodlandwing328
authored andcommitted
Allow specifying/overriding the parent in the pom file for Java and S… (OpenAPITools#1132)
* Allow specifying/overriding the parent in the pom file for Java and Spring generators. * Don't add extra whitespace to the pom file when the parent isn't overridden. * Remove accidentally added white space.
1 parent dfe3cfc commit 0babc5d

File tree

19 files changed

+174
-0
lines changed

19 files changed

+174
-0
lines changed

docs/generators/java.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ CONFIG OPTIONS for java
104104
booleanGetterPrefix
105105
Set booleanGetterPrefix (default value 'get')
106106

107+
parentGroupId
108+
parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
109+
110+
parentArtifactId
111+
parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
112+
113+
parentVersion
114+
parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
115+
107116
useRxJava
108117
Whether to use the RxJava adapter with the retrofit2 library. (Default: false)
109118

docs/generators/spring.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ CONFIG OPTIONS for spring
104104
booleanGetterPrefix
105105
Set booleanGetterPrefix (default value 'get')
106106

107+
parentGroupId
108+
parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
109+
110+
parentArtifactId
111+
parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
112+
113+
parentVersion
114+
parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect
115+
107116
title
108117
server title name or client service name
109118

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,12 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
265265
public static final String DATABASE_ADAPTER = "databaseAdapter";
266266
public static final String DATABASE_ADAPTER_DESC = "The adapter for database (e.g. mysql, sqlite). Default: sqlite";
267267

268+
public static final String PARENT_GROUP_ID = "parentGroupId";
269+
public static final String PARENT_GROUP_ID_DESC = "parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect";
270+
271+
public static final String PARENT_ARTIFACT_ID = "parentArtifactId";
272+
public static final String PARENT_ARTIFACT_ID_DESC = "parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect";
273+
274+
public static final String PARENT_VERSION = "parentVersion";
275+
public static final String PARENT_VERSION_DESC = "parent version in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect";
268276
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
105105
protected boolean disableHtmlEscaping = false;
106106
protected String booleanGetterPrefix = BOOLEAN_GETTER_PREFIX_DEFAULT;
107107
protected boolean useNullForUnknownEnumValue = false;
108+
protected String parentGroupId = "";
109+
protected String parentArtifactId = "";
110+
protected String parentVersion = "";
111+
protected boolean parentOverridden = false;
108112

109113
public AbstractJavaCodegen() {
110114
super();
@@ -198,6 +202,10 @@ public AbstractJavaCodegen() {
198202

199203
cliOptions.add(CliOption.newBoolean(DISABLE_HTML_ESCAPING, "Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)"));
200204
cliOptions.add(CliOption.newString(BOOLEAN_GETTER_PREFIX, "Set booleanGetterPrefix (default value '" + BOOLEAN_GETTER_PREFIX_DEFAULT + "')"));
205+
206+
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC));
207+
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC));
208+
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_VERSION, CodegenConstants.PARENT_VERSION_DESC));
201209
}
202210

203211
@Override
@@ -375,6 +383,22 @@ public void processOpts() {
375383
this.setWithXml(Boolean.valueOf(additionalProperties.get(WITH_XML).toString()));
376384
}
377385
additionalProperties.put(WITH_XML, withXml);
386+
387+
if (additionalProperties.containsKey(CodegenConstants.PARENT_GROUP_ID)) {
388+
this.setParentGroupId((String) additionalProperties.get(CodegenConstants.PARENT_GROUP_ID));
389+
}
390+
391+
if (additionalProperties.containsKey(CodegenConstants.PARENT_ARTIFACT_ID)) {
392+
this.setParentArtifactId((String) additionalProperties.get(CodegenConstants.PARENT_ARTIFACT_ID));
393+
}
394+
395+
if (additionalProperties.containsKey(CodegenConstants.PARENT_VERSION)) {
396+
this.setParentVersion((String) additionalProperties.get(CodegenConstants.PARENT_VERSION));
397+
}
398+
399+
if (!StringUtils.isEmpty(parentGroupId) && !StringUtils.isEmpty(parentArtifactId) && !StringUtils.isEmpty(parentVersion)) {
400+
additionalProperties.put("parentOverridden", true);
401+
}
378402

379403
// make api and model doc path available in mustache template
380404
additionalProperties.put("apiDocPath", apiDocPath);
@@ -1358,4 +1382,19 @@ public String sanitizeTag(String tag) {
13581382
return tag;
13591383
}
13601384

1385+
public void setParentGroupId(final String parentGroupId) {
1386+
this.parentGroupId = parentGroupId;
1387+
}
1388+
1389+
public void setParentArtifactId(final String parentArtifactId) {
1390+
this.parentArtifactId = parentArtifactId;
1391+
}
1392+
1393+
public void setParentVersion(final String parentVersion) {
1394+
this.parentVersion = parentVersion;
1395+
}
1396+
1397+
public void setParentOverridden(final boolean parentOverridden) {
1398+
this.parentOverridden = parentOverridden;
1399+
}
13611400
}

modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/google-api-client/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/resteasy/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
<developerConnection>scm:git:[email protected]:openapitools/openapi-generator.git</developerConnection>
1212
<url>https://openapi-generator.tech</url>
1313
</scm>
14+
{{#parentOverridden}}
15+
<parent>
16+
<groupId>{{{parentGroupId}}}</groupId>
17+
<artifactId>{{{parentArtifactId}}}</artifactId>
18+
<version>{{{parentVersion}}}</version>
19+
</parent>
20+
{{/parentOverridden}}
1421

1522
<build>
1623
<plugins>

modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/retrofit/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/retrofit2/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/vertx/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/Java/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
<developerConnection>{{scmDeveloperConnection}}</developerConnection>
1414
<url>{{scmUrl}}</url>
1515
</scm>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
1623

1724
<licenses>
1825
<license>

modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313
<springfox-version>2.8.0</springfox-version>
1414
{{/useSpringfox}}
1515
</properties>
16+
{{#parentOverridden}}
17+
<parent>
18+
<groupId>{{{parentGroupId}}}</groupId>
19+
<artifactId>{{{parentArtifactId}}}</artifactId>
20+
<version>{{{parentVersion}}}</version>
21+
</parent>
22+
{{/parentOverridden}}
23+
{{^parentOverridden}}
1624
<parent>
1725
<groupId>org.springframework.boot</groupId>
1826
<artifactId>spring-boot-starter-parent</artifactId>
1927
<version>{{#java8}}2.0.1.RELEASE{{/java8}}{{^java8}}1.5.12.RELEASE{{/java8}}</version>
2028
</parent>
29+
{{/parentOverridden}}
2130
<build>
2231
<sourceDirectory>src/main/java</sourceDirectory>
2332
{{^interfaceOnly}}

modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,20 @@
1111
<maven.compiler.target>${java.version}</maven.compiler.target>
1212
<swagger-core-version>1.5.18</swagger-core-version>
1313
</properties>
14+
{{#parentOverridden}}
15+
<parent>
16+
<groupId>{{{parentGroupId}}}</groupId>
17+
<artifactId>{{{parentArtifactId}}}</artifactId>
18+
<version>{{{parentVersion}}}</version>
19+
</parent>
20+
{{/parentOverridden}}
21+
{{^parentOverridden}}
1422
<parent>
1523
<groupId>org.springframework.boot</groupId>
1624
<artifactId>spring-boot-starter-parent</artifactId>
1725
<version>1.5.4.RELEASE</version>
1826
</parent>
27+
{{/parentOverridden}}
1928
<build>
2029
<sourceDirectory>src/main/java</sourceDirectory>
2130
</build>

modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-mvc/pom.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<packaging>jar</packaging>
66
<name>{{artifactId}}</name>
77
<version>{{artifactVersion}}</version>
8+
{{#parentOverridden}}
9+
<parent>
10+
<groupId>{{{parentGroupId}}}</groupId>
11+
<artifactId>{{{parentArtifactId}}}</artifactId>
12+
<version>{{{parentVersion}}}</version>
13+
</parent>
14+
{{/parentOverridden}}
815
<build>
916
<sourceDirectory>src/main/java</sourceDirectory>
1017
<plugins>

0 commit comments

Comments
 (0)