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

[2.0.x] Add OpenAPI resource annotation for the mapping example details into OAS #1718

Merged
merged 3 commits into from
Jun 14, 2024

Conversation

lnash94
Copy link
Member

@lnash94 lnash94 commented Jun 13, 2024

Purpose

ballerina-platform/ballerina-library#5983
As the first phase, we only support the below attribute metadata in suggested annotation

  • operationId
  • tags
  • summary
  • examples of response

Manually tested and integration test will be added after updating http version with this fix :
ballerina-platform/module-ballerina-http#2041

// AUTO-GENERATED FILE.
// This file is auto-generated by the Ballerina OpenAPI tool.

import ballerina/http;

listener http:Listener ep0 = new (8080, config = {host: "localhost"});

service / on ep0 {
    @openapi:ResourceInfo {
        operationId: "petId",
        tags: ["pets", "food"],
       summary: "Retrieve pet",
        examples: {
            "response": {
                "200":
                    {
                    "examples": {
                        "application/json": {
                            "pet1": {
                                "value": {
                                    "name": "Rova",
                                    "age": 5
                                }
                            },
                            "pet2": {
                                "value": {
                                    "name": "Tommoy",
                                    "age": 5
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    resource function get pet() returns record {} {
        return {};
    }
}

Generated code:

...
paths:
  /pet:
    get:
      tags:
      - pets
      - food
      summary: Retrieve pet
      operationId: petId
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                type: object
                properties: {}
              examples:
                pet1:
                  value:
                    name: Rova
                    age: 5
                pet2:
                  value:
                    name: Tommoy
                    age: 5

@lnash94 lnash94 requested review from TharmiganK and removed request for hevayo and NipunaRanasinghe June 13, 2024 19:23
@lnash94 lnash94 force-pushed the 2.0.x_add_example_to_oas branch 2 times, most recently from 4dc69c0 to b55aca6 Compare June 13, 2024 19:34
lnash94 added 2 commits June 14, 2024 01:10
…-tools into 2.0.x_add_example_to_oas

# Conflicts:
#	module-ballerina-openapi/CompilerPlugin.toml
@lnash94 lnash94 force-pushed the 2.0.x_add_example_to_oas branch from b55aca6 to ce93fa5 Compare June 13, 2024 19:41
@lnash94 lnash94 changed the base branch from master to 2.0.x June 13, 2024 19:43
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@lnash94
Copy link
Member Author

lnash94 commented Jun 14, 2024

This PR fix is for the preview state. The feature will be improved with the upcoming release.

@lnash94 lnash94 merged commit b1d0410 into ballerina-platform:2.0.x Jun 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants