@@ -3,7 +3,7 @@ const contentTyper = require('content-type');
33const mediaTyper = require ( 'media-typer' ) ;
44const pipeParseResult = require ( '../../pipeParseResult' ) ;
55const {
6- isExtension, hasKey, getKey, getValue,
6+ isString , isExtension, hasKey, getKey, getValue,
77} = require ( '../../predicates' ) ;
88const {
99 createWarning,
@@ -89,19 +89,28 @@ const createTextMessageBodyAsset = R.curry((namespace, mediaType, value) => {
8989 return asset ;
9090} ) ;
9191
92- function parseExample ( namespace , mediaType ) {
93- const createExampleNotJSONWarning = createWarning ( namespace ,
92+ function parseExample ( context , mediaType ) {
93+ const { namespace } = context ;
94+
95+ const createExampleNotSupportedForMediaTypeWarning = createWarning ( namespace ,
9496 `'${ name } ' 'example' is not supported for media type '${ mediaType } '` ) ;
9597
98+ const createExampleNotStringWarning = createWarning ( namespace ,
99+ `'${ name } ' 'example' should be a string for media type '${ mediaType } '` ) ;
100+
96101 const isTextBasedType = R . anyPass ( [
97102 ( ) => isTextMediaType ( mediaType ) ,
98103 ( ) => isXMLMediaType ( mediaType ) ,
99104 ] ) ;
100105
106+ const parseTextExample = pipeParseResult ( namespace ,
107+ R . unless ( isString , createExampleNotStringWarning ) ,
108+ createTextMessageBodyAsset ( namespace , mediaType ) ) ;
109+
101110 return R . compose ( R . cond ( [
102111 [ ( ) => isJSONMediaType ( mediaType ) , createJSONMessageBodyAsset ( namespace , mediaType ) ] ,
103- [ ( ) => isTextBasedType ( mediaType ) , createTextMessageBodyAsset ( namespace , mediaType ) ] ,
104- [ R . T , createExampleNotJSONWarning ] ,
112+ [ ( ) => isTextBasedType ( mediaType ) , parseTextExample ] ,
113+ [ R . T , createExampleNotSupportedForMediaTypeWarning ] ,
105114 ] ) , getValue ) ;
106115}
107116
@@ -167,7 +176,7 @@ function parseMediaTypeObject(context, MessageBodyClass, element) {
167176 createJSONMessageBodyAsset ( namespace , mediaType ) ) ;
168177
169178 const parseMember = R . cond ( [
170- [ hasKey ( 'example' ) , parseExample ( namespace , mediaType ) ] ,
179+ [ hasKey ( 'example' ) , parseExample ( context , mediaType ) ] ,
171180 [ hasKey ( 'examples' ) , R . compose ( parseExamples , getValue ) ] ,
172181 [ hasKey ( 'schema' ) , R . compose ( parseSchemaObjectOrRef ( context ) , getValue ) ] ,
173182
0 commit comments