Code-Hex/graphql-codegen-typescript-validation-schema

Support yup enums with any naming conventions (EnumName.ENUM_VALUE)

milan-wisdom opened this issue · 1 comments

I modified the casing of the GraphQL-generated enums to follow EnumName.ENUM_VALUE. When I run typescript-validation-schema to generate the schemas, it always defaults to the original EnumName.EnumValue casing.

My codegen

generates:
  types.ts:
    plugins:
      - 'typescript'
    config:
      namingConvention:
        enumValues: 'change-case-all#upperCase'
  validation.ts:
    plugins:
      - 'typescript-validation-schema'
    config:
      importFrom: ./types
      schema: yup

The outcome of this is the following generated files:

// types.ts
export enum SortDirection {
  ASC = 'ASC',
  DESC = 'DESC'
}
// validation.ts
import * as yup from 'yup'
import { SortDirectionSchema } from './types'

export const SortDirectionSchema = yup.string<SortDirection>().oneOf([SortDirection.Asc, SortDirection.Desc]).defined();

However, if the generator would create the following valid yup schema, the casing of the enum values would be irrelevant.

// validation.ts
import * as yup from 'yup'
import { SortDirectionSchema } from './types'

export const SortDirectionSchema = yup.string<SortDirection>().oneOf(Object.values(SortDirection)).defined();

Reference discussion: jquense/yup#1013

@milan-wisdom Thanks for your report!
I fixed this issue in v0.13.0!