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

Commit 5b81fab

Browse files
committed
feat(oas3): add support for generateMessageBody
1 parent 91d1b8e commit 5b81fab

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

packages/fury-adapter-oas3-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
- Support for `Server Object` and `Server Variable Object`
1010

11+
- The parser can now be configured to disable generation of example message
12+
bodies by providing an adapter option `generateMessageBody` as `false` during
13+
parse.
14+
1115
## 0.10.2 (2020-03-16)
1216

1317
### Enhancements

packages/fury-adapter-oas3-parser/lib/context.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ const State = require('./state.js');
33
class Context {
44
constructor(namespace, options) {
55
this.namespace = namespace;
6+
this.options = options || {};
67

7-
if (options === undefined) {
8-
this.options = { generateSourceMap: false };
9-
} else {
10-
this.options = options;
8+
if (this.options.generateSourceMap === undefined) {
9+
this.options.generateSourceMap = false;
10+
}
11+
12+
if (this.options.generateMessageBody === undefined) {
13+
this.options.generateMessageBody = true;
1114
}
1215

1316
this.state = new State();

packages/fury-adapter-oas3-parser/lib/parser/oas/parseMediaTypeObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function parseMediaTypeObject(context, MessageBodyClass, element) {
198198

199199
const dataStructure = mediaTypeObject.get('schema');
200200

201-
if (!messageBody && dataStructure && canGenerateMessageBodyForMediaType(mediaType)) {
201+
if (!messageBody && dataStructure && context.options.generateMessageBody && canGenerateMessageBodyForMediaType(mediaType)) {
202202
const asset = generateMessageBody(context, mediaType, dataStructure);
203203
if (asset) {
204204
message.push(asset);

packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseMediaTypeObject-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,5 +413,27 @@ describe('Media Type Object', () => {
413413
expect(message).to.be.instanceof(messageBodyClass);
414414
expect(message.messageBody).to.be.undefined;
415415
});
416+
417+
it('does not generate a messageBody asset when generateMessageBody is disabled', () => {
418+
context.options.generateMessageBody = false;
419+
420+
const mediaType = new namespace.elements.Member('application/json', {
421+
schema: {
422+
type: 'object',
423+
properties: {
424+
name: {
425+
type: 'string',
426+
example: 'doe',
427+
},
428+
},
429+
},
430+
});
431+
432+
const parseResult = parse(context, messageBodyClass, mediaType);
433+
434+
const message = parseResult.get(0);
435+
expect(message).to.be.instanceof(messageBodyClass);
436+
expect(message.messageBody).to.be.undefined;
437+
});
416438
});
417439
});

0 commit comments

Comments
 (0)