Issue with generated OAS for record field has array record with nullable
**Description:**
```ballerina
type ResponseError record {|
    int? id;
    ResponseError[]? resError;
|};

type ResponseError record {|
    int? id;
    ResponseError[]? resError?;
|};
```
**Steps to reproduce:**

**Affected Versions:**

**OS, DB, other environment details and versions:**

**Related Issues (optional):**
<!-- Any related issues such as sub tasks, issues reported in other repositories (e.g component repositories), similar problems, etc. -->

**Suggested Labels (optional):**
<!-- Optional comma separated list of suggested labels. Non committers can’t assign labels to issues, so this will help issue creators who are not a committer to suggest possible labels-->

**Suggested Assignees (optional):**
<!--Optional comma separated list of suggested team members who should attend the issue. Non committers can’t assign issues to assignees, so this will help issue creators who are not a committer to suggest possible assignees-->

diff --git a/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIComponentMapper.java b/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIComponentMapper.java
index 159cf157..15cd93bc 100644
--- a/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIComponentMapper.java
+++ b/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIComponentMapper.java
@@ -189,7 +189,7 @@ public class OpenAPIComponentMapper {
                 schema = components.getSchemas();
             }
             if (property instanceof ArraySchema) {
-                mapArrayToArraySchema(schema, field.getValue(), (ArraySchema) property);
+                mapArrayToArraySchema(schema, field.getValue(), (ArraySchema) property, componentName);
                 schema = components.getSchemas();
             }
             // Add API documentation for record field
@@ -307,7 +307,8 @@ public class OpenAPIComponentMapper {
     /**
      * Generate arraySchema for ballerina record  as array type.
      */
-    private void mapArrayToArraySchema(Map<String, Schema> schema, RecordFieldSymbol field, ArraySchema property) {
+    private void mapArrayToArraySchema(Map<String, Schema> schema, RecordFieldSymbol field, ArraySchema property,
+                                       String componentName) {
 
         TypeSymbol symbol = field.typeDescriptor();
         int arrayDimensions = 0;
@@ -320,19 +321,11 @@ public class OpenAPIComponentMapper {
         Schema symbolProperty  = ConverterCommonUtils.getOpenApiSchema(symbol.typeKind().getName());
         // Handle record fields have union type array (ex: string[]? name)
         if (symbol.typeKind() == TypeDescKind.UNION) {
-            symbolProperty = getSchemaForUnionType((UnionTypeSymbol) symbol, symbolProperty);
+            symbolProperty = getSchemaForUnionType((UnionTypeSymbol) symbol, symbolProperty, componentName, schema);
         }
         // Set the record model to the definition
         if (symbol.typeKind().equals(TypeDescKind.TYPE_REFERENCE)) {
-            if (((TypeReferenceTypeSymbol) symbol).definition().kind() == SymbolKind.ENUM) {
-                TypeReferenceTypeSymbol typeRefEnum = (TypeReferenceTypeSymbol) symbol;
-                EnumSymbol enumSymbol = (EnumSymbol) typeRefEnum.definition();
-                symbolProperty = mapEnumValues(enumSymbol);
-            } else {
-                symbolProperty.set$ref(symbol.getName().orElseThrow().trim());
-                TypeReferenceTypeSymbol typeRecord = (TypeReferenceTypeSymbol) symbol;
-                createComponentSchema(schema, typeRecord);
-            }
+            symbolProperty = getSchemaForTypeReferenceSymbol(symbol, symbolProperty, componentName, schema);
         }
         // Handle nested array type
         if (arrayDimensions > 1) {
@@ -349,12 +342,18 @@ public class OpenAPIComponentMapper {
      * `string[]? name` here it takes union member types as array and nil,fix should do with array type and map to
      * oneOf OAS.
      */
-    private Schema getSchemaForUnionType(UnionTypeSymbol symbol, Schema symbolProperty) {
+    private Schema getSchemaForUnionType(UnionTypeSymbol symbol, Schema symbolProperty, String componentName,
+                                         Map<String, Schema> schema) {
         List<TypeSymbol> typeSymbols = symbol.userSpecifiedMemberTypes();
         for (TypeSymbol typeSymbol: typeSymbols) {
             if (typeSymbol.typeKind() == TypeDescKind.ARRAY) {
                 TypeSymbol arrayType = ((ArrayTypeSymbol) typeSymbol).memberTypeDescriptor();
-                symbolProperty = ConverterCommonUtils.getOpenApiSchema(arrayType.typeKind().getName());
+                // Set the record model to the definition
+                if (arrayType.typeKind().equals(TypeDescKind.TYPE_REFERENCE)) {
+                    symbolProperty = getSchemaForTypeReferenceSymbol(arrayType, symbolProperty, componentName, schema);
+                } else {
+                    symbolProperty = ConverterCommonUtils.getOpenApiSchema(arrayType.typeKind().getName());
+                }
             } else if (typeSymbol.typeKind() != TypeDescKind.NIL) {
                 symbolProperty = ConverterCommonUtils.getOpenApiSchema(typeSymbol.typeKind().getName());
             }
@@ -362,6 +361,26 @@ public class OpenAPIComponentMapper {
         return symbolProperty;
     }
 
+    /**
+     * This util function is to handle the type reference symbol is record type or enum type.
+     */
+    private Schema getSchemaForTypeReferenceSymbol(TypeSymbol arrayType, Schema symbolProperty, String componentName,
+                                                   Map<String, Schema> schema) {
+
+        if (((TypeReferenceTypeSymbol) arrayType).definition().kind() == SymbolKind.ENUM) {
+            TypeReferenceTypeSymbol typeRefEnum = (TypeReferenceTypeSymbol) arrayType;
+            EnumSymbol enumSymbol = (EnumSymbol) typeRefEnum.definition();
+            symbolProperty = mapEnumValues(enumSymbol);
+        } else {
+            symbolProperty.set$ref(arrayType.getName().orElseThrow().trim());
+            TypeReferenceTypeSymbol typeRecord = (TypeReferenceTypeSymbol) arrayType;
+            if (!isSameRecord(componentName, typeRecord)) {
+                createComponentSchema(schema, typeRecord);
+            }
+        }
+        return symbolProperty;
+    }
+
     /**
      * Handle nested array.
      */
diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/record/cyclic_record.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/record/cyclic_record.yaml
index f220c40d..da66ec3c 100644
--- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/record/cyclic_record.yaml
+++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/record/cyclic_record.yaml
@@ -34,6 +34,66 @@ paths:
                 $ref: '#/components/schemas/ResponseError02'
         "202":
           description: Accepted
+  /pet03:
+    post:
+      operationId: operation_post_/pet03
+      responses:
+        "200":
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ResponseError03'
+        "202":
+          description: Accepted
+  /pet04:
+    post:
+      operationId: operation_post_/pet04
+      responses:
+        "200":
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ResponseError04'
+        "202":
+          description: Accepted
+  /pet05:
+    post:
+      operationId: operation_post_/pet05
+      responses:
+        "200":
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ResponseError05'
+        "202":
+          description: Accepted
+  /pet06:
+    post:
+      operationId: operation_post_/pet06
+      responses:
+        "200":
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ResponseError06'
+        "202":
+          description: Accepted
+  /pet07:
+    post:
+      operationId: operation_post_/pet07
+      responses:
+        "200":
+          description: Ok
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/ResponseError07'
+        "202":
+          description: Accepted
 components:
   schemas:
     ResponseError:
@@ -60,3 +120,73 @@ components:
           oneOf:
             - $ref: '#/components/schemas/ResponseError02'
             - type: string
+    ResponseError03:
+      required:
+        - id
+      type: object
+      properties:
+        id:
+          type: integer
+          format: int32
+          nullable: true
+        resError:
+          type: array
+          items:
+            $ref: '#/components/schemas/ResponseError03'
+    ResponseError04:
+      required:
+        - id
+      type: object
+      properties:
+        id:
+          type: integer
+          format: int32
+          nullable: true
+        resError:
+          type: array
+          items:
+            type: array
+            items:
+              $ref: '#/components/schemas/ResponseError04'
+    ResponseError05:
+      required:
+        - id
+      type: object
+      properties:
+        id:
+          type: integer
+          format: int32
+          nullable: true
+        resError:
+          nullable: true
+          oneOf:
+            - $ref: '#/components/schemas/ResponseError05'
+    ResponseError06:
+      required:
+        - id
+      type: object
+      properties:
+        id:
+          type: integer
+          format: int32
+          nullable: true
+        resError:
+          type: array
+          nullable: true
+          items:
+            $ref: '#/components/schemas/ResponseError06'
+    ResponseError07:
+      required:
+        - id
+        - resError
+      type: object
+      properties:
+        id:
+          type: integer
+          format: int32
+          nullable: true
+        resError:
+          type: array
+          nullable: true
+          items:
+            $ref: '#/components/schemas/ResponseError07'
diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/record/cyclic_record.bal b/openapi-cli/src/test/resources/ballerina-to-openapi/record/cyclic_record.bal
index 60a120e1..30650857 100644
--- a/openapi-cli/src/test/resources/ballerina-to-openapi/record/cyclic_record.bal
+++ b/openapi-cli/src/test/resources/ballerina-to-openapi/record/cyclic_record.bal
@@ -10,6 +10,31 @@ type ResponseError02 record {|
     ResponseError02|string resError?;
 |};
 
+type ResponseError03 record {|
+    int? id;
+    ResponseError03[] resError?;
+|};
+
+type ResponseError04 record {|
+    int? id;
+    ResponseError04[][] resError?;
+|};
+
+type ResponseError05 record {|
+    int? id;
+    ResponseError05? resError?;
+|};
+
+type ResponseError06 record {|
+    int? id;
+    ResponseError06[]? resError?;
+|};
+
+type ResponseError07 record {|
+    int? id;
+    ResponseError07[]? resError;
+|};
+
 listener http:Listener ep0 = new (443, config = {host: "petstore.swagger.io"});
 
 service /payloadV on ep0 {
@@ -21,4 +46,24 @@ service /payloadV on ep0 {
         http:Accepted accept = {body: ()};
         return accept;
     }
+    resource function post pet03() returns ResponseError03|http:Accepted {
+        http:Accepted accept = {body: ()};
+        return accept;
+    }
+    resource function post pet04() returns ResponseError04|http:Accepted {
+        http:Accepted accept = {body: ()};
+        return accept;
+    }
+    resource function post pet05() returns ResponseError05|http:Accepted {
+         http:Accepted accept = {body: ()};
+         return accept;
+    }
+    resource function post pet06() returns ResponseError06|http:Accepted {
+         http:Accepted accept = {body: ()};
+         return accept;
+    }
+    resource function post pet07() returns ResponseError07|http:Accepted {
+        http:Accepted accept = {body: ()};
+        return accept;
+    }
 }
['openapi-cli/src/test/resources/ballerina-to-openapi/record/cyclic_record.bal', 'openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIComponentMapper.java', 'openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/record/cyclic_record.yaml']