Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wsdl] Handle schema property of type array with oneOf items and other minor updates/fixes #10434

Merged
merged 11 commits into from
Sep 21, 2021
2 changes: 1 addition & 1 deletion docs/generators/fsharp-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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|
|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|

## IMPORT MAPPING
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/jaxrs-cxf-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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|
|useBeanValidation|Use BeanValidation API annotations| |false|
|useGenericResponse|Use generic response| |false|
|useGzipFeatureForTests|Use Gzip Feature for tests| |false|
Expand Down
4 changes: 2 additions & 2 deletions docs/generators/swift5.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,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 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Arrays;

public class WsdlSchemaCodegen extends DefaultCodegen implements CodegenConfig {
public static final String PROJECT_NAME = "projectName";
Expand Down Expand Up @@ -128,9 +129,21 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o

// if param is enum, uppercase 'baseName' to have a reference to wsdl simpletype
if (param.isEnum) {
char[] c = param.baseName.toCharArray();
c[0] = Character.toUpperCase(c[0]);
param.baseName = new String(c);
param.baseName = param.baseName.substring(0, 1).toUpperCase(Locale.getDefault())
+ param.baseName.substring(1);
}
}

// handle case lowercase schema-name in openapi to have reference to wsdl complextype
for (CodegenResponse response : op.responses) {
if (response.isModel) {
response.dataType = response.dataType.substring(0, 1).toUpperCase(Locale.getDefault())
+ response.dataType.substring(1);
}

if (response.isArray) {
response.baseType = response.baseType.substring(0, 1).toUpperCase(Locale.getDefault())
+ response.baseType.substring(1);
}
}

Expand Down Expand Up @@ -174,33 +187,19 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> mod = (Map<String, Object>) mo;
CodegenModel model = (CodegenModel) mod.get("model");
Map<String, Object> modelVendorExtensions = model.getVendorExtensions();

/* check if model is a model with no properties
* Used in the mustache template to ensure that no complextype is created
* if model is just a schema with an enum defined in the openapi specification
*/
if (model.allowableValues != null) {
modelVendorExtensions.put("x-is-openapimodel-enum", true);
} else {
modelVendorExtensions.put("x-is-openapimodel-enum", false);
}


for (CodegenProperty var : model.vars) {
Map<String, Object> propertyVendorExtensions = var.getVendorExtensions();

// lowercase basetypes if openapitype is string
if ("string".equals(var.openApiType)) {
char[] c = var.baseType.toCharArray();
c[0] = Character.toLowerCase(c[0]);
var.baseType = new String(c);
var.baseType = var.baseType.substring(0, 1).toLowerCase(Locale.getDefault())
+ var.baseType.substring(1);
}
// if string enum, uppercase 'name' to have a reference to wsdl simpletype
if (var.isEnum) {
char[] c = var.name.toCharArray();
c[0] = Character.toUpperCase(c[0]);
var.name = new String(c);
var.name = var.name.substring(0, 1).toUpperCase(Locale.getDefault()) + var.name.substring(1);
}

// prevent default="null" in wsdl-tag if no default was specified for a property
if ("null".equals(var.defaultValue) || var.defaultValue == null) {
propertyVendorExtensions.put("x-prop-has-defaultvalue", false);
Expand All @@ -217,6 +216,21 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
} else {
propertyVendorExtensions.put("x-prop-has-minormax", false);
}

// specify appearing schema names in case of openapi array with oneOf elements
if (var.openApiType == "array" && var.items.dataType.startsWith("oneOf<")) {
// get only comma separated names of schemas from oneOf<name1,name2...>
String schemaNamesString =
var.items.dataType.substring(6, var.items.dataType.length() - 1);
List<String> oneofSchemas =
new ArrayList<String>(Arrays.asList(schemaNamesString.split("\\s*,\\s*")));

for (int i = 0; i < oneofSchemas.size(); i++) {
oneofSchemas.set(i, lowerCaseStringExceptFirstLetter(oneofSchemas.get(i)));
}

propertyVendorExtensions.put("x-oneof-schemas", oneofSchemas);
}
}
}
return super.postProcessModelsEnum(objs);
Expand All @@ -233,7 +247,8 @@ public String generateOperationId(CodegenOperation op) {
pathElements[i] = "";
}
if (pathElements[i].length() > 0) {
newOperationid = newOperationid + this.lowerCaseStringExceptFirstLetter(pathElements[i]);
newOperationid = newOperationid
+ this.lowerCaseStringExceptFirstLetter(pathElements[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{/apiInfo}}
{{#models}}
{{#model}}
{{^vendorExtensions.x-is-openapimodel-enum}}
{{^isEnum}}
<xs:complexType name="{{classname}}">
{{#description}}
<xs:annotation>
Expand Down Expand Up @@ -65,6 +65,10 @@
</xs:element>
{{/vendorExtensions.x-prop-has-minormax}}
{{^vendorExtensions.x-prop-has-minormax}}
{{#vendorExtensions.x-oneof-schemas}}
<xs:element minOccurs="0" maxOccurs="unbounded" name="{{#lambda.lowercase}}{{.}}{{/lambda.lowercase}}" type="schemas:{{.}}" />
{{/vendorExtensions.x-oneof-schemas}}
{{^vendorExtensions.x-oneof-schemas}}
{{#isContainer}}
<xs:element minOccurs="{{minItems}}{{^minItems}}{{#required}}1{{/required}}{{^required}}0{{/required}}{{/minItems}}" maxOccurs="{{maxItems}}{{^maxItems}}unbounded{{/maxItems}}" name="{{baseName}}" type="{{#items}}{{#isModel}}schemas:{{complexType}}{{/isModel}}{{^isModel}}{{#isFreeFormObject}}xs:string{{/isFreeFormObject}}{{^isFreeFormObject}}{{#isString}}xs:{{complexType}}{{/isString}}{{^isString}}{{#isNumeric}}xs:{{complexType}}{{/isNumeric}}{{^isNumeric}}schemas:{{complexType}}{{/isNumeric}}{{/isString}}{{/isFreeFormObject}}{{/isModel}}{{/items}}"{{^description}} /{{/description}}>
{{/isContainer}}
Expand All @@ -77,11 +81,12 @@
</xs:annotation>
</xs:element>
{{/description}}
{{/vendorExtensions.x-oneof-schemas}}
{{/vendorExtensions.x-prop-has-minormax}}
{{/vars}}
</xs:sequence>
</xs:complexType>
{{/vendorExtensions.x-is-openapimodel-enum}}
{{/isEnum}}
{{/model}}
{{/models}}
{{#models}}
Expand Down Expand Up @@ -206,7 +211,7 @@
<xs:complexType name="{{operationId}}_ResponseMessage">
<xs:sequence>
{{#message}}
<xs:element minOccurs="1"{{#isArray}} maxOccurs="unbounded"{{/isArray}} name="{{#isModel}}{{#isMap}}response{{/isMap}}{{^isMap}}{{#isFile}}response{{/isFile}}{{^isFile}}{{dataType}}{{/isFile}}{{/isMap}}{{/isModel}}{{^isModel}}{{#isArray}}{{baseType}}{{/isArray}}{{^isArray}}response{{/isArray}}{{/isModel}}"{{#dataType}} type="{{#isModel}}{{#isMap}}xs:{{baseType}}{{/isMap}}{{^isMap}}{{#isFile}}xs:anyType{{/isFile}}{{^isFile}}schemas:{{dataType}}{{/isFile}}{{/isMap}}{{/isModel}}{{^isModel}}{{#isArray}}schemas:{{baseType}}{{/isArray}}{{^isArray}}xs:{{dataType}}{{/isArray}}{{/isModel}}"{{/dataType}}>
<xs:element minOccurs="1"{{#isArray}} maxOccurs="unbounded"{{/isArray}} name="{{#isModel}}{{#isMap}}response{{/isMap}}{{^isMap}}{{#isFile}}response{{/isFile}}{{^isFile}}{{dataType}}{{/isFile}}{{/isMap}}{{/isModel}}{{^isModel}}{{#isArray}}{{baseType}}{{/isArray}}{{^isArray}}response{{/isArray}}{{/isModel}}"{{#dataType}} type="{{#isModel}}{{#isMap}}xs:{{baseType}}{{/isMap}}{{^isMap}}{{#isFile}}xs:string{{/isFile}}{{^isFile}}schemas:{{dataType}}{{/isFile}}{{/isMap}}{{/isModel}}{{^isModel}}{{#isArray}}schemas:{{baseType}}{{/isArray}}{{^isArray}}xs:{{dataType}}{{/isArray}}{{/isModel}}"{{/dataType}}>
<xs:annotation>
<xs:documentation>{{message}}</xs:documentation>
</xs:annotation>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/R/.openapi-generator/FILES
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib/Api</directory>
<directory suffix=".php">./lib/Model</directory>
<directory suffix=".php">./lib\/Api</directory>
<directory suffix=".php">./lib\/Model</directory>
</whitelist>
</filter>
<php>
Expand Down
12 changes: 6 additions & 6 deletions samples/client/petstore/powershell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ Class | Method | HTTP request | Description

## Documentation for Models

- [PSPetstore/Model.ApiResponse](docs/ApiResponse.md)
- [PSPetstore/Model.Category](docs/Category.md)
- [PSPetstore/Model.Order](docs/Order.md)
- [PSPetstore/Model.Pet](docs/Pet.md)
- [PSPetstore/Model.Tag](docs/Tag.md)
- [PSPetstore/Model.User](docs/User.md)
- [PSPetstore\Model.ApiResponse](docs/ApiResponse.md)
- [PSPetstore\Model.Category](docs/Category.md)
- [PSPetstore\Model.Order](docs/Order.md)
- [PSPetstore\Model.Pet](docs/Pet.md)
- [PSPetstore\Model.Tag](docs/Tag.md)
- [PSPetstore\Model.User](docs/User.md)


## Documentation for Authorization
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/powershell/docs/PSPetApi.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PSPetstore.PSPetstore/Api.PSPetApi
# PSPetstore.PSPetstore\Api.PSPetApi

All URIs are relative to *http://petstore.swagger.io:80/v2*

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/powershell/docs/PSStoreApi.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PSPetstore.PSPetstore/Api.PSStoreApi
# PSPetstore.PSPetstore\Api.PSStoreApi

All URIs are relative to *http://petstore.swagger.io:80/v2*

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/powershell/docs/PSUserApi.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PSPetstore.PSPetstore/Api.PSUserApi
# PSPetstore.PSPetstore\Api.PSUserApi

All URIs are relative to *http://petstore.swagger.io:80/v2*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Capitalization {
sCAETHFlowPoints?: string;
/**
* Name of the pet

* @type {string}
* @memberof Capitalization
*/
Expand Down
Loading