Skip to content

Commit

Permalink
Move config from transform to types
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Lucas committed Jun 13, 2024
1 parent c736133 commit 0bbddc1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/openapi-ts/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('index', () => {
dryRun: false,
input: './test/spec/v3-transforms.json',
output: './generated/v3/',
transform: {
dates: true,
types: {
dates: 'types+transform',
},
});
});
Expand Down
16 changes: 0 additions & 16 deletions packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@ const getTypes = (userConfig: ClientConfig): Config['types'] => {
return types;
};

const getTransforms = (userConfig: ClientConfig): Config['types'] => {
const transforms: Config['transform'] = {
dates: false,
...userConfig.transform,
};

return transforms;
};

const initConfigs = async (userConfig: UserConfig): Promise<Config[]> => {
const { config: configFromFile } = await loadConfig<UserConfig>({
jitiOptions: {
Expand Down Expand Up @@ -237,12 +228,6 @@ const initConfigs = async (userConfig: UserConfig): Promise<Config[]> => {
const services = getServices(userConfig);
const types = getTypes(userConfig);

const transform = getTransforms(userConfig);
if (transform.dates) {
// If transforming dates then also force the type on
types.dates = true;
}

output.path = path.resolve(process.cwd(), output.path);

return setConfig({
Expand All @@ -257,7 +242,6 @@ const initConfigs = async (userConfig: UserConfig): Promise<Config[]> => {
request,
schemas,
services,
transform,
types,
useOptions,
});
Expand Down
14 changes: 2 additions & 12 deletions packages/openapi-ts/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ export interface ClientConfig {
| string
| {
/**
* Output Date instead of string for format "date-time"
* Output Date type and possibly runtime transform instead of string for format "date-time"
* @default false
*/
dates?: boolean;
dates?: boolean | 'types+transform' | 'types';
/**
* Generate enum definitions?
* @default false
Expand All @@ -169,16 +169,6 @@ export interface ClientConfig {
*/
name?: 'PascalCase' | 'preserve';
};

/**
* Generate transforms for types?
*/
transform?: {
/**
* Transform dates strings to dates
*/
dates?: boolean;
};
/**
* Use options or arguments functions
* @deprecated
Expand Down
7 changes: 5 additions & 2 deletions packages/openapi-ts/src/utils/write/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const processType = (client: Client, model: Model, onNode: OnNode) => {

const generateTransform = (client: Client, model: Model, onNode: OnNode) => {
const config = getConfig();
if (config.transform.dates) {
if (config.types.dates === 'types+transform') {
const mapTypeToTransformStatements = (
localPath: string[],
property: Model,
Expand Down Expand Up @@ -444,7 +444,10 @@ const processServiceTypes = (client: Client, onNode: OnNode) => {
}),
});

if (config.transform.dates && responses.length === 1) {
if (
config.types.dates === 'types+transform' &&
responses.length === 1
) {
if (client.types[responses[0].type]?.hasTransformer) {
const name = operationResponseTypeName(operation.name);
const transformAlias = compiler.transform.alias({
Expand Down

0 comments on commit 0bbddc1

Please sign in to comment.