Skip to content

Commit

Permalink
test: add test for serialized strings (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchdesign authored Sep 7, 2023
1 parent b0fc029 commit c0ddbf3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/fixtures/serialization/specs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.3
info:
title: title
description: description
version: 1.0.0
components:
schemas:
Foo:
description: Foo description
type: object
properties:
one:
type: 'string'
pattern1: '([a-zA-Z\s\-'']){1,50}'
pattern2: ([a-zA-Z\s\-']){1,50}
34 changes: 34 additions & 0 deletions test/serialization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import path from 'path';
import { describe, it, expect } from 'vitest';
import { openapiToTsJsonSchema } from '../src';
import { importFresh } from './test-utils';

const fixtures = path.resolve(__dirname, 'fixtures');

describe('openapiToTsJsonSchema', async () => {
it('serializes strings as expected', async () => {
const { outputPath } = await openapiToTsJsonSchema({
openApiSchema: path.resolve(fixtures, 'serialization/specs.yaml'),
definitionPathsToGenerateFrom: ['components.schemas'],
silent: true,
});

const actual = await importFresh(
path.resolve(outputPath, 'components/schemas/Foo'),
);

const expected = {
description: 'Foo description',
type: 'object',
properties: {
one: {
type: 'string',
pattern1: "([a-zA-Z\\s\\-']){1,50}",
pattern2: "([a-zA-Z\\s\\-']){1,50}",
},
},
};

expect(actual.default).toEqual(expected);
});
});

0 comments on commit c0ddbf3

Please sign in to comment.