generated from stijnvanhulle/template
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chaim Lev-Ari
committed
Jan 9, 2024
1 parent
70864b4
commit d4587aa
Showing
9 changed files
with
121 additions
and
43 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
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,39 @@ | ||
definitions: | ||
enumVarNames.Type: | ||
enum: | ||
- 0 | ||
- 1 | ||
type: integer | ||
x-enum-varnames: | ||
- Pending | ||
- Received | ||
enumNames.Type: | ||
enum: | ||
- 0 | ||
- 1 | ||
x-enumNames: | ||
- Pending | ||
- Received | ||
swagger: "2.0" | ||
info: | ||
title: test | ||
version: "1.0.0" | ||
paths: | ||
/var-names: | ||
get: | ||
consumes: | ||
- application/json | ||
responses: | ||
200: | ||
description: Success | ||
schema: | ||
$ref: '#/definitions/enumVarNames.Type' | ||
/names: | ||
get: | ||
consumes: | ||
- application/json | ||
responses: | ||
200: | ||
description: Success | ||
schema: | ||
$ref: '#/definitions/enumNames.Type' |
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,33 @@ | ||
import { OasManager } from '@kubb/swagger' | ||
import { FakerGenerator } from './FakerGenerator' | ||
import path from 'node:path' | ||
import { mockedPluginManager } from '@kubb/core/mocks' | ||
import type { OasTypes } from '@kubb/swagger/oas' | ||
|
||
describe('FakeGenerator enums', async () => { | ||
const schemaPath = path.resolve(__dirname, '../mocks/enums.yaml') | ||
const oas = await new OasManager().parse(schemaPath) | ||
const generator = new FakerGenerator({ | ||
dateType: 'string', | ||
mapper: {}, | ||
seed: 1, | ||
transformers: {}, | ||
}, { | ||
oas, | ||
pluginManager: mockedPluginManager, | ||
}) | ||
|
||
const schemas = oas.getDefinition().components?.schemas | ||
|
||
test('generate x-enum-varnames types', async () => { | ||
const node = generator.build({ schema: schemas?.['enumVarNames.Type'] as OasTypes.SchemaObject, baseName: 'enumVarNames' }) | ||
|
||
expect(node).toMatchSnapshot() | ||
}) | ||
|
||
test('generate x-enumNames types', async () => { | ||
const node = generator.build({ schema: schemas?.['enumNames.Type'] as OasTypes.SchemaObject, baseName: 'enumNames' }) | ||
|
||
expect(node).toMatchSnapshot() | ||
}) | ||
}) |
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
23 changes: 23 additions & 0 deletions
23
packages/swagger-faker/src/__snapshots__/FakerGenerator.test.ts.snap
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,23 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`FakeGenerator enums > generate x-enum-varnames types 1`] = ` | ||
[ | ||
" | ||
export function enumVarNames(): NonNullable<EnumVarNames> { | ||
faker.seed(1) | ||
return faker.helpers.arrayElement<any>([\`Pending\`, \`Received\`]); | ||
} | ||
", | ||
] | ||
`; | ||
exports[`FakeGenerator enums > generate x-enumNames types 1`] = ` | ||
[ | ||
" | ||
export function enumNames(): NonNullable<EnumNames> { | ||
faker.seed(1) | ||
return faker.helpers.arrayElement<any>([\`Pending\`, \`Received\`]); | ||
} | ||
", | ||
] | ||
`; |
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