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

[master]Add OAS meta info mapping and example mapping #1731

Merged
merged 11 commits into from
Jun 20, 2024

Conversation

lnash94
Copy link
Member

@lnash94 lnash94 commented Jun 19, 2024

Purpose

Meta info Mapping

Fixes #ballerina-platform/ballerina-library#6621

Introduced below fields for the openAPI service annotation for spec generation

public type ServiceInformation record {|
    ...
    string email?;
    string description?;
    string contactName?;
    string contactURL?;
    string termsOfService?;
    string licenseName?;
    string licenseURL?;
|};

Generated openapi spec

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: sumudu@abc.com
  license:
    name: ABC
    url: http://abc.com

Example Mapping

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

Related PRs:
#1717
#1718
#1722

@lnash94 lnash94 changed the title [master]Add OpenAPI resource annotation for the mapping example details into OAS [master]Add OAS meta info mapping and example mapping Jun 20, 2024
@lnash94 lnash94 marked this pull request as ready for review June 20, 2024 05:26
Copy link
Contributor

@TharmiganK TharmiganK left a comment

Choose a reason for hiding this comment

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

LGTM

@lnash94 lnash94 merged commit 6bcffcb into ballerina-platform:master Jun 20, 2024
3 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
2 participants