Skip to content

Commit 1602942

Browse files
authored
[Wsdl] Adding cli-option for generating different versions of WSDL-files regarding Media type versioning (content negotiation) (#12206)
* add wsdl version generation * add option to use specified operationId * update samples * update cli description
1 parent 5b6b4c9 commit 1602942

File tree

43 files changed

+454
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+454
-346
lines changed

docs/generators/fsharp-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3434
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
3535
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3636
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
37-
|sourceFolder|source folder for generated code| |OpenAPI/src|
37+
|sourceFolder|source folder for generated code| |OpenAPI\src|
3838

3939
## IMPORT MAPPING
4040

docs/generators/fsharp-giraffe-server.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3030
|packageVersion|F# package version.| |1.0.0|
3131
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
3232
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
33-
|sourceFolder|source folder for generated code| |OpenAPI/src|
33+
|sourceFolder|source folder for generated code| |OpenAPI\src|
3434
|useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false|
3535
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
3636
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |false|

docs/generators/java-inflector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
6161
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|null|
6262
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
6363
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
64-
|sourceFolder|source folder for generated code| |src/gen/java|
64+
|sourceFolder|source folder for generated code| |src\gen\java|
6565
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
6666
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
6767

docs/generators/jaxrs-cxf-client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
6161
|snapshotVersion|Uses a SNAPSHOT version.|<dl><dt>**true**</dt><dd>Use a SnapShot Version</dd><dt>**false**</dt><dd>Use a Release Version</dd></dl>|null|
6262
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
6363
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
64-
|sourceFolder|source folder for generated code| |src/gen/java|
64+
|sourceFolder|source folder for generated code| |src\gen\java|
6565
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
6666
|useBeanValidation|Use BeanValidation API annotations| |false|
6767
|useGenericResponse|Use generic response| |false|

docs/generators/swift5.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4949
|responseAs|Optionally use libraries to manage response. Currently PromiseKit, RxSwift, Result, Combine, AsyncAwait are available.| |null|
5050
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
5151
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
52-
|swiftPackagePath|Set a custom source path instead of OpenAPIClient/Classes/OpenAPIs.| |null|
52+
|swiftPackagePath|Set a custom source path instead of OpenAPIClient\Classes\OpenAPIs.| |null|
5353
|swiftUseApiNamespace|Flag to make all the API classes inner-class of {{projectName}}API| |null|
5454
|useBacktickEscapes|Escape reserved words using backticks (default: false)| |false|
5555
|useClasses|Use final classes for models instead of structs (default: false)| |false|
56-
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: false).| |null|
56+
|useSPMFileStructure|Use SPM file structure and set the source path to Sources\{{projectName}} (default: false).| |null|
5757

5858
## IMPORT MAPPING
5959

docs/generators/wsdl-schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
22+
|contentTypeVersion|generate WSDL with parameters/responses of the specified content-type| |null|
2223
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
2324
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
2425
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
@@ -29,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2930
|soapPath|basepath of the soap services| |null|
3031
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3132
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
33+
|useSpecifiedOperationId|wheather to use autogenerated operationId's (default)or those specified in openapi spec| |false|
3234

3335
## IMPORT MAPPING
3436

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

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
public class WsdlSchemaCodegen extends DefaultCodegen implements CodegenConfig {
3333
public static final String PROJECT_NAME = "projectName";
3434

35+
protected String contentTypeVersion = null;
36+
37+
protected boolean useSpecifiedOperationId = false;
38+
3539
public CodegenType getTag() {
3640
return CodegenType.SCHEMA;
3741
}
@@ -59,6 +63,11 @@ public WsdlSchemaCodegen() {
5963
cliOptions.add(new CliOption("hostname", "the hostname of the service"));
6064
cliOptions.add(new CliOption("soapPath", "basepath of the soap services"));
6165
cliOptions.add(new CliOption("serviceName", "service name for the wsdl"));
66+
cliOptions.add(new CliOption("contentTypeVersion",
67+
"generate WSDL with parameters/responses of the specified content-type"));
68+
cliOptions.add(new CliOption("useSpecifiedOperationId",
69+
"wheather to use autogenerated operationId's (default) "
70+
+ "or those specified in openapi spec"));
6271

6372
additionalProperties.put("hostname", "localhost");
6473
additionalProperties.put("soapPath", "soap");
@@ -79,6 +88,17 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
7988
info.setTitle(this.escapeTitle(title));
8089
}
8190

91+
@Override
92+
public void processOpts() {
93+
if (additionalProperties.containsKey("contentTypeVersion")) {
94+
this.setContentTypeVersion((String) additionalProperties.get("contentTypeVersion"));
95+
}
96+
if (additionalProperties.containsKey("useSpecifiedOperationId")) {
97+
this.setUseSpecifiedOperationId(
98+
Boolean.parseBoolean(additionalProperties.get("useSpecifiedOperationId").toString()));
99+
}
100+
}
101+
82102
private String escapeTitle(String title) {
83103
// strip umlauts etc.
84104
final String normalizedTitle = Normalizer.normalize(title, Normalizer.Form.NFD)
@@ -93,12 +113,87 @@ public String processOpenapiSpecDescription(String description) {
93113
return "No description provided";
94114
}
95115
}
96-
116+
97117
@Override
98118
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
99119
for (CodegenOperation op : objs.getOperations().getOperation()) {
100-
op.operationId = this.generateOperationId(op);
120+
// depending on the specified content type generate WSDL of this version
121+
if (this.contentTypeVersion != null) {
122+
List<String> unusedModels = new ArrayList<String>();
123+
124+
// use content type data to change dataType/baseType variable depending on specified version
125+
for (CodegenParameter codegenParameter : op.allParams) {
126+
if (codegenParameter.isBodyParam) {
127+
for (Map.Entry<String, CodegenMediaType> ite1
128+
: codegenParameter.getContent().entrySet()) {
129+
// only if specified content-type was found inside content variable
130+
if (ite1.getKey().startsWith(this.contentTypeVersion)) {
131+
if (codegenParameter.isArray) {
132+
codegenParameter.baseType =
133+
ite1.getValue().getSchema().getItems().getBaseType();
134+
} else {
135+
codegenParameter.dataType =
136+
ite1.getValue().getSchema().getDataType();
137+
}
138+
// mark unused models of other versions for removal
139+
for (Map.Entry<String, CodegenMediaType> ite2
140+
: codegenParameter.getContent().entrySet()) {
141+
if (!ite2.getKey().startsWith(this.contentTypeVersion)) {
142+
if (codegenParameter.isArray) {
143+
unusedModels.add(ite2.getValue().getSchema().getItems().getBaseType());
144+
} else {
145+
unusedModels.add(ite2.getValue().getSchema().getDataType());
146+
}
147+
}
148+
}
149+
break;
150+
}
151+
}
152+
}
153+
}
154+
155+
// same approach for responses
156+
for (CodegenResponse codegenResponse : op.responses) {
157+
if (codegenResponse.getContent() != null) {
158+
for (Map.Entry<String, CodegenMediaType> ite1
159+
: codegenResponse.getContent().entrySet()) {
160+
if (ite1.getKey().startsWith(this.contentTypeVersion)
161+
&& codegenResponse.is2xx) {
162+
if (codegenResponse.isArray) {
163+
codegenResponse.baseType =
164+
ite1.getValue().getSchema().getItems().getBaseType();
165+
} else {
166+
codegenResponse.dataType =
167+
ite1.getValue().getSchema().getDataType();
168+
}
169+
for (Map.Entry<String, CodegenMediaType> ite2
170+
: codegenResponse.getContent().entrySet()) {
171+
if (!ite2.getKey().startsWith(this.contentTypeVersion)
172+
&& codegenResponse.is2xx) {
173+
if (codegenResponse.isArray) {
174+
unusedModels.add(ite2.getValue().getSchema().getItems().getBaseType());
175+
} else {
176+
unusedModels.add(ite2.getValue().getSchema().getDataType());
177+
}
178+
}
179+
}
180+
break;
181+
}
182+
}
183+
}
184+
}
101185

186+
// remove models which are used by other versions than the specified one
187+
for (String unusedModelName : unusedModels) {
188+
allModels.removeIf(modelMap ->
189+
(modelMap.getModel().getClassname().equals(unusedModelName)));
190+
}
191+
}
192+
193+
if (!useSpecifiedOperationId) {
194+
op.operationId = this.generateOperationId(op);
195+
}
196+
102197
// for xml compliant primitives, lowercase dataType of openapi
103198
for (CodegenParameter param : op.allParams) {
104199
Map<String, Object> paramVendorExtensions = param.vendorExtensions;
@@ -277,6 +372,16 @@ public String escapeUnsafeCharacters(String input) {
277372
return input;
278373
}
279374

375+
public void setContentTypeVersion(String contentTypeVersion) {
376+
this.contentTypeVersion = contentTypeVersion;
377+
}
378+
379+
public void setUseSpecifiedOperationId(boolean useSpecifiedOperationId) {
380+
this.useSpecifiedOperationId = useSpecifiedOperationId;
381+
}
382+
280383
@Override
281-
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.WSDL; }
384+
public GeneratorLanguage generatorLanguage() {
385+
return GeneratorLanguage.WSDL;
386+
}
282387
}

samples/client/petstore/R/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.travis.yml
44
DESCRIPTION
55
NAMESPACE
6+
README.md
67
R/api_client.R
78
R/api_response.R
89
R/category.R
@@ -14,7 +15,6 @@ R/store_api.R
1415
R/tag.R
1516
R/user.R
1617
R/user_api.R
17-
README.md
1818
docs/Category.md
1919
docs/ModelApiResponse.md
2020
docs/Order.md

samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ docs/Model/SpecialModelName.md
5959
docs/Model/Tag.md
6060
docs/Model/User.md
6161
git_push.sh
62+
lib/ApiException.php
6263
lib/Api/AnotherFakeApi.php
6364
lib/Api/DefaultApi.php
6465
lib/Api/FakeApi.php
6566
lib/Api/FakeClassnameTags123Api.php
6667
lib/Api/PetApi.php
6768
lib/Api/StoreApi.php
6869
lib/Api/UserApi.php
69-
lib/ApiException.php
7070
lib/Configuration.php
7171
lib/HeaderSelector.php
7272
lib/Model/AdditionalPropertiesClass.php

samples/client/petstore/php/OpenAPIClient-php/phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
33
<coverage processUncoveredFiles="true">
44
<include>
5-
<directory suffix=".php">./lib/Api</directory>
6-
<directory suffix=".php">./lib/Model</directory>
5+
<directory suffix=".php">./lib\/Api</directory>
6+
<directory suffix=".php">./lib\/Model</directory>
77
</include>
88
</coverage>
99
<testsuites>

0 commit comments

Comments
 (0)