Commit 8cdef059 authored by mohoff's avatar mohoff Committed by Richard Crosby

refactor: only call generateTypesFromSchema if type params are not set to false

parent 256dd142
......@@ -129,12 +129,21 @@ describe('load()', () => {
)
})
it('generates types based on schema if schema was found', () => {
it('generates types if parameters.types is not false', () => {
load(mockedParameters)
expect(generateTypeFromSchema).toHaveBeenCalledWith(mockedParameters)
})
it('skips generating types if parameters.types is false', () => {
load({
...mockedParameters,
types: false,
})
expect(generateTypeFromSchema).toHaveBeenCalledTimes(0)
})
it('skips validating config if schema was not found', () => {
mockedReadSchemaFile.mockReturnValueOnce(null)
......
......@@ -33,7 +33,9 @@ export const load = (parameters: Parameters): HydratedConfig => {
if (schemaFile !== null) {
validateJson(config, schemaFile.contents)
generateTypeFromSchema(parameters)
if (parameters.types !== false) {
generateTypeFromSchema(parameters)
}
}
return config
......
......@@ -63,15 +63,6 @@ describe('generateTypeFromSchema()', () => {
jest.clearAllMocks()
})
it('immediately returns when types=false', async () => {
await generateTypeFromSchema({
...mockedParameters,
types: false,
})
expect(mockedCompileFromFile).toHaveBeenCalledTimes(0)
})
it('calls compileFromFile with a file path', async () => {
await generateTypeFromSchema(mockedParameters)
......
......@@ -2,7 +2,7 @@ import { compileFromFile } from 'json-schema-to-typescript'
import fs from 'fs'
import R from 'ramda'
import { Parameters } from '../params'
import { Parameters, TypesParameters } from '../params'
// json-schema-to-typescript uses a `toSafeString(string)` function https://github.com/bcherny/json-schema-to-typescript/blob/f41945f19b68918e9c13885f345cb708e1d9898a/src/utils.ts#L163) to obtain a normalized string. This pascalCase mimics this functionality and should address most cases.
export const pascalCase = (input: string): string =>
......@@ -16,9 +16,8 @@ export const generateTypeFromSchema = async ({
schemaPath,
types,
}: Parameters): Promise<void> => {
if (types === false) {
return
}
// When this function is called, we are sure that types !== false
types = types as TypesParameters
const baseTypes = await compileFromFile(schemaPath)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment