diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
index eb3c227d125..f198bb1c8ae 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
@@ -6722,6 +6722,9 @@ public class DefaultCodegen implements CodegenConfig {
// Set 'required' flag defined in the schema element
if (!codegenParameter.required && schema.getRequired() != null) {
codegenParameter.required = schema.getRequired().contains(entry.getKey());
+ } else if (!codegenParameter.required) {
+ // Set 'required' flag for properties declared inside the allOf
+ codegenParameter.required = allRequired.stream().anyMatch(r -> r.equals(codegenParameter.paramName));
}
parameters.add(codegenParameter);
diff --git a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
index ff40f507720..8a003841821 100644
--- a/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
+++ b/modules/openapi-generator/src/test/resources/3_0/csharp/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
@@ -1117,6 +1117,23 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ArrayOfEnums'
+ /country:
+ post:
+ operationId: getCountry
+ requestBody:
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ allOf:
+ - required:
+ - country
+ type: object
+ properties:
+ country:
+ type: string
+ responses:
+ '200':
+ description: OK
servers:
- url: 'http://{server}.swagger.io:{port}/v2'
description: petstore server
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/README.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/README.md
index bff23f31e56..cf4a21009f8 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/README.md
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/README.md
@@ -105,6 +105,7 @@ Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AnotherFakeApi* | [**Call123TestSpecialTags**](docs/AnotherFakeApi.md#call123testspecialtags) | **PATCH** /another-fake/dummy | To test special tags
*DefaultApi* | [**FooGet**](docs/DefaultApi.md#fooget) | **GET** /foo |
+*DefaultApi* | [**GetCountry**](docs/DefaultApi.md#getcountry) | **POST** /country |
*FakeApi* | [**FakeHealthGet**](docs/FakeApi.md#fakehealthget) | **GET** /fake/health | Health check endpoint
*FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **POST** /fake/outer/boolean |
*FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **POST** /fake/outer/composite |
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/docs/DefaultApi.md b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/docs/DefaultApi.md
index 3a93305e15b..265fec1a6f9 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/docs/DefaultApi.md
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/docs/DefaultApi.md
@@ -5,6 +5,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
| Method | HTTP request | Description |
|--------|--------------|-------------|
| [**FooGet**](DefaultApi.md#fooget) | **GET** /foo | |
+| [**GetCountry**](DefaultApi.md#getcountry) | **POST** /country | |
# **FooGet**
@@ -88,3 +89,86 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
+
+# **GetCountry**
+> void GetCountry (string country)
+
+
+
+### Example
+```csharp
+using System.Collections.Generic;
+using System.Diagnostics;
+using Org.OpenAPITools.Api;
+using Org.OpenAPITools.Client;
+using Org.OpenAPITools.Model;
+
+namespace Example
+{
+ public class GetCountryExample
+ {
+ public static void Main()
+ {
+ Configuration config = new Configuration();
+ config.BasePath = "http://petstore.swagger.io:80/v2";
+ var apiInstance = new DefaultApi(config);
+ var country = "country_example"; // string |
+
+ try
+ {
+ apiInstance.GetCountry(country);
+ }
+ catch (ApiException e)
+ {
+ Debug.Print("Exception when calling DefaultApi.GetCountry: " + e.Message);
+ Debug.Print("Status Code: " + e.ErrorCode);
+ Debug.Print(e.StackTrace);
+ }
+ }
+ }
+}
+```
+
+#### Using the GetCountryWithHttpInfo variant
+This returns an ApiResponse object which contains the response data, status code and headers.
+
+```csharp
+try
+{
+ apiInstance.GetCountryWithHttpInfo(country);
+}
+catch (ApiException e)
+{
+ Debug.Print("Exception when calling DefaultApi.GetCountryWithHttpInfo: " + e.Message);
+ Debug.Print("Status Code: " + e.ErrorCode);
+ Debug.Print(e.StackTrace);
+}
+```
+
+### Parameters
+
+| Name | Type | Description | Notes |
+|------|------|-------------|-------|
+| **country** | **string** | | |
+
+### Return type
+
+void (empty response body)
+
+### Authorization
+
+No authorization required
+
+### HTTP request headers
+
+ - **Content-Type**: application/x-www-form-urlencoded
+ - **Accept**: Not defined
+
+
+### HTTP response details
+| Status code | Description | Response headers |
+|-------------|-------------|------------------|
+| **200** | OK | - |
+
+[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
+
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Api/DefaultApi.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Api/DefaultApi.cs
index bc5b5556d25..0ae306612df 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Api/DefaultApi.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient-ConditionalSerialization/src/Org.OpenAPITools/Api/DefaultApi.cs
@@ -45,6 +45,26 @@ namespace Org.OpenAPITools.Api
/// Index associated with the operation.
/// ApiResponse of FooGetDefaultResponse
ApiResponse FooGetWithHttpInfo(int operationIndex = 0);
+ ///
+ ///
+ ///
+ /// Thrown when fails to make API call
+ ///
+ /// Index associated with the operation.
+ ///
+ void GetCountry(string country, int operationIndex = 0);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Thrown when fails to make API call
+ ///
+ /// Index associated with the operation.
+ /// ApiResponse of Object(void)
+ ApiResponse