ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
137 stars 58 forks source link

Data mapping ballerna openapi extension #5742

Open niveathika opened 10 months ago

niveathika commented 10 months ago

Summary

Introduce a ballerina openapi extension for simple data mapping scenarios. When creating ballerina client connectors. There can be instances where the request payload type is complex. We can add a mapping layer on top of the client to define more user-friendly types.

Goals

Introduce ballerina openapi extension to data mapping layer which can then be generated with minimal code changes.

Motivation

Even if only changes to the openapi spec is introducing only minimal additions to the code base on top of code generation

Description

requestBody:
  x-ballerina-request:
    schema:
      $ref: "#/components/schemas/EmailMessage"
  description: The message to be sent.
  content:
    application/json:
      schema:
        $ref: "#/components/schemas/Message"
responses:
  "200":
    x-ballerina-response:
      schema:
        $ref: "#/components/schemas/EmailMessage"
    content:
      application/json:
        schema:
          $ref: "#/components/schemas/Message"
    description: Successful response

With the above definition generator client can generate both EmailMessage and Message ballerina types.

Here additionally, user has to add the conversion utils. This is additional to the generated client.

Alternatives

Use a wrapper client to wrap the generated client. More information

niveathika commented 10 months ago

This is still under development as we have to sort out the issue of user giving conversion code in the definition itself. If the developer can give the mapping the entire code can be generated