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

Enable @openapi:ResourceInfo annotation for service contract type #1800

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion module-ballerina-openapi/annotation.bal
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public type Examples readonly & record {|
|};

# Annotation for additional OpenAPI information of a Ballerina resource function.
public const annotation ResourceInformation ResourceInfo on object function;
public const annotation ResourceInformation ResourceInfo on object function, object field;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to enable it in the object field?


# Annotation for additional OpenAPI information of a Ballerina service.
public annotation ServiceInformation ServiceInfo on service, type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org= "ballerina"
name= "service_contract"
version= "2.0.0"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
|};
Loading