openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

add camelcase option to schema type generation

Open MbBrainz opened this issue 1 year ago • 1 comments

This pr is regarding the implementation of the feature request in this issue: https://github.com/fabien0102/openapi-codegen/issues/213

This pr adds the following features:

  • optional config parameter useCamelCasedProps
  • camelcasing of schema type parameters.

The new config param useCamelCasedProps has the following effect on the schema:

    const schema: SchemaObject = {
      type: "object",
      properties: {
        ["foo_bar"]: {
          type: "string",
        },
      },
    };

// resulting type for `useCamelCasedProps == false` (as usual)
export type Test = {
          foo_bar?: string;
}

// resulting type for `useCamelCasedProps == true` with the new addition
export type Test = {
          fooBar?: string;
}

This pr is still in DRAFT because:

With the current state of this pr the fetchers will fail to get parse the received json correctly, as the received data will be in snake_case and the types to cast to would be in camelCase. A solution to make this work, would be a configurable adjustment to the fetcher template (./plugins/typescript/src/core/templates/fetcher.ts) that applies camelCase to incoming request data and that applies snake_case to outgoing data. (exact implementation is still to be figured out)

@fabien0102 Please let me know whether you would be interested in having this feature added, and if so i can try to spend the additional time needed to make this work. Any tips/comments/improvements are very welcome!

MbBrainz avatar Jan 05 '24 10:01 MbBrainz

@fb55 @fabien0102 @micha-f What do you think about this feature

MbBrainz avatar Apr 19 '24 08:04 MbBrainz