Skip to content

Commit

Permalink
Merge pull request #200 from hey-api/fix/exporting-empty-files
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos authored Apr 1, 2024
2 parents 0f50ab5 + dbd0718 commit c5559ab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-snails-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(client): do not create or export empty files
4 changes: 4 additions & 0 deletions src/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';
{{/if}}

{{#if models.length}}
{{#if @root.$config.exportModels}}
export * from './models'
{{/if}}
{{#if @root.$config.exportSchemas}}
export * from './schemas'
{{/if}}
{{/if}}
{{#if services.length}}
{{#if @root.$config.exportServices}}
export * from './services'
{{/if}}
{{/if}}
4 changes: 4 additions & 0 deletions src/utils/write/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const writeClientModels = async (
outputPath: string,
config: Config
): Promise<void> => {
// Dont create empty file
if (client.models.length === 0) {
return;
}
// Generate a file with all models
const results: string[] = [];
for (const model of client.models) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/write/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const writeClientSchemas = async (
outputPath: string,
config: Config
): Promise<void> => {
// Dont create empty file
if (client.models.length === 0) {
return;
}
// Generate file with all schemas
const results: string[] = [];
for (const model of client.models) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/write/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const writeClientServices = async (
outputPath: string,
config: Config
): Promise<void> => {
// Dont create empty file
if (client.services.length === 0) {
return;
}
// Generate file for each service.
for (const service of client.services) {
const file = path.resolve(outputPath, `${service.name}${config.postfixServices}.ts`);
Expand Down

0 comments on commit c5559ab

Please sign in to comment.