Skip to content

Commit

Permalink
Merge pull request #11 from ballerina-platform/fix-utils
Browse files Browse the repository at this point in the history
Fix multi-part form data entity creation for array values
  • Loading branch information
NipunaRanasinghe authored Aug 17, 2024
2 parents de5a74d + 521fb84 commit 8d109c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 0 additions & 1 deletion ballerina/tests/tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ isolated function testCreateSpeech() returns error? {


@test:Config {
enable:false,
groups: ["live_tests", "mock_tests"]
}
isolated function testCreateTranscription() returns error? {
Expand Down
14 changes: 12 additions & 2 deletions ballerina/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ isolated function createBodyParts(record {|anydata...;|} anyRecord, map<Encoding
} else if value is byte[] {
entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`));
entity.setByteArray(value);
} else if value is SimpleBasicType|SimpleBasicType[] {
} else if value is SimpleBasicType {
entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`));
entity.setText(value.toString());
} else if value is record {}|record {}[] {
} else if value is SimpleBasicType[] {
foreach SimpleBasicType member in value {
entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`));
entity.setText(member.toString());
}
} else if value is record {} {
entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`));
entity.setJson(value.toJson());
} else if value is record {}[] {
foreach record{} member in value {
entity.setContentDisposition(mime:getContentDispositionObject(string `form-data; name=${key};`));
entity.setJson(member.toJson());
}
}
if encodingData?.contentType is string {
check entity.setContentType(encodingData?.contentType.toString());
Expand Down
5 changes: 4 additions & 1 deletion docs/spec/sanitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _Edition_: Swan Lake
# Sanitation for OpenAPI specification

This document records the sanitation done on top of the official OpenAPI specification from OpenAI Audio.
The OpenAPI specification is obtained from The OpenAPI specification is obtained from the [OpenAPI specification for the OpenAI API](https://github.com/openai/openai-openapi/blob/master/openapi.yaml)..
The OpenAPI specification is obtained from The OpenAPI specification is obtained from the [OpenAPI specification for the OpenAI API](https://github.com/openai/openai-openapi/blob/master/openapi.yaml).
These changes are done in order to improve the overall usability, and as workarounds for some known language limitations.

1. **Removed the `default:null` property from the below schemas**:
Expand Down Expand Up @@ -54,6 +54,9 @@ These changes are done in order to improve the overall usability, and as workaro
- $ref: "#/components/schemas/CreateTranslationResponseVerboseJson"

- **Reason**: This modification has been implemented to enhance the readability and user-friendliness of record naming conventions.

3. Modified the generated util function `createBodyParts` as a workaround for the issue https://github.com/ballerina-platform/ballerina-library/issues/6872. This change should be reverted once the issue is fixed in a future release (2201.9.4 or later).


## OpenAPI cli command

Expand Down

0 comments on commit 8d109c8

Please sign in to comment.