Skip to content

Commit

Permalink
Add negative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Nov 7, 2024
1 parent 39680e2 commit 64292fc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ public void testForExamplesHasCompilerErrorse() throws IOException, InterruptedE
assertOnErrorStream(process, out);
}

@Test(description = "Generate with openapi serviceConfig annotation to service contract type " +
"and service declaration")
public void openapiServiceConfigForServiceContractTypeWithServiceDeclaration() throws IOException,
InterruptedException {
String balFilePath = "project_openapi_info_with_service_contract_type_and_declaration/service_file.bal";
List<String> buildArgs = new LinkedList<>();
buildArgs.add(0, "openapi");
buildArgs.add("-i");
buildArgs.add(balFilePath);
buildArgs.add("-o");
buildArgs.add(tmpDir.toString());

Process process = getProcess(buildArgs, TEST_RESOURCE);
//Thread for wait out put generate
Thread.sleep(5000);
// compare generated file has not included constraint annotation for scenario record field.
Assert.assertTrue(Files.exists(TEST_RESOURCE.resolve("service_contract_openapi.yaml")));
Assert.assertTrue(Files.exists(TEST_RESOURCE.resolve("v1_openapi.yaml")));
process.waitFor();
}

@AfterClass
public void cleanUp() throws IOException {
TestUtil.cleanDistribution();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org= "ballerina"
name= "openapi_service_contract"
version= "2.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
openapi: 3.0.1
info:
title: Pet Store
description: API system description
termsOfService: http://mock-api-doc
contact:
name: sumudu
url: http://mock-api-contact
email: [email protected]
license:
name: ABC
url: http://abc.com
version: 1.0.0
servers:
- url: "http://{server}:{port}/v1"
variables:
server:
default: localhost
port:
default: "8080"
paths:
/users:
get:
operationId: getUsers
responses:
"200":
description: Ok
content:
application/json:
schema:
type: array
items:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/http;
import ballerina/openapi;

@openapi:ServiceInfo {
version: "1.0.0",
title: "Pet store",
description: "API system description",
email: "[email protected]",
contactName: "sumudu",
contactURL: "http://mock-api-contact",
termsOfService: "http://mock-api-doc",
licenseName: "ABC",
licenseURL: "http://abc.com"
}
@http:ServiceConfig {basePath: "/v1"}
type OASServiceType service object {
*http:ServiceContract;
resource function get users() returns string[];
};

0 comments on commit 64292fc

Please sign in to comment.