diff --git a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java index c915afa38..0c4786e53 100644 --- a/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java +++ b/openapi-integration-tests/src/test/java/io/ballerina/openapi/cmd/BallerinaToOpenAPITests.java @@ -209,6 +209,13 @@ public void openapiServiceConfigForServiceContractType() throws IOException, Int "project_openapi_info_with_service_contract_type/result.yaml", true); } + @Test(description = "Generate openapi for service contract type with resourceInfo annotation") + public void openapiResourceConfigForServiceContractType() throws IOException, InterruptedException { + executeCommand("project_resource_info_with_service_contract_type/service_file.bal", + "v1_openapi.yaml", + "project_resource_info_with_service_contract_type/result.yaml", true); + } + @AfterClass public void cleanUp() throws IOException { TestUtil.cleanDistribution(); diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/result.yaml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/result.yaml new file mode 100644 index 000000000..449a62736 --- /dev/null +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/result.yaml @@ -0,0 +1,83 @@ +openapi: 3.0.1 +info: + title: V1 + version: 2.0.0 +servers: + - url: "http://{server}:{port}/v1" + variables: + server: + default: localhost + port: + default: "8080" +paths: + /user: + post: + tags: + - user + operationId: postUser + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + examples: + user01: + value: + id: "123" + name: Jessica + required: true + responses: + "201": + description: Created + content: + application/json: + schema: + $ref: '#/components/schemas/User' + examples: + Jessica: + value: + id: "123" + name: Jessica + "400": + description: BadRequest + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorPayload' +components: + schemas: + 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 + User: + required: + - id + - name + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + additionalProperties: false diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/service_file.bal b/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/service_file.bal new file mode 100644 index 000000000..8d172aee0 --- /dev/null +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_resource_info_with_service_contract_type/service_file.bal @@ -0,0 +1,58 @@ +// 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; + +@http:ServiceConfig {basePath: "/v1"} +type OASServiceType service object { + *http:ServiceContract; + @openapi:ResourceInfo { + tags: ["user"], + examples: { + response: { + "201": { + "examples": { + "application/json": { + "Jessica": { + "value": { + "id" : "123", + "name": "Jessica" + } + } + } + } + } + }, + requestBody: { + "application/json": { + "user01": { + "value": { + "id": "123", + "name": "Jessica" + } + } + } + } + } + } + resource function post user(User user) returns User; +}; + +public type User record {| + int id; + string name; +|};