Skip to content

Commit

Permalink
Enable resource config annotation for service contract type
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Dec 6, 2024
1 parent 95f0235 commit 7506069
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
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,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;
|};

0 comments on commit 7506069

Please sign in to comment.