Skip to content

Commit

Permalink
Merge pull request #45 from Nirhoshan/add_xml_support
Browse files Browse the repository at this point in the history
Address inline schema for xml
  • Loading branch information
nadheesh committed Feb 7, 2024
2 parents ba779f9 + 491600f commit 937367e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
distribution = "2201.8.4"
org = "ballerinax"
name = "ai.agent"
version = "0.7.4"
version = "0.7.5"
license = ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["AI/Agent", "Cost/Freemium"]
Expand Down
14 changes: 10 additions & 4 deletions ballerina/openapi_utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class OpenApiSpecVisitor {
return error UnsupportedMediaTypeError("Only json, xml or text content is supported.", availableContentTypes = content.keys());
}

private isolated function visitRequestBody(RequestBody requestBody) returns RequestBodySchema|error {
private isolated function visitRequestBody(RequestBody requestBody) returns RequestBodySchema|OpenApiParsingError|error {
map<MediaType> content = requestBody.content;
string mediaType;
Schema schema;
Expand All @@ -224,10 +224,16 @@ class OpenApiSpecVisitor {
schema: check self.visitSchema(schema)
};
}
if schema is Reference {
string refName = regexp:split(re `/`, schema.\$ref).pop();
schema = {'type: OBJECT, properties: {[refName] : schema}};
string? xmlName = schema.'xml?.name;
string outerBlockName;
if xmlName is string {
outerBlockName = xmlName;
} else if schema is Reference {
outerBlockName = regexp:split(re `/`, schema.\$ref).pop();
} else {
return error OpenApiParsingError("Error while parsing the OpenAPI specification. The schema should have a name for xml content type.", cause = schema);
}
schema = {'type: OBJECT, properties: {[outerBlockName] : schema}};
return {
mediaType,
schema: check self.visitSchema(schema, true)
Expand Down

0 comments on commit 937367e

Please sign in to comment.