Skip to content

Commit

Permalink
Merge pull request #1557 from ballerina-platform/fix-req-body-mapping
Browse files Browse the repository at this point in the history
[1.8.x]Fix req body mapping for array type from external module
  • Loading branch information
lnash94 authored Oct 18, 2023
2 parents 099183d + 81a4e3a commit 8f77adb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -346,16 +346,21 @@ private void handleArrayTypePayload(Map<String, Schema> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8f77adb

Please sign in to comment.