Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 555011d

Browse files
committed
fix(oas2): allow JSON body generation for unknown formats
1 parent 3c32334 commit 555011d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

packages/fury-adapter-swagger/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Fury Swagger Parser Changelog
22

3+
## Master
4+
5+
### Bug Fixes
6+
7+
- Support JSON Body generation when a schema contains an unknown "format".
8+
Previously this would cause a warning:
9+
10+
> Unable to generate application/json example message body out of JSON Schema
11+
312
## 0.24.1 (2019-03-05)
413

514
### Bug Fixes

packages/fury-adapter-swagger/lib/generator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { inferred } = require('./link');
77
const { isFormURLEncoded, isMultiPartFormData, parseBoundary } = require('./media-type');
88

99
faker.option({
10+
failOnInvalidFormat: false,
1011
fixedProbabilities: true,
1112
optionalsProbability: 1.0,
1213
useExamplesValue: true,

packages/fury-adapter-swagger/test/generator-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ describe('bodyFromSchema', () => {
4343
expect(asset.content).to.match(/^(19|20)[0-9]{2}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/);
4444
});
4545

46+
it('can generate a JSON value for unknown format', () => {
47+
const schema = {
48+
type: 'string',
49+
format: 'unknown',
50+
};
51+
52+
const payload = { content: [] };
53+
const asset = bodyFromSchema(schema, payload, parser, 'application/json');
54+
55+
expect(typeof asset.content).to.equal('string');
56+
expect(asset.content.length).to.be.above(0);
57+
});
58+
4659
it('limits a strings min/max length to 256', () => {
4760
const schema = {
4861
type: 'string',

0 commit comments

Comments
 (0)