diff --git a/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIRequestBodyMapper.java b/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIRequestBodyMapper.java index 9308f66e3..8a278cbe3 100644 --- a/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIRequestBodyMapper.java +++ b/openapi-bal-service/src/main/java/io/ballerina/openapi/converter/service/OpenAPIRequestBodyMapper.java @@ -283,8 +283,8 @@ private String getMediaTypeForSyntaxKind(TypeDescriptorNode payloadNode) { return customMediaPrefix == null ? MediaType.APPLICATION_OCTET_STREAM : APPLICATION_PREFIX + customMediaPrefix + OCTECT_STREAM_POSTFIX; case SIMPLE_NAME_REFERENCE: - SimpleNameReferenceNode record = (SimpleNameReferenceNode) payloadNode; - TypeSymbol typeSymbol = getReferenceTypeSymbol(semanticModel.symbol(record)); + case QUALIFIED_NAME_REFERENCE: + TypeSymbol typeSymbol = getReferenceTypeSymbol(semanticModel.symbol(payloadNode)); if (typeSymbol instanceof TypeReferenceTypeSymbol) { typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); } @@ -346,16 +346,21 @@ private void handleArrayTypePayload(Map schema, ArrayTypeDescrip TypeDescriptorNode typeDescriptorNode = arrayNode.memberTypeDesc(); // Nested array not allowed io.swagger.v3.oas.models.media.MediaType media = new io.swagger.v3.oas.models.media.MediaType(); - if (typeDescriptorNode.kind().equals(SyntaxKind.SIMPLE_NAME_REFERENCE)) { + if (typeDescriptorNode.kind().equals(SyntaxKind.SIMPLE_NAME_REFERENCE) || + typeDescriptorNode.kind().equals(SyntaxKind.QUALIFIED_NAME_REFERENCE)) { //handle record for components - SimpleNameReferenceNode referenceNode = (SimpleNameReferenceNode) typeDescriptorNode; - TypeSymbol typeSymbol = getReferenceTypeSymbol(semanticModel.symbol(referenceNode)); + TypeSymbol typeSymbol = getReferenceTypeSymbol(semanticModel.symbol(typeDescriptorNode)); OpenAPIComponentMapper componentMapper = new OpenAPIComponentMapper(components); componentMapper.createComponentSchema(schema, typeSymbol); diagnostics.addAll(componentMapper.getDiagnostics()); Schema itemSchema = new Schema(); - arraySchema.setItems(itemSchema.$ref(ConverterCommonUtils.unescapeIdentifier( - referenceNode.name().text().trim()))); + String referenceName; + if (typeDescriptorNode.kind().equals(SyntaxKind.SIMPLE_NAME_REFERENCE)) { + referenceName = ((SimpleNameReferenceNode) typeDescriptorNode).name().toString().trim(); + } else { + referenceName = ((QualifiedNameReferenceNode) typeDescriptorNode).identifier().text(); + } + arraySchema.setItems(itemSchema.$ref(ConverterCommonUtils.unescapeIdentifier(referenceName))); media.setSchema(arraySchema); } else if (typeDescriptorNode.kind() == SyntaxKind.BYTE_TYPE_DESC) { StringSchema byteSchema = new StringSchema(); diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/ballerina-project/service/snowpeak_request_body.bal b/openapi-cli/src/test/resources/ballerina-to-openapi/ballerina-project/service/snowpeak_request_body.bal index 63440d66d..30c48aea6 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/ballerina-project/service/snowpeak_request_body.bal +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/ballerina-project/service/snowpeak_request_body.bal @@ -31,6 +31,15 @@ service /payloadV on new http:Listener(9090) { return created; } + # Represents Snowpeak reservations resource + # + # + reservations - Array representation of Reservations + # + return - `ReservationCreated` or ReservationConflict representation + resource function post reservations(@http:Payload rep:Reservation[] reservations) + returns @http:Cache{} http:Created|rep:ReservationConflict { + return http:CREATED; + } + # Represents Snowpeak payment resource # # + id - Unique identification of payment diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml index 22fdfebfd..ad6cfdf69 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml @@ -44,6 +44,38 @@ paths: text/plain: schema: type: string + /reservations: + post: + summary: Represents Snowpeak reservations resource + operationId: postReservations + requestBody: + description: Array representation of Reservations + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Reservation' + responses: + "201": + description: Created + headers: + Cache-Control: + schema: + type: string + default: "must-revalidate,public,max-age=3600" + ETag: + schema: + type: string + Last-Modified: + schema: + type: string + "409": + description: Conflict + content: + text/plain: + schema: + type: string /payment/{id}: post: summary: Represents Snowpeak payment resource