-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid printing duplicate null nodes
- Loading branch information
Showing
9 changed files
with
164 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hey-api/openapi-ts': patch | ||
--- | ||
|
||
fix: avoid printing duplicate null nodes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
**/.vitepress/cache | ||
**/.vitepress/dist | ||
**/test/e2e | ||
**/__snapshots__ | ||
|
||
**/CHANGELOG.md | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { readFileSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { createClient } from '../'; | ||
import type { UserConfig } from '../src/types/config'; | ||
import { getFilePaths } from './utils'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
describe('OpenAPI 3.1.0', () => { | ||
const createConfig = (userConfig: UserConfig): UserConfig => ({ | ||
client: '@hey-api/client-fetch', | ||
schemas: false, | ||
...userConfig, | ||
input: path.join( | ||
__dirname, | ||
'spec', | ||
'3.1.0', | ||
typeof userConfig.input === 'string' ? userConfig.input : '', | ||
), | ||
output: path.join( | ||
__dirname, | ||
'generated', | ||
'3.1.0', | ||
typeof userConfig.output === 'string' ? userConfig.output : '', | ||
), | ||
}); | ||
|
||
const scenarios = [ | ||
{ | ||
config: createConfig({ | ||
input: 'duplicate-null.json', | ||
output: 'duplicate-null', | ||
services: { | ||
export: false, | ||
}, | ||
}), | ||
description: 'does not generate duplicate null', | ||
}, | ||
]; | ||
|
||
it.each(scenarios)('$description', async ({ config }) => { | ||
// @ts-ignore | ||
await createClient(config); | ||
|
||
const outputPath = typeof config.output === 'string' ? config.output : ''; | ||
const filePaths = getFilePaths(outputPath); | ||
|
||
filePaths.forEach((filePath) => { | ||
const fileContent = readFileSync(filePath, 'utf-8'); | ||
expect(fileContent).toMatchFileSnapshot( | ||
path.join( | ||
__dirname, | ||
'__snapshots__', | ||
'3.1.0', | ||
filePath.slice(outputPath.length + 1), | ||
), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// This file is auto-generated by @hey-api/openapi-ts | ||
export * from './types.gen'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This file is auto-generated by @hey-api/openapi-ts | ||
|
||
export type PostTestData = { | ||
/** | ||
* should not produce duplicate null | ||
*/ | ||
body?: { | ||
weirdEnum?: ('' | (string) | null); | ||
}; | ||
}; | ||
|
||
export type $OpenApiTs = { | ||
'/test': { | ||
post: { | ||
req: PostTestData; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/test": { | ||
"post": { | ||
"requestBody": { | ||
"description": "should not produce duplicate null", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"weirdEnum": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"enum": [""] | ||
}, | ||
{ | ||
"type": "string", | ||
"nullable": true | ||
} | ||
], | ||
"nullable": true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { readdirSync, statSync } from 'node:fs'; | ||
import path from 'node:path'; | ||
|
||
export const getFilePaths = (dirPath: string): Array<string> => { | ||
let filePaths: Array<string> = []; | ||
const files = readdirSync(dirPath); | ||
|
||
for (const file of files) { | ||
const filePath = path.join(dirPath, file); | ||
const stat = statSync(filePath); | ||
|
||
if (stat.isDirectory()) { | ||
filePaths = filePaths.concat(getFilePaths(filePath)); | ||
} else { | ||
filePaths.push(filePath); | ||
} | ||
} | ||
|
||
return filePaths; | ||
}; |