Skip to content

Commit

Permalink
fix: schema faker fix (#195)
Browse files Browse the repository at this point in the history
* fix: SL-2036 deep clone schema for json-schema-faker

* test: SL-2036 added test
  • Loading branch information
karol-maciaszek committed Mar 14, 2019
1 parent 2462ce6 commit 5889cc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IExampleGenerator } from './IExampleGenerator';

export class JSONSchemaExampleGenerator implements IExampleGenerator<any> {
public async generate(schema: any, mediaType: string): Promise<string> {
const example = await jsf.resolve(schema);
const example = await jsf.resolve(JSON.parse(JSON.stringify(schema)));
return this.transform(mediaType, example);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,25 @@ describe('JSONSchemaExampleGenerator', () => {
});

it('fails when media type is unknown', async () => {
expect(
return expect(
jsonSchemaExampleGenerator.generate({}, 'non-existing/media-type')
).rejects.toThrowErrorMatchingSnapshot();
});

it('operates on sealed schema objects', async () => {
const schema = {
type: 'object',
properties: {
name: { type: 'string' },
},
required: ['name'],
};

Object.defineProperty(schema.properties, 'name', { writable: false });

return expect(
jsonSchemaExampleGenerator.generate(schema, 'application/json')
).resolves.toBeTruthy();
});
});
});

0 comments on commit 5889cc7

Please sign in to comment.