-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1767 from ballerina-platform/fix-default-value-is…
…sues Fix issues with default values in OpenAPI/Code generation
- Loading branch information
Showing
14 changed files
with
766 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...c/test/resources/ballerina-to-openapi/expected_gen/record/record_with_default_values.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
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/{id}: | ||
get: | ||
operationId: getAlbumsId | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
- name: q1 | ||
in: query | ||
schema: | ||
type: string | ||
default: query1 | ||
- name: q2 | ||
in: query | ||
schema: | ||
type: integer | ||
format: int64 | ||
default: -1 | ||
- name: X-HEADER | ||
in: header | ||
schema: | ||
type: string | ||
default: header1 | ||
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: | ||
- author | ||
- title | ||
type: object | ||
properties: | ||
iid: | ||
type: integer | ||
format: int64 | ||
default: -1 | ||
title: | ||
type: string | ||
author: | ||
type: string | ||
genre: | ||
allOf: | ||
- $ref: "#/components/schemas/Genre" | ||
default: | ||
name: Unknown | ||
description: Unknown | ||
iid: -1 | ||
tags: | ||
type: array | ||
items: | ||
type: string | ||
default: | ||
- tag1 | ||
- tag2 | ||
ratings: | ||
type: array | ||
items: | ||
oneOf: | ||
- type: string | ||
- type: integer | ||
format: int64 | ||
default: | ||
- unrated | ||
- 5 | ||
- 4 | ||
price: | ||
type: number | ||
format: double | ||
default: 100.55 | ||
available: | ||
type: boolean | ||
default: true | ||
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 | ||
Genre: | ||
required: | ||
- description | ||
- iid | ||
- name | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
description: | ||
oneOf: | ||
- type: string | ||
- type: array | ||
items: | ||
type: string | ||
iid: | ||
type: integer | ||
format: int64 | ||
additionalProperties: false |
31 changes: 31 additions & 0 deletions
31
openapi-cli/src/test/resources/ballerina-to-openapi/record/record_with_default_values.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import ballerina/http; | ||
|
||
public type Genre record {| | ||
string name; | ||
string|string[] description; | ||
int iid; | ||
|}; | ||
|
||
public type Album record {| | ||
int iid = -1; | ||
string title; | ||
string author; | ||
Genre genre = { | ||
name: "Unknown", | ||
description: "Unknown", | ||
iid: -1 | ||
}; | ||
string[] tags = ["tag1", "tag2"]; | ||
(string|int)[] ratings = ["unrated", 5, 4]; | ||
decimal price = 100.55; | ||
boolean available = true; | ||
|}; | ||
|
||
@http:ServiceConfig { | ||
basePath: "/payloadV" | ||
} | ||
type AlbumService service object { | ||
*http:ServiceContract; | ||
|
||
resource function get albums/[string id](string q1 = "query1", int q2 = -1, @http:Header {name: "X-HEADER"} string h1 = "header1") returns Album; | ||
}; |
118 changes: 118 additions & 0 deletions
118
openapi-cli/src/test/resources/default_value_generation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
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/{id}: | ||
get: | ||
operationId: getAlbumsId | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
- name: q1 | ||
in: query | ||
required: true | ||
schema: | ||
type: string | ||
default: query1 | ||
- name: q2 | ||
in: query | ||
schema: | ||
type: integer | ||
format: int64 | ||
default: -1 | ||
- name: X-HEADER | ||
in: header | ||
required: true | ||
schema: | ||
type: string | ||
default: header1 | ||
responses: | ||
"200": | ||
description: Ok | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Album" | ||
components: | ||
schemas: | ||
Album: | ||
required: | ||
- author | ||
- title | ||
type: object | ||
properties: | ||
iid: | ||
type: integer | ||
format: int64 | ||
default: -1 | ||
title: | ||
type: string | ||
author: | ||
type: string | ||
genre: | ||
allOf: | ||
- $ref: "#/components/schemas/Genre" | ||
default: | ||
name: Unknown | ||
description: Unknown | ||
iid: -1 | ||
tags: | ||
type: array | ||
items: | ||
type: string | ||
default: | ||
- tag1 | ||
- tag2 | ||
ratings: | ||
type: array | ||
items: | ||
oneOf: | ||
- type: string | ||
- type: integer | ||
format: int64 | ||
default: | ||
- unrated | ||
- 5 | ||
- 4 | ||
price: | ||
type: number | ||
format: double | ||
default: 100.55 | ||
available: | ||
type: boolean | ||
default: true | ||
additionalProperties: false | ||
Genre: | ||
required: | ||
- description | ||
- iid | ||
- name | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
default: Unknown | ||
description: | ||
oneOf: | ||
- type: string | ||
- type: array | ||
items: | ||
type: string | ||
default: | ||
- Unknown | ||
- Unknown | ||
iid: | ||
type: integer | ||
format: int64 | ||
additionalProperties: false |
Oops, something went wrong.