Skip to content

Commit

Permalink
[Wsdl] Adding cli-option for generating different versions of WSDL-fi…
Browse files Browse the repository at this point in the history
…les regarding Media type versioning (content negotiation) (OpenAPITools#12206)

* add wsdl version generation

* add option to use specified operationId

* update samples

* update cli description
  • Loading branch information
adessoDpd authored and rk0n committed Apr 24, 2022
1 parent f41e756 commit cce98b8
Show file tree
Hide file tree
Showing 43 changed files with 454 additions and 346 deletions.
2 changes: 1 addition & 1 deletion docs/generators/fsharp-functions.md
Expand Up @@ -34,7 +34,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |OpenAPI/src|
|sourceFolder|source folder for generated code| |OpenAPI\src|

## IMPORT MAPPING

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/fsharp-giraffe-server.md
Expand Up @@ -30,7 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageVersion|F# package version.| |1.0.0|
|returnICollection|Return ICollection<T> instead of the concrete type.| |false|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |OpenAPI/src|
|sourceFolder|source folder for generated code| |OpenAPI\src|
|useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false|
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|
|useSwashbuckle|Uses the Swashbuckle.AspNetCore NuGet package for documentation.| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/java-inflector.md
Expand Up @@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|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|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/gen/java|
|sourceFolder|source folder for generated code| |src\gen\java|
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|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|

Expand Down
2 changes: 1 addition & 1 deletion docs/generators/jaxrs-cxf-client.md
Expand Up @@ -61,7 +61,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|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|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src/gen/java|
|sourceFolder|source folder for generated code| |src\gen\java|
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
|useBeanValidation|Use BeanValidation API annotations| |false|
|useGenericResponse|Use generic response| |false|
Expand Down
4 changes: 2 additions & 2 deletions docs/generators/swift5.md
Expand Up @@ -49,11 +49,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|responseAs|Optionally use libraries to manage response. Currently PromiseKit, RxSwift, Result, Combine, AsyncAwait are available.| |null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|swiftPackagePath|Set a custom source path instead of OpenAPIClient/Classes/OpenAPIs.| |null|
|swiftPackagePath|Set a custom source path instead of OpenAPIClient\Classes\OpenAPIs.| |null|
|swiftUseApiNamespace|Flag to make all the API classes inner-class of {{projectName}}API| |null|
|useBacktickEscapes|Escape reserved words using backticks (default: false)| |false|
|useClasses|Use final classes for models instead of structs (default: false)| |false|
|useSPMFileStructure|Use SPM file structure and set the source path to Sources/{{projectName}} (default: false).| |null|
|useSPMFileStructure|Use SPM file structure and set the source path to Sources\{{projectName}} (default: false).| |null|

## IMPORT MAPPING

Expand Down
2 changes: 2 additions & 0 deletions docs/generators/wsdl-schema.md
Expand Up @@ -19,6 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|contentTypeVersion|generate WSDL with parameters/responses of the specified content-type| |null|
|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|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|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|
Expand All @@ -29,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|soapPath|basepath of the soap services| |null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|useSpecifiedOperationId|wheather to use autogenerated operationId's (default)or those specified in openapi spec| |false|

## IMPORT MAPPING

Expand Down
Expand Up @@ -32,6 +32,10 @@
public class WsdlSchemaCodegen extends DefaultCodegen implements CodegenConfig {
public static final String PROJECT_NAME = "projectName";

protected String contentTypeVersion = null;

protected boolean useSpecifiedOperationId = false;

public CodegenType getTag() {
return CodegenType.SCHEMA;
}
Expand Down Expand Up @@ -59,6 +63,11 @@ public WsdlSchemaCodegen() {
cliOptions.add(new CliOption("hostname", "the hostname of the service"));
cliOptions.add(new CliOption("soapPath", "basepath of the soap services"));
cliOptions.add(new CliOption("serviceName", "service name for the wsdl"));
cliOptions.add(new CliOption("contentTypeVersion",
"generate WSDL with parameters/responses of the specified content-type"));
cliOptions.add(new CliOption("useSpecifiedOperationId",
"wheather to use autogenerated operationId's (default) "
+ "or those specified in openapi spec"));

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

@Override
public void processOpts() {
if (additionalProperties.containsKey("contentTypeVersion")) {
this.setContentTypeVersion((String) additionalProperties.get("contentTypeVersion"));
}
if (additionalProperties.containsKey("useSpecifiedOperationId")) {
this.setUseSpecifiedOperationId(
Boolean.parseBoolean(additionalProperties.get("useSpecifiedOperationId").toString()));
}
}

private String escapeTitle(String title) {
// strip umlauts etc.
final String normalizedTitle = Normalizer.normalize(title, Normalizer.Form.NFD)
Expand All @@ -93,12 +113,87 @@ public String processOpenapiSpecDescription(String description) {
return "No description provided";
}
}

@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
for (CodegenOperation op : objs.getOperations().getOperation()) {
op.operationId = this.generateOperationId(op);
// depending on the specified content type generate WSDL of this version
if (this.contentTypeVersion != null) {
List<String> unusedModels = new ArrayList<String>();

// use content type data to change dataType/baseType variable depending on specified version
for (CodegenParameter codegenParameter : op.allParams) {
if (codegenParameter.isBodyParam) {
for (Map.Entry<String, CodegenMediaType> ite1
: codegenParameter.getContent().entrySet()) {
// only if specified content-type was found inside content variable
if (ite1.getKey().startsWith(this.contentTypeVersion)) {
if (codegenParameter.isArray) {
codegenParameter.baseType =
ite1.getValue().getSchema().getItems().getBaseType();
} else {
codegenParameter.dataType =
ite1.getValue().getSchema().getDataType();
}
// mark unused models of other versions for removal
for (Map.Entry<String, CodegenMediaType> ite2
: codegenParameter.getContent().entrySet()) {
if (!ite2.getKey().startsWith(this.contentTypeVersion)) {
if (codegenParameter.isArray) {
unusedModels.add(ite2.getValue().getSchema().getItems().getBaseType());
} else {
unusedModels.add(ite2.getValue().getSchema().getDataType());
}
}
}
break;
}
}
}
}

// same approach for responses
for (CodegenResponse codegenResponse : op.responses) {
if (codegenResponse.getContent() != null) {
for (Map.Entry<String, CodegenMediaType> ite1
: codegenResponse.getContent().entrySet()) {
if (ite1.getKey().startsWith(this.contentTypeVersion)
&& codegenResponse.is2xx) {
if (codegenResponse.isArray) {
codegenResponse.baseType =
ite1.getValue().getSchema().getItems().getBaseType();
} else {
codegenResponse.dataType =
ite1.getValue().getSchema().getDataType();
}
for (Map.Entry<String, CodegenMediaType> ite2
: codegenResponse.getContent().entrySet()) {
if (!ite2.getKey().startsWith(this.contentTypeVersion)
&& codegenResponse.is2xx) {
if (codegenResponse.isArray) {
unusedModels.add(ite2.getValue().getSchema().getItems().getBaseType());
} else {
unusedModels.add(ite2.getValue().getSchema().getDataType());
}
}
}
break;
}
}
}
}

// remove models which are used by other versions than the specified one
for (String unusedModelName : unusedModels) {
allModels.removeIf(modelMap ->
(modelMap.getModel().getClassname().equals(unusedModelName)));
}
}

if (!useSpecifiedOperationId) {
op.operationId = this.generateOperationId(op);
}

// for xml compliant primitives, lowercase dataType of openapi
for (CodegenParameter param : op.allParams) {
Map<String, Object> paramVendorExtensions = param.vendorExtensions;
Expand Down Expand Up @@ -277,6 +372,16 @@ public String escapeUnsafeCharacters(String input) {
return input;
}

public void setContentTypeVersion(String contentTypeVersion) {
this.contentTypeVersion = contentTypeVersion;
}

public void setUseSpecifiedOperationId(boolean useSpecifiedOperationId) {
this.useSpecifiedOperationId = useSpecifiedOperationId;
}

@Override
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.WSDL; }
public GeneratorLanguage generatorLanguage() {
return GeneratorLanguage.WSDL;
}
}
2 changes: 1 addition & 1 deletion samples/client/petstore/R/.openapi-generator/FILES
Expand Up @@ -3,6 +3,7 @@
.travis.yml
DESCRIPTION
NAMESPACE
README.md
R/api_client.R
R/api_response.R
R/category.R
Expand All @@ -14,7 +15,6 @@ R/store_api.R
R/tag.R
R/user.R
R/user_api.R
README.md
docs/Category.md
docs/ModelApiResponse.md
docs/Order.md
Expand Down
Expand Up @@ -59,14 +59,14 @@ docs/Model/SpecialModelName.md
docs/Model/Tag.md
docs/Model/User.md
git_push.sh
lib/ApiException.php
lib/Api/AnotherFakeApi.php
lib/Api/DefaultApi.php
lib/Api/FakeApi.php
lib/Api/FakeClassnameTags123Api.php
lib/Api/PetApi.php
lib/Api/StoreApi.php
lib/Api/UserApi.php
lib/ApiException.php
lib/Configuration.php
lib/HeaderSelector.php
lib/Model/AdditionalPropertiesClass.php
Expand Down
Expand Up @@ -2,8 +2,8 @@
<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">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./lib/Api</directory>
<directory suffix=".php">./lib/Model</directory>
<directory suffix=".php">./lib\/Api</directory>
<directory suffix=".php">./lib\/Model</directory>
</include>
</coverage>
<testsuites>
Expand Down

0 comments on commit cce98b8

Please sign in to comment.