@@ -60,10 +60,10 @@ function rename(obj,key,newKey){
6060 }
6161}
6262
63- function checkDef ( openapi , name ) {
64- if ( ! openapi . components . schemas [ name ] ) {
65- //console.log('Forcing definition of:',name);
66- openapi . components . schemas [ name ] = { } ;
63+ function checkDef ( openapi , container ) {
64+ assert . equal ( typeof container . shape , 'string' ) ;
65+ if ( ! openapi . components . schemas [ container . shape ] ) {
66+ openapi . components . schemas [ container . shape ] = { } ;
6767 }
6868}
6969
@@ -334,7 +334,7 @@ function transformShape(openapi,shape){
334334 // use the shape.key.shape to only allow valid keys. For now we allow
335335 // any string.
336336
337- checkDef ( openapi , shape . value . shape ) ;
337+ checkDef ( openapi , shape . value ) ;
338338 delete shape . key ;
339339 delete shape . value ;
340340 }
@@ -369,9 +369,11 @@ function transformShape(openapi,shape){
369369
370370 recurse ( shape , { } , function ( obj , key , state ) {
371371 if ( key == 'shape' ) {
372- obj [ "$ref" ] = '#/components/schemas/' + obj [ key ] ;
373- checkDef ( openapi , obj [ key ] ) ;
374- delete obj [ key ] ;
372+ if ( state . pkey !== 'properties' ) {
373+ obj [ "$ref" ] = '#/components/schemas/' + obj [ key ] ;
374+ checkDef ( openapi , obj ) ;
375+ }
376+ delete obj [ key ] ; // TODO / FIXME validate this for runtime.lex.v2
375377 }
376378 if ( key == 'documentation' ) {
377379 obj . description = clean ( obj . documentation ) ;
@@ -662,7 +664,7 @@ function attachParameters(openapi, src, op, action, consumes, options) {
662664
663665 case 'json' :
664666 // All params are sent as a JSON object in the body
665- checkDef ( openapi , op . input . shape ) ;
667+ checkDef ( openapi , op . input ) ;
666668 action . requestBody = { required : true , content : { } } ;
667669 for ( let mediatype of consumes ) {
668670 action . requestBody . content [ mediatype ] = {
@@ -1001,7 +1003,7 @@ module.exports = {
10011003 success . content [ mediatype ] . schema = { } ;
10021004 success . content [ mediatype ] . schema . $ref = '#/components/schemas/' + op . output . shape ;
10031005 }
1004- checkDef ( s , op . output . shape ) ;
1006+ checkDef ( s , op . output ) ;
10051007
10061008 if ( options . examples && options . examples . examples [ op . name ] ) {
10071009 for ( var e in options . examples . examples [ op . name ] ) {
@@ -1029,7 +1031,7 @@ module.exports = {
10291031 failure . content [ mediatype ] . schema = { } ;
10301032 failure . content [ mediatype ] . schema . $ref = '#/components/schemas/' + error . shape ;
10311033 }
1032- checkDef ( s , error . shape ) ;
1034+ checkDef ( s , error ) ;
10331035 action . responses [ error . error ? error . error . httpStatusCode : defStatus ++ ] = failure ; //TODO fake statuses created. Map to combined output schema with a 'oneOf'?
10341036 }
10351037
0 commit comments