ballerina-platform / ballerina-library

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

The generated type names for the headers and queries should be Ballerina friendly #6961

Closed TharmiganK closed 2 months ago

TharmiganK commented 2 months ago

Description:

When there are queries and headers for a particular operation, those are represented as record types in the client generation. The record type names are inferred from the operation id. Those auto-generated type names should be align with the Ballerina naming conventions

Identified from: https://github.com/ballerina-platform/ballerina-library/issues/6906

Steps to reproduce:

Please use the following OpenAPI specification to reproduce the issue:

openapi: 3.0.1
info:
  title: PayloadV
  version: 0.0.0
servers:
- url: "http://{server}:{port}/payloadV"
  variables:
    server:
      default: localhost
    port:
      default: "8080"
paths:
  /albums:
    get:
      operationId: Get_Albums_Id
      parameters:
      - name: q1
        in: query
        required: false
        style: form
        explode: true
        schema:
          type: string
      - name: q2
        in: query
        required: false
        style: form
        explode: true
        schema:
          type: integer
          format: int64
      - name: X-HEADER
        in: header
        required: false
        style: simple
        explode: false
        schema:
          type: string
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                type: object

The generated resource function signature:

resource isolated function get albums(Get_Albums_IdHeaders headers = {}, *Get_Albums_IdQueries queries) 
       returns record {}|error {
   ...
}

Describe your solution(s)

The names should be properly sanitized like this:

resource isolated function get albums(GetAlbumsIdHeaders headers = {}, *GetAlbumsIdQueries queries) 
       returns record {}|error {
   ...
}