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

[CSharp] optional properties use boxed type [fix #19461] #19463

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion docs/generators/fsharp-functions.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
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 @@ -65,7 +65,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|
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk.| |false|
|useBeanValidation|Use BeanValidation API annotations| |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 @@ -48,13 +48,13 @@ 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|
|useCustomDateWithoutTime|Uses a custom type to decode and encode dates without time information to support OpenAPIs date format (default: false)| |false|
|useJsonEncodable|Make models conform to JSONEncodable protocol (default: true)| |true|
|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|
|validatable|Make validation rules and validator for model properies (default: true)| |true|

## IMPORT MAPPING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,17 @@ public String getTypeDeclaration(Schema p) {
return super.getTypeDeclaration(p);
}

@Override
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
var property = super.fromProperty(name, p, required);
if (required && property.dataType.endsWith("?") && !property.isNullable) {
property.dataType = property.dataType.substring(0, property.dataType.length()-1);
property.baseType = property.baseType.substring(0, property.baseType.length()-1);
property.datatypeWithEnum = property.datatypeWithEnum.substring(0, property.datatypeWithEnum.length()-1);
}
return property;
}

@Override
public String toModelName(String name) {
// obtain the name from modelNameMapping directly if provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public String getNullableType(Schema p, String type) {
}

if (languageSpecificPrimitives.contains(type)) {
if (isSupportNullable() && ModelUtils.isNullable(p) && this.getNullableTypes().contains(type)) {
if (isSupportNullable() && this.getNullableTypes().contains(type)) {
return type + "?";
} else {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public String toRegularExpression(String pattern) {
@Override
public String getNullableType(Schema p, String type) {
if (languageSpecificPrimitives.contains(type)) {
if (isSupportNullable() && ModelUtils.isNullable(p) && (this.getNullableTypes().contains(type) || nullReferenceTypesFlag)) {
if (isSupportNullable() && (this.getNullableTypes().contains(type) || nullReferenceTypesFlag)) {
return type + "?";
} else {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public String getNameUsingModelPropertyNaming(String name) {
@Override
public String getNullableType(Schema p, String type) {
if (languageSpecificPrimitives.contains(type)) {
if (isSupportNullable() && ModelUtils.isNullable(p) && this.getNullableTypes().contains(type)) {
if (isSupportNullable() && this.getNullableTypes().contains(type)) {
return type + "?";
} else {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testUnsigned() {

final CodegenProperty property1 = cm1.allVars.get(2);
Assert.assertEquals(property1.baseName, "unsigned_integer");
Assert.assertEquals(property1.dataType, "uint");
Assert.assertEquals(property1.dataType, "uint?");
Assert.assertEquals(property1.vendorExtensions.get("x-unsigned"), Boolean.TRUE);
Assert.assertTrue(property1.isPrimitiveType);
Assert.assertTrue(property1.isInteger);
Expand All @@ -82,7 +82,7 @@ public void testUnsigned() {

final CodegenProperty property2 = cm1.allVars.get(4);
Assert.assertEquals(property2.baseName, "unsigned_long");
Assert.assertEquals(property2.dataType, "ulong");
Assert.assertEquals(property2.dataType, "ulong?");
Assert.assertEquals(property2.vendorExtensions.get("x-unsigned"), Boolean.TRUE);
Assert.assertTrue(property2.isPrimitiveType);
Assert.assertTrue(property2.isLong);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ public void simpleModelTest() {

final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.dataType, "DateTime");
Assert.assertEquals(property3.dataType, "DateTime?");
Assert.assertEquals(property3.name, "CreatedAt");
Assert.assertNull(property3.defaultValue);
Assert.assertEquals(property3.baseType, "DateTime");
Assert.assertEquals(property3.baseType, "DateTime?");
Assert.assertFalse(property3.required);
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/csharp-restsharp/docs/Category.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **long** | | [optional]
**Id** | **long?** | | [optional]
**Name** | **string** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
4 changes: 2 additions & 2 deletions samples/client/echo_api/csharp-restsharp/docs/DataQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **long** | Query | [optional]
**Id** | **long?** | Query | [optional]
**Outcomes** | **List&lt;Query.OutcomesEnum&gt;** | | [optional]
**Suffix** | **string** | test suffix | [optional]
**Text** | **string** | Some text containing white spaces | [optional]
**Date** | **DateTime** | A date | [optional]
**Date** | **DateTime?** | A date | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Name | Type | Description | Notes
**ArrayStringEnumRefDefault** | [**List&lt;StringEnumRef&gt;**](StringEnumRef.md) | | [optional]
**ArrayStringEnumDefault** | **List&lt;DefaultValue.ArrayStringEnumDefaultEnum&gt;** | | [optional]
**ArrayStringDefault** | **List&lt;string&gt;** | | [optional]
**ArrayIntegerDefault** | **List&lt;int&gt;** | | [optional]
**ArrayIntegerDefault** | **List&lt;int?&gt;** | | [optional]
**ArrayString** | **List&lt;string&gt;** | | [optional]
**ArrayStringNullable** | **List&lt;string&gt;** | | [optional]
**ArrayStringExtensionNullable** | **List&lt;string&gt;** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Number** | **decimal** | | [optional]
**Float** | **float** | | [optional]
**Double** | **double** | | [optional]
**Number** | **decimal?** | | [optional]
**Float** | **float?** | | [optional]
**Double** | **double?** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

6 changes: 3 additions & 3 deletions samples/client/echo_api/csharp-restsharp/docs/PathApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All URIs are relative to *http://localhost:3000*

<a id="testspathstringpathstringintegerpathintegerenumnonrefstringpathenumrefstringpath"></a>
# **TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath**
> string TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath (string pathString, int pathInteger, string enumNonrefStringPath, StringEnumRef enumRefStringPath)
> string TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath (string pathString, int? pathInteger, string enumNonrefStringPath, StringEnumRef enumRefStringPath)

Test path parameter(s)

Expand All @@ -32,7 +32,7 @@ namespace Example
config.BasePath = "http://localhost:3000";
var apiInstance = new PathApi(config);
var pathString = "pathString_example"; // string |
var pathInteger = 56; // int |
var pathInteger = 56; // int? |
var enumNonrefStringPath = "success"; // string |
var enumRefStringPath = (StringEnumRef) "success"; // StringEnumRef |

Expand Down Expand Up @@ -78,7 +78,7 @@ catch (ApiException e)
| Name | Type | Description | Notes |
|------|------|-------------|-------|
| **pathString** | **string** | | |
| **pathInteger** | **int** | | |
| **pathInteger** | **int?** | | |
| **enumNonrefStringPath** | **string** | | |
| **enumRefStringPath** | **StringEnumRef** | | |

Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/csharp-restsharp/docs/Pet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **long** | | [optional]
**Id** | **long?** | | [optional]
**Name** | **string** | |
**Category** | [**Category**](Category.md) | | [optional]
**PhotoUrls** | **List&lt;string&gt;** | |
Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/csharp-restsharp/docs/Query.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **long** | Query | [optional]
**Id** | **long?** | Query | [optional]
**Outcomes** | **List&lt;Query.OutcomesEnum&gt;** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
6 changes: 3 additions & 3 deletions samples/client/echo_api/csharp-restsharp/docs/QueryApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ No authorization required

<a id="testquerystyleformexplodefalsearrayinteger"></a>
# **TestQueryStyleFormExplodeFalseArrayInteger**
> string TestQueryStyleFormExplodeFalseArrayInteger (List<int>? queryObject = null)
> string TestQueryStyleFormExplodeFalseArrayInteger (List<int?>? queryObject = null)

Test query parameter(s)

Expand All @@ -505,7 +505,7 @@ namespace Example
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
var apiInstance = new QueryApi(config);
var queryObject = new List<int>?(); // List<int>? | (optional)
var queryObject = new List<int?>?(); // List<int?>? | (optional)

try
{
Expand Down Expand Up @@ -548,7 +548,7 @@ catch (ApiException e)

| Name | Type | Description | Notes |
|------|------|-------------|-------|
| **queryObject** | [**List&lt;int&gt;?**](int.md) | | [optional] |
| **queryObject** | [**List&lt;int?&gt;?**](int?.md) | | [optional] |

### Return type

Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/csharp-restsharp/docs/Tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | **long** | | [optional]
**Id** | **long?** | | [optional]
**Name** | **string** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Size** | **string** | | [optional]
**Color** | **string** | | [optional]
**Id** | **long** | | [optional]
**Id** | **long?** | | [optional]
**Name** | **string** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Loading
Loading