Skip to content

Commit

Permalink
Merge pull request #867 from lnash94/beta_6_choreo
Browse files Browse the repository at this point in the history
[BallerinaToOpenAPI][beta6]Fix cyclic array record resolving issue
  • Loading branch information
hevayo authored Jan 21, 2022
2 parents a00632c + 03b5c71 commit 3a4e4a9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private ObjectSchema generateObjectSchemaFromRecordFields(Map<String, Schema> sc
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
Expand Down Expand Up @@ -307,7 +307,8 @@ private Schema mapEnumValues(EnumSymbol enumSymbol) {
/**
* 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;
Expand All @@ -331,7 +332,9 @@ private void mapArrayToArraySchema(Map<String, Schema> schema, RecordFieldSymbol
} else {
symbolProperty.set$ref(symbol.getName().orElseThrow().trim());
TypeReferenceTypeSymbol typeRecord = (TypeReferenceTypeSymbol) symbol;
createComponentSchema(schema, typeRecord);
if (!isSameRecord(componentName, typeRecord)) {
createComponentSchema(schema, typeRecord);
}
}
}
// Handle nested array type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ 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
components:
schemas:
ResponseError:
Expand All @@ -60,3 +72,16 @@ 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'
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ type ResponseError02 record {|
ResponseError02|string resError?;
|};

type ResponseError03 record {|
int? id;
ResponseError03[] resError?;
|};

listener http:Listener ep0 = new (443, config = {host: "petstore.swagger.io"});

service /payloadV on ep0 {
Expand All @@ -21,4 +26,8 @@ service /payloadV on ep0 {
http:Accepted accept = {body: ()};
return accept;
}
resource function post pet03() returns ResponseError03|http:Accepted {
http:Accepted accept = {body: ()};
return accept;
}
}

0 comments on commit 3a4e4a9

Please sign in to comment.