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

support kebabcase request headers #23

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

spokli
Copy link
Collaborator

@spokli spokli commented Jun 19, 2023

The previous version was not able to generate types for headers in kebab-case.
Example:

  /v1/playground:
    get:
      parameters:
        - name: X-Sdk-Version
          in: header
          schema:
            type: string
          required: true

would result in the following service definition:

playAround = async (
  headerParameter: IPlayAroundHeaderParameter, 
  ...
): Promise<IPlaygroundResponse> => {
    
        const response = await http({
                method: 'GET',
                url: `${openApi.endpointUrl}/v1/playground`,
                header: {
                    'X-Sdk-Version': headerParameter.X-Sdk-Version,

The last line leads to a syntax error, due to the dashes in the parameter name.

Similar for the type generation of IPlayAroundHeaderParameter. The parameter name with dashes is not valid javascript code:

export interface IPlayAroundHeaderParameter {
    X-Sdk-Version: string;
}

An easy fix would be to add ' ' around the parameter names. However, the parameter names should follow the general code style and be in camelCase. It's also not a solution to convert the header parameter to camelCase and forget about its original name, because the original name is required in the header definition. Hence, this PR generates the code like this:

playAround = async (
 headerParameter: IPlayAroundHeaderParameter, 
 ...
): Promise<IPlaygroundResponse> => {
   
       const response = await http({
               method: 'GET',
               url: `${openApi.endpointUrl}/v1/playground`,
               header: {
                   'X-Sdk-Version': headerParameter.xSdkVersion,

In the last line, we keep the original name of the parameter for the HTTP request, but the attribute of headerParameter is in camelCase.
Similar in the interface:

export interface IPlayAroundHeaderParameter {
    xSdkVersion: string;
}

The changes are backwards-compatible. Parameters that were in camelCase before are still handled the same.

@spokli spokli requested review from Mansi1 and kyr0 June 19, 2023 07:26
@spokli spokli merged commit 3eafce4 into master Aug 23, 2023
4 checks passed
@spokli spokli deleted the feature/support-kebabcase-request-headers branch August 23, 2023 06:10
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.

1 participant