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

Sync master with 1.8.x branch #1547

Merged
merged 10 commits into from
Oct 6, 2023
50 changes: 25 additions & 25 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
org.gradle.caching=true
group=io.ballerina
version=1.8.0-SNAPSHOT
version=1.8.1-SNAPSHOT

#dependency
ballerinaLangVersion=2201.8.0-20230908-135700-74a59dff
ballerinaLangVersion=2201.8.0
testngVersion=7.6.1
slf4jVersion=1.7.30
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8
Expand All @@ -15,41 +15,41 @@ swaggerParserVersion=2.1.16
puppycrawlCheckstyleVersion = 10.12.1

# Stdlib Level 01
stdlibIoVersion=1.6.0-20230911-134800-de06e28
stdlibIoVersion=1.6.0
stdlibRegexVersion=1.4.3
stdlibTimeVersion=2.4.0-20230911-140200-7f96f1e
stdlibUrlVersion=2.4.0-20230911-140700-36451a2
stdlibXmldataVersion=2.7.0-20230911-140600-3edd92d
stdlibTimeVersion=2.4.0
stdlibUrlVersion=2.4.0
stdlibXmldataVersion=2.7.0

# Stdlib Level 02
stdlibConstraintVersion=1.4.0-20230911-142700-8202202
stdlibCryptoVersion=2.5.0-20230911-142900-8807d07
stdlibLogVersion=2.9.0-20230911-150900-2f32c1a
stdlibOsVersion=1.8.0-20230911-142700-b182bf4
stdlibTaskVersion=2.5.0-20230911-143300-237313e
stdlibConstraintVersion=1.4.0
stdlibCryptoVersion=2.5.0
stdlibLogVersion=2.9.0
stdlibOsVersion=1.8.0
stdlibTaskVersion=2.5.0

# Stdlib Level 03
stdlibCacheVersion=3.7.0-20230911-145700-142f375
stdlibFileVersion=1.9.0-20230911-153400-738b25e
stdlibMimeVersion=2.9.0-20230911-153200-3add04c
stdlibUuidVersion=1.7.0-20230911-150900-6c4771f
stdlibCacheVersion=3.7.0
stdlibFileVersion=1.9.0
stdlibMimeVersion=2.9.0
stdlibUuidVersion=1.7.0

# Stdlib Level 04
stdlibAuthVersion=2.10.0-20230911-153500-8c3c5cb
stdlibJwtVersion=2.10.0-20230911-153400-b5de47b
stdlibOAuth2Version=2.10.0-20230911-153600-6710ec0
stdlibAuthVersion=2.10.0
stdlibJwtVersion=2.10.0
stdlibOAuth2Version=2.10.0

# Stdlib Level 05
stdlibHttpVersion=2.10.0-20230911-204400-1c092fe
stdlibHttpVersion=2.10.0

# Stdlib Level 06
stdlibGrpcVersion=1.10.0-20230911-215000-dc09f7e
stdlibWebsocketVersion=2.10.0-20230911-221500-317e2e7
stdlibWebsubVersion=2.10.0-20230911-215500-06f9822
stdlibGrpcVersion=1.10.0
stdlibWebsocketVersion=2.10.0
stdlibWebsubVersion=2.10.0

# Stdlib Level 07
stdlibGraphqlVersion=1.10.0-20230912-084000-2ef781d
stdlibGraphqlVersion=1.10.0

# Ballerinax Observer
observeVersion=1.2.0-20230911-133500-b3d8db3
observeInternalVersion=1.2.0-20230911-141700-4c0454a
observeVersion=1.2.0
observeInternalVersion=1.2.0
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public enum DiagnosticMessages {
"for Ballerina type '%s'. ", DiagnosticSeverity.WARNING),

OAS_CONVERTOR_115("OAS_CONVERTOR_115", "Given Ballerina file does not contain any HTTP service.",
DiagnosticSeverity.ERROR);
DiagnosticSeverity.ERROR),
OAS_CONVERTOR_116("OAS_CONVERTOR_116", "Generated OpenAPI definition does not contain `%s` request" +
" body information, as it's not supported by the OpenAPI tool.",
DiagnosticSeverity.WARNING);

private final String code;
private final String description;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.ballerina.openapi.converter.diagnostic.IncompatibleResourceDiagnostic;
import io.ballerina.openapi.converter.diagnostic.OpenAPIConverterDiagnostic;
import io.ballerina.openapi.converter.utils.ConverterCommonUtils;
import io.ballerina.tools.diagnostics.DiagnosticSeverity;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
Expand Down Expand Up @@ -215,8 +216,12 @@ private Optional<OperationAdaptor> convertResourceToOperation(FunctionDefinition
openAPIParameterMapper.getResourceInputs(components, semanticModel);
if (openAPIParameterMapper.getErrors().size() > 1 || (openAPIParameterMapper.getErrors().size() == 1 &&
!openAPIParameterMapper.getErrors().get(0).getCode().equals("OAS_CONVERTOR_113"))) {
errors.addAll(openAPIParameterMapper.getErrors());
return Optional.empty();
boolean isErrorIncluded = openAPIParameterMapper.getErrors().stream().anyMatch(d ->
DiagnosticSeverity.ERROR.equals(d.getDiagnosticSeverity()));
if (isErrorIncluded) {
errors.addAll(openAPIParameterMapper.getErrors());
return Optional.empty();
}
}
errors.addAll(openAPIParameterMapper.getErrors());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ public void testForServiceConfigOnlyWithCors() {
compareWithGeneratedFile(ballerinaFilePath, "service_config_with_cors.yaml");
}

@Test(description = "Generate OpenAPI spec for request body with union type")
public void testForUnionTypeRequestBody() {
Path ballerinaFilePath = RES_DIR.resolve("request_body/union_type.bal");
compareWithGeneratedFile(ballerinaFilePath, "union_type.yaml");
}

@AfterMethod
public void cleanUp() {
deleteDirectory(this.tempDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,18 @@ public void testsRefParamsInOpenAPIV31() throws IOException, BallerinaOpenApiExc
CommonTestFunctions.compareGeneratedSyntaxTreewithExpectedSyntaxTree(
"parameter_with_ref_v31.bal", syntaxTree);
}
}

@Test(description = "Tests for path segments has parameters with extension")
public void testsForPathSegmentHasExtensionType() throws IOException, BallerinaOpenApiException {
Path definitionPath = RES_DIR.resolve("swagger/multiPathParamWithExtensionType.yaml");
OpenAPI openAPI = GeneratorUtils.getOpenAPIFromOpenAPIV3Parser(definitionPath);
OASServiceMetadata oasServiceMetadata = new OASServiceMetadata.Builder()
.withOpenAPI(openAPI)
.withFilters(filter)
.build();
BallerinaServiceGenerator ballerinaServiceGenerator = new BallerinaServiceGenerator(oasServiceMetadata);
syntaxTree = ballerinaServiceGenerator.generateSyntaxTree();
CommonTestFunctions.compareGeneratedSyntaxTreewithExpectedSyntaxTree(
"multiPathParamWithExtensionType.bal", syntaxTree);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
openapi: 3.0.1
info:
title: PayloadV
version: 0.0.0
servers:
- url: "{server}:{port}/payloadV"
variables:
server:
default: http://localhost
port:
default: "0"
paths:
/path:
post:
operationId: postPath
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ABC'
responses:
"202":
description: Accepted
/path1:
post:
operationId: postPath1
responses:
"202":
description: Accepted
/path2:
post:
operationId: postPath2
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ABC'
application/xml:
schema: {}
responses:
"202":
description: Accepted
/path3:
post:
operationId: postPath3
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ABC'
- $ref: '#/components/schemas/Remote'
application/xml:
schema: {}
responses:
"202":
description: Accepted
/path4:
post:
operationId: postPath4
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ABC'
text/plain:
schema:
type: string
application/xml:
schema: {}
responses:
"202":
description: Accepted
/path5:
post:
operationId: postPath5
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ABC'
- type: integer
format: int64
responses:
"202":
description: Accepted
/path6:
post:
operationId: postPath6
requestBody:
content:
application/json:
schema:
type: integer
format: int64
text/plain:
schema:
type: string
responses:
"202":
description: Accepted
/path7:
post:
operationId: postPath7
requestBody:
content:
application/json:
schema:
oneOf:
- type: object
additionalProperties: {}
- type: array
items:
type: integer
format: int64
responses:
"202":
description: Accepted
/path8:
post:
operationId: postPath8
requestBody:
content:
application/json:
schema:
type: object
additionalProperties:
type: integer
format: int64
text/plain:
schema:
type: string
responses:
"202":
description: Accepted
/path9:
post:
operationId: postPath9
requestBody:
content:
application/json:
schema:
oneOf:
- type: object
additionalProperties:
type: integer
format: int64
- type: object
additionalProperties:
type: string
responses:
"202":
description: Accepted
components:
schemas:
ABC:
required:
- id
- name
type: object
properties:
id:
type: integer
format: int64
name:
type: string
Remote:
required:
- host
- ip
- port
type: object
properties:
host:
type: string
port:
type: integer
format: int64
ip:
type: string
description: Presents a read-only view of the remote address.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import ballerina/http;

public type ABC record {
int id;
string name;
};
type UnionType ABC|xml;

service /payloadV on new http:Listener(0) {
resource function post path(ABC? payload) {
}
//This needs to be fixed with separated PR
resource function post path1(UnionType payload) {
}
resource function post path2(ABC|xml payload) {
}
resource function post path3(ABC|http:Remote|xml? payload) {
}
resource function post path4(@http:Payload ABC|string|xml payload) {
}
//oneOF- scenarios for application/json
resource function post path5(@http:Payload ABC|int payload) {
}
resource function post path6(@http:Payload int|string payload) {
}
resource function post path7(@http:Payload map<json>|int[] payload) {
}
resource function post path8(@http:Payload map<int>|string payload) {
}
resource function post path9(@http:Payload map<int>|map<string> payload) {
}

// //negative - skip
// resource function post path10(ABC|string payload) {
// }
// resource function post path11(int|string payload) {
// }
// resource function post path12(map<int>|string payload) {
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ballerina/http;

listener http:Listener ep0 = new (80, config = {host: "petstore.openapi.io"});

service /v1 on ep0 {
# Info for a specific pet
#
# + spreadsheetId - The id of the pet to retrieve
# + sheetidCopyto - The id of the pet to retrieve
# + return - returns can be any of following types
# http:Ok (Expected response to a valid request)
# http:Response (unexpected error)
resource function get v4/spreadsheets/[int spreadsheetId]/sheets/[string sheetidCopyto]() returns http:Ok|http:Response|error {
if !sheetidCopyto.endsWith(":copyTo") {
return error("bad URL");
}
string sheetId = sheetidCopyto.substring(0, sheetidCopyto.length() - 6);
}
# Get the details of the specified field
#
# + idJson - Field ID
# + return - Successful response
resource function get 'field/[string idJson]() returns http:Ok|error {
if !idJson.endsWith(".json") {
return error("bad URL");
}
string id = idJson.substring(0, idJson.length() - 4);
}
}
Loading