hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.41k stars 106 forks source link

Pascal case option ignored when using the experimental parser #1351

Open aldirrix opened 22 hours ago

aldirrix commented 22 hours ago

Description

Our schema has camel case properties that when transformed into types using the default configuration stay with the same casing eg. a commandMsg schema results in a type inside our types.gen.ts like

export type commandMsg = {}`

Which is understandable. Since we wanted to have them with pascal case, we used the PascalCase property inside our config file for the types plugin and then we get the result we want.

Later we wanted to try the experimental parser to try some of the available features and realised that the casing is back to camel case. I'd consider this not to be the expected behavior.

our config

export default defineConfig({
  client: '@hey-api/client-fetch',
  input: './api.json',
  output: './src/api',
  experimentalParser: true,
  plugins: [
    '@hey-api/services',
    {
      name: '@hey-api/types',
      style: 'PascalCase',
    },
  ],
});

Reproducible example or configuration

No response

OpenAPI specification (optional)

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "Swagger Petstore",
    "license": {
      "name": "MIT"
    }
  },
  "servers": [
    {
      "url": "http://petstore.swagger.io/v1"
    }
  ],
  "paths": {
    "/pets": {
      "get": {
        "summary": "List all pets",
        "operationId": "listPets",
        "tags": ["pets"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "An paged array of pets",
            "headers": {
              "x-next": {
                "description": "A link to the next page of responses",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/pet"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "pet": {
        "required": ["id", "name"],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "name": {
            "type": "string"
          },
          "tag": {
            "type": "string"
          }
        }
      }
    }
  }
}

No response

System information (optional)

No response

mrlubos commented 22 hours ago

@aldirrix Currently working on this!

mrlubos commented 20 hours ago

@aldirrix to be clear, are you expecting the type names to be pascalcase, or anything inside the actual types too?

aldirrix commented 19 hours ago

@mrlubos I would expect all generated types to be pascal case, if by inside you mean like there is a nested structure eg.

imagine the following is openapi spec 😅

type1: {
  prop1: bool,
  prop2: #/schemas/someOtherType,
  prop3: string
}

Then the result would be something like

export const Type1: {
  prop1: bool,
  prop2: someOtherType,
  prop3: string
}

export const SomeOtherType: {
  someOtherProp: string
  ...
}

Does that make sense?

mrlubos commented 18 hours ago

Yep! I was asking about this but sounds like you don't want to transform the keys too

export const Type1: {
  Prop1: bool,
  Prop2: SomeOtherType,
  Prop3: string
}

export const SomeOtherType: {
  SomeOtherProp: string
  ...
}