File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,9 @@ function JsonTransformStrategy(schema, value) {
130130 if ( ! value ) {
131131 return JSON . stringify ( { } ) ;
132132 }
133- return JSON . stringify ( value ) ;
133+ if ( ! schema . skip_xform ) {
134+ return JSON . stringify ( value ) ;
135+ }
134136 }
135137
136138 if ( schema . format === 'text' && value ) {
@@ -471,6 +473,7 @@ class Template {
471473 }
472474 } else if ( defType === 'object' ) {
473475 Object . assign ( newDef , items ) ;
476+ newDef . skip_xform = true ;
474477 } else if ( ! asBool ) {
475478 throw new Error ( `unsupported type for section "${ defName } ": ${ defType } ` ) ;
476479 }
Original file line number Diff line number Diff line change @@ -546,6 +546,28 @@ describe('Template class tests', function () {
546546 assert . strictEqual ( tmpl . render ( view ) , reference ) ;
547547 } ) ;
548548 } ) ;
549+ it ( 'render_section_as_object' , function ( ) {
550+ const ymldata = `
551+ contentType: application/json
552+ definitions:
553+ obj:
554+ type: object
555+ template: |-
556+ {{#obj}}{ "prop": {{prop}}}{{/obj}}
557+ ` ;
558+ const parameters = {
559+ obj : {
560+ prop : 'foo'
561+ }
562+ } ;
563+ const reference = '{\n "prop": "foo"\n}' ;
564+
565+ return Template . loadYaml ( ymldata )
566+ . then ( ( tmpl ) => {
567+ console . log ( tmpl . getParametersSchema ( ) ) ;
568+ assert . strictEqual ( tmpl . render ( parameters ) , reference ) ;
569+ } ) ;
570+ } ) ;
549571 it ( 'render_section_with_partial' , function ( ) {
550572 const ymldata = `
551573 parameters:
You can’t perform that action at this time.
0 commit comments