Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.8.x]Fix req body mapping for array type from external module #1557

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
lnash94 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading