diff --git a/packages/core/src/writers/schemas.ts b/packages/core/src/writers/schemas.ts index 9fbbaa461..59c175676 100644 --- a/packages/core/src/writers/schemas.ts +++ b/packages/core/src/writers/schemas.ts @@ -35,8 +35,8 @@ const getSchema = ({ return file; }; -const getPath = (path: string, name: string): string => - upath.join(path, `/${name}.ts`); +const getPath = (path: string, name: string, fileExtension: string): string => + upath.join(path, `/${name}${fileExtension}`); export const writeModelInline = (acc: string, model: string): string => acc + `${model}\n`; @@ -48,6 +48,7 @@ export const writeSchema = async ({ path, schema, target, + fileExtension, specKey, isRootKey, specsName, @@ -56,6 +57,7 @@ export const writeSchema = async ({ path: string; schema: GeneratorSchema; target: string; + fileExtension: string; specKey: string; isRootKey: boolean; specsName: Record; @@ -65,7 +67,7 @@ export const writeSchema = async ({ try { await fs.outputFile( - getPath(path, name), + getPath(path, name, fileExtension), getSchema({ schema, target, isRootKey, specsName, header, specKey }), ); } catch (e) { @@ -77,6 +79,7 @@ export const writeSchemas = async ({ schemaPath, schemas, target, + fileExtension, specKey, isRootKey, specsName, @@ -86,6 +89,7 @@ export const writeSchemas = async ({ schemaPath: string; schemas: GeneratorSchema[]; target: string; + fileExtension: string; specKey: string; isRootKey: boolean; specsName: Record; @@ -98,6 +102,7 @@ export const writeSchemas = async ({ path: schemaPath, schema, target, + fileExtension, specKey, isRootKey, specsName, @@ -107,7 +112,7 @@ export const writeSchemas = async ({ ); if (indexFiles) { - const schemaFilePath = upath.join(schemaPath, '/index.ts'); + const schemaFilePath = upath.join(schemaPath, `/index${fileExtension}`); await fs.ensureFile(schemaFilePath); // Ensure separate files are used for parallel schema writing. @@ -139,14 +144,22 @@ export const writeSchemas = async ({ const stringData = data.toString(); + const ext = fileExtension.endsWith('.ts') + ? fileExtension.slice(0, -3) + : fileExtension; + const importStatements = schemas .filter((schema) => { return ( - !stringData.includes(`export * from './${camel(schema.name)}'`) && - !stringData.includes(`export * from "./${camel(schema.name)}"`) + !stringData.includes( + `export * from './${camel(schema.name)}${ext}'`, + ) && + !stringData.includes( + `export * from "./${camel(schema.name)}${ext}"`, + ) ); }) - .map((schema) => `export * from './${camel(schema.name)}';`); + .map((schema) => `export * from './${camel(schema.name)}${ext}';`); const currentFileExports = (stringData .match(/export \* from(.*)('|")/g) diff --git a/packages/orval/src/write-specs.ts b/packages/orval/src/write-specs.ts index a5c78e099..b84bece49 100644 --- a/packages/orval/src/write-specs.ts +++ b/packages/orval/src/write-specs.ts @@ -62,6 +62,10 @@ export const writeSpecs = async ( if (output.schemas) { const rootSchemaPath = output.schemas; + const fileExtension = ['tags', 'tags-split', 'split'].includes(output.mode) + ? '.ts' + : output.fileExtension ?? '.ts'; + await Promise.all( Object.entries(schemas).map(([specKey, schemas]) => { const schemaPath = !isRootKey(specKey, target) @@ -72,6 +76,7 @@ export const writeSpecs = async ( schemaPath, schemas, target, + fileExtension, specsName, specKey, isRootKey: isRootKey(specKey, target),