Skip to content

Commit

Permalink
Merge branch 'master' into master_doc_update
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 authored Dec 13, 2024
2 parents 6f0d96e + 63df1bd commit 7f8ad63
Show file tree
Hide file tree
Showing 68 changed files with 4,964 additions and 216 deletions.
60 changes: 30 additions & 30 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
org.gradle.caching=true
group=io.ballerina
version=2.1.1-SNAPSHOT
version=2.2.0-SNAPSHOT

ballerinaToOpenAPIVersion=2.1.1-SNAPSHOT
ballerinaToOpenAPIVersion=2.2.0-SNAPSHOT

spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=5.4.0
releasePluginVersion=2.8.0

# Client Native Version
clientNativeVersion=1.0.1-SNAPSHOT
clientNativeVersion=1.1.0-SNAPSHOT
# Mark this as false to skip publishing the client native artifacts
clientNativePublish=false
clientNativePublish=true

#dependency
ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77
ballerinaLangVersion=2201.11.0-20241209-162400-0c015833
testngVersion=7.6.1
slf4jVersion=1.7.30
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8
Expand All @@ -29,45 +29,45 @@ puppycrawlCheckstyleVersion = 10.12.1
commonsCodecVersion=1.16.0

# Stdlib Level 01
stdlibIoVersion=1.6.2-20241112-233100-995cf5f
stdlibRegexVersion=1.4.4-20241108-130200-fcd3fce
stdlibTimeVersion=2.6.0-20241113-073800-201b904
stdlibUrlVersion=2.4.1-20241113-073900-335ff51
stdlibDataXmldataVersion=1.0.1-20241113-122800-f4e815c
stdlibIoVersion=1.7.0-20241209-171400-26de7d8
stdlibRegexVersion=1.5.0-20241122-102400-e9a90a4
stdlibTimeVersion=2.6.0-20241209-171400-4b43c7d
stdlibUrlVersion=2.5.0-20241209-171400-b09a145
stdlibDataXmldataVersion=1.2.0-20241209-175000-04587de

# Stdlib Level 02
stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5
stdlibCryptoVersion=2.7.3-20241113-081400-d015a39
stdlibLogVersion=2.10.1-20241113-120000-4577868
stdlibOsVersion=1.8.1-20241113-122000-cca973b
stdlibTaskVersion=2.5.1-20241113-123500-f905281
stdlibConstraintVersion=1.6.0-20241209-172100-2facdca
stdlibCryptoVersion=2.8.0-20241209-172100-28a92b5
stdlibLogVersion=2.11.0-20241209-174200-4ab1866
stdlibOsVersion=1.9.0-20241209-172200-af4e3f3
stdlibTaskVersion=2.6.0-20241209-172700-f6bf4fc

# Stdlib Level 03
stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf
stdlibFileVersion=1.10.1-20241113-151700-e1a2e38
stdlibMimeVersion=2.10.2-20241113-154200-d953747
stdlibUuidVersion=1.8.1-20241113-154400-443c67b
stdlibCacheVersion=3.9.0-20241209-173700-f1bd537
stdlibFileVersion=1.11.0-20241209-180600-1aa2676
stdlibMimeVersion=2.11.0-20241209-180600-aa73132
stdlibUuidVersion=1.9.0-20241209-175500-c039f34

# Stdlib Level 04
stdlibAuthVersion=2.12.1-20241113-162300-ded40eb
stdlibDataJsonDataVersion=0.3.0-20241114-143900-285d739
stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa
stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe
stdlibAuthVersion=2.13.0-20241209-180400-7e56348
stdlibDataJsonDataVersion=1.0.0-20241125-114000-0c2f457
stdlibJwtVersion=2.14.0-20241209-180600-f1a51a1
stdlibOAuth2Version=2.13.0-20241209-180800-22f19ac

# Stdlib Level 05
stdlibHttpVersion=2.13.0-20241126-143900-9551ecd
stdlibHttpVersion=2.13.0-20241209-200000-1b8535c

# Stdlib Level 06
stdlibGrpcVersion=1.13.0-20241114-195700-5188f60
stdlibWebsocketVersion=2.13.0-20241116-202000-ddd958d
stdlibWebsubVersion=2.13.0-20241114-233100-73205d6
stdlibGrpcVersion=1.13.0-20241209-205200-960b8d4
stdlibWebsocketVersion=2.13.0-20241209-205700-4bd3b42
stdlibWebsubVersion=2.13.0-20241209-204800-ddcac4b

# Stdlib Level 07
stdlibGraphqlVersion=1.15.0-20241117-164000-4d95b39
stdlibGraphqlVersion=1.15.0-20241210-134800-e896962

# Ballerinax Observer
observeVersion=1.4.0-20241113-092000-b83ae74
observeInternalVersion=1.3.1-20241113-101700-265054d
observeVersion=1.4.0-20241209-171500-9472db2
observeInternalVersion=1.4.0-20241209-172400-71fe9c4

# Enabled publishing insecure checksums, due to fail to publish to maven central
# Refer https://github.com/gradle/gradle/issues/11308
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions module-ballerina-openapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ ballerinaBuild.dependsOn checkstyleMain
ballerinaBuild.dependsOn checkstyleTest
ballerinaBuild.dependsOn jar
ballerinaBuild.finalizedBy revertTomlFile
ballerinaBuild.dependsOn test
build.dependsOn ballerinaBuild

publishToMavenLocal.dependsOn build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public class Flatten extends SubCmdBase {

private static final String ERROR_OCCURRED_WHILE_GENERATING_SCHEMA_NAMES = "ERROR: error occurred while " +
"generating schema names";
private static final String INFO_MSG_PREFIX = "Flattened";

public Flatten() {
super(CommandType.FLATTEN);
super(CommandType.FLATTEN, INFO_MSG_PREFIX);
}

public Flatten(PrintStream errorStream, boolean exitWhenFinish) {
super(CommandType.FLATTEN, errorStream, exitWhenFinish);
super(CommandType.FLATTEN, INFO_MSG_PREFIX, errorStream, exitWhenFinish);
}

@Override
Expand All @@ -67,7 +68,7 @@ public String getDefaultFileName() {

@Override
public Optional<OpenAPI> generate(String openAPIFileContent) {
Optional<OpenAPI> filteredOpenAPI = getFilteredOpenAPI(openAPIFileContent);
Optional<OpenAPI> filteredOpenAPI = getFilteredOpenAPI(openAPIFileContent, false);
if (filteredOpenAPI.isEmpty()) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
)
public class Sanitize extends SubCmdBase {

private static final String INFO_MSG_PREFIX = "Sanitized";

public Sanitize() {
super(CommandType.SANITIZE);
super(CommandType.SANITIZE, INFO_MSG_PREFIX);
}

public Sanitize(PrintStream errorStream, boolean exitWhenFinish) {
super(CommandType.SANITIZE, errorStream, exitWhenFinish);
super(CommandType.SANITIZE, INFO_MSG_PREFIX, errorStream, exitWhenFinish);
}

@Override
Expand All @@ -53,7 +55,7 @@ public String getDefaultFileName() {

@Override
public Optional<OpenAPI> generate(String openAPIFileContent) {
Optional<OpenAPI> filteredOpenAPI = getFilteredOpenAPI(openAPIFileContent);
Optional<OpenAPI> filteredOpenAPI = getFilteredOpenAPI(openAPIFileContent, true);
return filteredOpenAPI.flatMap(this::sanitizeOpenAPI);
}

Expand Down
21 changes: 13 additions & 8 deletions openapi-cli/src/main/java/io/ballerina/openapi/cmd/SubCmdBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public String getName() {
private static final String COMMAND_IDENTIFIER = "openapi-%s";
private static final String COMMA = ",";

private static final String INFO_OUTPUT_WRITTEN_MSG = "INFO: %sed OpenAPI definition file was successfully" +
private static final String INFO_OUTPUT_WRITTEN_MSG = "INFO: %s OpenAPI definition file was successfully" +
" written to: %s%n";
private static final String WARNING_INVALID_OUTPUT_FORMAT = "WARNING: invalid output format. The output format" +
" should be either \"json\" or \"yaml\".Defaulting to format of the input file";
Expand All @@ -93,7 +93,7 @@ public String getName() {
"parsing the OpenAPI definition file";
protected static final String FOUND_PARSER_DIAGNOSTICS = "found the following parser diagnostic messages:";
private static final String ERROR_OCCURRED_WHILE_WRITING_THE_OUTPUT_OPENAPI_FILE = "ERROR: error occurred while " +
"writing the %sed OpenAPI definition file%n";
"writing the %s OpenAPI definition file%n";
private static final String WARNING_SWAGGER_V2_FOUND = "WARNING: Swagger version 2.0 found in the OpenAPI " +
"definition. The generated OpenAPI definition will be in OpenAPI version 3.0.x";

Expand All @@ -103,6 +103,7 @@ public String getName() {
private Path targetPath = Paths.get(System.getProperty("user.dir"));
private boolean exitWhenFinish = true;
private final CommandType cmdType;
private final String infoMsgPrefix;

@CommandLine.Option(names = {"-h", "--help"}, hidden = true)
public boolean helpFlag;
Expand All @@ -125,14 +126,16 @@ public String getName() {
@CommandLine.Option(names = {"--operations"}, description = "Operations that need to be included when sanitizing.")
public String operations;

protected SubCmdBase(CommandType cmdType) {
protected SubCmdBase(CommandType cmdType, String infoMsgPrefix) {
this.cmdType = cmdType;
this.infoMsgPrefix = infoMsgPrefix;
}

protected SubCmdBase(CommandType cmdType, PrintStream errorStream, boolean exitWhenFinish) {
protected SubCmdBase(CommandType cmdType, String infoMsgPrefix, PrintStream errorStream, boolean exitWhenFinish) {
this.cmdType = cmdType;
this.errorStream = errorStream;
this.exitWhenFinish = exitWhenFinish;
this.infoMsgPrefix = infoMsgPrefix;
}

public void printHelpText() {
Expand Down Expand Up @@ -198,11 +201,13 @@ public Optional<OpenAPI> getFlattenOpenAPI(OpenAPI openAPI) {
return Optional.of(openAPI);
}

public Optional<OpenAPI> getFilteredOpenAPI(String openAPIFileContent) {
public Optional<OpenAPI> getFilteredOpenAPI(String openAPIFileContent, boolean enableResolver) {
// Read the contents of the file with default parser options
// Flattening will be done after filtering the operations
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(enableResolver);
SwaggerParseResult parserResult = new OpenAPIParser().readContents(openAPIFileContent, null,
new ParseOptions());
parseOptions);
if (!parserResult.getMessages().isEmpty() &&
parserResult.getMessages().contains(UNSUPPORTED_OPENAPI_VERSION_PARSER_MESSAGE)) {
errorStream.println(ERROR_UNSUPPORTED_OPENAPI_VERSION);
Expand Down Expand Up @@ -287,9 +292,9 @@ private void writeGeneratedOpenAPIFile(OpenAPI openAPI) {
try {
CodegenUtils.writeFile(targetPath.resolve(outputFileNameWithExt),
outputFileNameWithExt.endsWith(JSON_EXTENSION) ? Json.pretty(openAPI) : Yaml.pretty(openAPI));
infoStream.printf(INFO_OUTPUT_WRITTEN_MSG, cmdType.getName(), targetPath.resolve(outputFileNameWithExt));
infoStream.printf(INFO_OUTPUT_WRITTEN_MSG, infoMsgPrefix, targetPath.resolve(outputFileNameWithExt));
} catch (IOException exception) {
errorStream.printf(ERROR_OCCURRED_WHILE_WRITING_THE_OUTPUT_OPENAPI_FILE, cmdType.getName());
errorStream.printf(ERROR_OCCURRED_WHILE_WRITING_THE_OUTPUT_OPENAPI_FILE, infoMsgPrefix);
exitError();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,17 @@ public void testSanitizeCmdWithComposedSchema() throws IOException {
compareFiles(expectedFilePath, tmpDir.resolve("sanitized_openapi.json"));
}

@Test(description = "Test openapi sanitize sub command with unresolved parameter schema")
public void testSanitizeCmdWithUnresolvedParameterSchema() throws IOException {
Path expectedFilePath = resourceDir.resolve(
Paths.get("cmd/sanitize/sanitized_openapi_unresolved_expected.yaml"));
String[] args = {"-i", resourceDir + "/cmd/sanitize/openapi_unresolved.yaml", "-o", tmpDir.toString()};
Sanitize sanitize = new Sanitize();
new CommandLine(sanitize).parseArgs(args);
sanitize.execute();
compareFiles(expectedFilePath, tmpDir.resolve("sanitized_openapi.yaml"));
}

@AfterTest
public void clean() {
System.setErr(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Arrays;
import java.util.List;

import static io.ballerina.openapi.generators.common.GeneratorTestUtils.compareGeneratedSyntaxTreeWithExpectedSyntaxTree;
import static io.ballerina.openapi.generators.common.GeneratorTestUtils.getDiagnostics;

/**
Expand Down Expand Up @@ -210,6 +211,20 @@ public void testMultipartCustomBodyParts() throws IOException, BallerinaOpenApiE
Assert.assertTrue(diagnostics.isEmpty());
}

@Test(description = "Test for generating request body and utils when operation has multipart form-data " +
"media type with array")
public void testRequestBodyWithMultipartMediaArrayType() throws IOException, BallerinaOpenApiException,
ClientException {
Path expectedClientPath = RESDIR.resolve("../ballerina/multipart_formdata_array_client.bal");
Path expectedUtilsPath = RESDIR.resolve("../ballerina/multipart_formdata_array_utils.bal");
Path definitionPath = RESDIR.resolve("swagger/multipart_formdata_array.yaml");
BallerinaClientGenerator ballerinaClientGenerator = getBallerinaClientGenerator(definitionPath);
SyntaxTree clientSyntaxTree = ballerinaClientGenerator.generateSyntaxTree();
compareGeneratedSyntaxTreeWithExpectedSyntaxTree(expectedClientPath, clientSyntaxTree);
SyntaxTree utilsSyntaxTree = ballerinaClientGenerator.getBallerinaUtilGenerator().generateUtilSyntaxTree();
compareGeneratedSyntaxTreeWithExpectedSyntaxTree(expectedUtilsPath, utilsSyntaxTree);
}

private boolean checkUtil(List<String> invalidFunctionNames, SyntaxTree utilSyntaxTree) {
ModulePartNode modulePartNode = utilSyntaxTree.rootNode();
NodeList<ModuleMemberDeclarationNode> members = modulePartNode.members();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" # Enables relaxed data binding on the client side. When enabled, `nil` values are treated " +
"as optional,\n" +
" # and absent fields are handled as `nilable` types. Enabled by default.\n" +
" boolean laxDataBinding = true;\n" +
"|};";

Expand Down Expand Up @@ -216,11 +214,9 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" # Enables relaxed data binding on the client side. When enabled, `nil` values are treated " +
"as optional,\n" +
" # and absent fields are handled as `nilable` types. Enabled by default.\n" +
" boolean laxDataBinding = true;\n" +
"|};";
public static final String CONNECTION_CONFIG_MIXED_AUTH = "" +
Expand Down Expand Up @@ -260,11 +256,9 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
"Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection, \n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" # Enables relaxed data binding on the client side. When enabled, `nil` values are treated " +
"as optional,\n" +
" # and absent fields are handled as `nilable` types. Enabled by default.\n" +
" boolean laxDataBinding = true;\n" +
"|};";

Expand Down Expand Up @@ -302,11 +296,9 @@ public class TestConstants {
" # Enables the inbound payload validation functionality which provided by the constraint package. " +
" Enabled by default\n" +
" boolean validation = true;\n" +
" # Enables or disables relaxed data binding on the client side. Disabled by default.\n" +
" # When enabled, the JSON data will be projected to the Ballerina record type and during the " +
"projection,\n" +
" # nil values will be considered as optional fields and absent fields will be considered for " +
"nilable types\n" +
" # Enables relaxed data binding on the client side. When enabled, `nil` values are treated " +
"as optional,\n" +
" # and absent fields are handled as `nilable` types. Enabled by default.\n" +
" boolean laxDataBinding = true;\n" +
"|};";
public static final String OAUTH2_REFRESH_TOKEN_GRANT_CONFIG_RECORD = "#OAuth2ClientCredentialsGrantConfigs" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void testResponseWithSimpleNameReferenceReturnType() throws IOException {
compareWithGeneratedFile(ballerinaFilePath, "response/simple_name_ref.yaml");
}

@Test(description = "Test scenarios where return type is a SimpleNameReference with readonly")
@Test(description = "Test scenarios where return type is a SimpleNameReference with readonly", enabled = false)
public void testResponseWithReadOnlySimpleNameReferenceReturnType() throws IOException {
Path ballerinaFilePath = RES_DIR.resolve("response/readonly.bal");
OASContractGenerator openApiConverterUtils = new OASContractGenerator();
Expand Down Expand Up @@ -383,7 +383,7 @@ public void testNilReturnType() throws IOException {
compareWithGeneratedFile(ballerinaFilePath, "response/nil_return_type.yaml");
}

@Test(description = "When the resource has nil union type return")
@Test(description = "When the resource has nil union type return", enabled = false)
public void testNilUnionReturnType() throws IOException {
Path ballerinaFilePath = RES_DIR.resolve("response/nil_union_return_type.bal");
OASContractGenerator openApiConverterUtils = new OASContractGenerator();
Expand Down
Loading

0 comments on commit 7f8ad63

Please sign in to comment.