Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Sep 20, 2024
1 parent 960593e commit 57b2c6d
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ public void testRecordWithDefaultValues() throws IOException {
TestUtils.compareWithGeneratedFile(ballerinaFilePath, "record/record_with_default_values.yaml");
}

@Test(description = "Test for record fields with name field annotation")
public void testRecordWithNameFieldAnnotation() throws IOException {
Path ballerinaFilePath = RES_DIR.resolve("record/record_field_with_name_annotation.bal");
TestUtils.compareWithGeneratedFile(ballerinaFilePath, "record/record_field_with_name_annotation.yaml");
}

@AfterMethod
public void cleanUp() {
TestUtils.deleteDirectory(this.tempDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
openapi: 3.0.1
info:
title: PayloadV
version: 0.0.0
servers:
- url: "http://{server}:{port}/payloadV"
variables:
server:
default: localhost
port:
default: "8080"
paths:
/albums:
get:
operationId: getAlbums
parameters:
- name: artists
in: query
schema:
type: array
items:
type: string
default: []
- name: X-API-VERSION
in: header
schema:
type: string
nullable: true
default: v1
responses:
"200":
description: Ok
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Album"
"400":
description: BadRequest
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorPayload"
post:
operationId: postAlbums
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Album"
required: true
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/Album"
"400":
description: BadRequest
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorPayload"
/albums/{id}:
get:
operationId: getAlbumsId
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: Ok
content:
application/json:
schema:
$ref: "#/components/schemas/Album"
"400":
description: BadRequest
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorPayload"
components:
schemas:
Album:
required:
- _id
- _title
- artist
type: object
properties:
artist:
type: string
_id:
type: string
_title:
type: string
additionalProperties: false
ErrorPayload:
required:
- message
- method
- path
- reason
- status
- timestamp
type: object
properties:
timestamp:
type: string
status:
type: integer
format: int64
reason:
type: string
message:
type: string
path:
type: string
method:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ballerina/data.jsondata;
import ballerina/http;

@http:ServiceConfig {basePath: "/payloadV"}
type OASServiceType service object {
*http:ServiceContract;
resource function get albums(string[] artists = [], @http:Header {name: "X-API-VERSION"} string? xAPIVERSION = "v1") returns Album[];
resource function post albums(Album payload) returns Album;
resource function get albums/[string id]() returns Album;
};

const titleField = "_title";

public type Album record {|
string artist;
@jsondata:Name {value: "_id"}
string id;
@jsondata:Name {value: titleField}
string title;
|};

0 comments on commit 57b2c6d

Please sign in to comment.