-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle additionalProperties boolean in experimental parser
- Loading branch information
Showing
51 changed files
with
569 additions
and
92 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: handle additionalProperties: boolean in experimental parser |
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
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
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,71 @@ | ||
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); | ||
|
||
const VERSION = '3.0.x'; | ||
|
||
const outputDir = path.join(__dirname, 'generated', VERSION); | ||
|
||
describe(`OpenAPI ${VERSION}`, () => { | ||
const createConfig = (userConfig: UserConfig): UserConfig => ({ | ||
client: '@hey-api/client-fetch', | ||
experimentalParser: true, | ||
plugins: ['@hey-api/types'], | ||
...userConfig, | ||
input: path.join( | ||
__dirname, | ||
'spec', | ||
VERSION, | ||
typeof userConfig.input === 'string' ? userConfig.input : '', | ||
), | ||
output: path.join( | ||
outputDir, | ||
typeof userConfig.output === 'string' ? userConfig.output : '', | ||
), | ||
}); | ||
|
||
const scenarios = [ | ||
{ | ||
config: createConfig({ | ||
input: 'additional-properties-false.json', | ||
output: 'additional-properties-false', | ||
}), | ||
description: 'forbids arbitrary properties on objects', | ||
}, | ||
{ | ||
config: createConfig({ | ||
input: 'additional-properties-true.json', | ||
output: 'additional-properties-true', | ||
}), | ||
description: 'allows arbitrary properties on objects', | ||
}, | ||
]; | ||
|
||
it.each(scenarios)('$description', async ({ config }) => { | ||
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__', | ||
VERSION, | ||
filePath.slice(outputDir.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
2 changes: 2 additions & 0 deletions
2
packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-false/index.ts
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'; |
13 changes: 13 additions & 0 deletions
13
packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-false/types.gen.ts
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,13 @@ | ||
// This file is auto-generated by @hey-api/openapi-ts | ||
|
||
export type Foo = { | ||
foo: string; | ||
}; | ||
|
||
export type Bar = Foo & { | ||
[key: string]: never; | ||
}; | ||
|
||
export type Baz = Foo & { | ||
bar: string; | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-true/index.ts
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'; |
15 changes: 15 additions & 0 deletions
15
packages/openapi-ts/test/__snapshots__/3.0.x/additional-properties-true/types.gen.ts
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,15 @@ | ||
// This file is auto-generated by @hey-api/openapi-ts | ||
|
||
export type Foo = { | ||
foo: string; | ||
[key: string]: unknown | string; | ||
}; | ||
|
||
export type Bar = Foo & { | ||
[key: string]: unknown; | ||
}; | ||
|
||
export type Baz = Foo & { | ||
bar: string; | ||
[key: string]: unknown | string; | ||
}; |
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
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
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
Oops, something went wrong.