handleSwaggerExampleResponse(
    transaction, methodValue, responseValue,
    statusCode, responseBody, contentType
  ) {
    const { Asset, Copy } = this.namespace.elements;
    const { response } = transaction;

    this.withPath('responses', statusCode, () => {
      if (responseValue.description) {
        const description = new Copy(responseValue.description);
        response.content.push(description);

        if (this.generateSourceMap) {
          this.createSourceMap(description, this.path.concat(['description']));
        }
      }

      if (contentType) {
        if (responseValue.examples && responseValue.examples[contentType]) {
          this.withPath('examples', contentType, () => {
            pushHeader('Content-Type', contentType, response, this);
          });
        } else {
          pushHeader('Content-Type', contentType, response, this, 'produces-content-type');
        }
      }

      const isJsonResponse = isJsonContentType(contentType);

      if (responseValue.headers) {
        this.updateHeaders(response, responseValue.headers);
      }

      this.withPath('examples', () => {
        // Responses can have bodies
        if (responseBody !== undefined) {
          this.withPath(contentType, () => {
            let formattedResponseBody = responseBody;

            if (typeof responseBody !== 'string') {
              formattedResponseBody = JSON.stringify(responseBody, null, 2);
            }

            const bodyAsset = new Asset(formattedResponseBody);
            bodyAsset.classes.push('messageBody');

            if (this.generateSourceMap) {
              this.createSourceMap(bodyAsset, this.path);
            }

            response.content.push(bodyAsset);
          });
        }

        // Responses can have schemas in Swagger
        const exampleSchema = responseValue.examples && responseValue.examples.schema;
        const schema = responseValue.schema || exampleSchema;

        if (schema && schema.format !== 'binary') {
          let args;

          if (responseValue.examples && responseValue.examples.schema) {
            args = [5, 'examples', 'schema'];
          } else {
            args = [5, 'schema'];
          }

          this.withSlicedPath(...args.concat([() => {
            this.pushAssets(schema, response, contentType,
              isJsonResponse && responseBody === undefined);
          }]));
        }

        if (statusCode !== 'null') {
          response.statusCode = statusCode;

          if (this.generateSourceMap) {
            this.createSourceMap(response.attributes.get('statusCode'), this.path.slice(0, -1));
          }
        }
      });


      this.handleSwaggerVendorExtensions(response, responseValue);

      return response;
    });
  }
// Convert a Swagger example into a Refract response.
Convert a Swagger example into a Refract response.
Convert a Swagger example into a Refract response .
handleSwaggerExampleResponse(
    transaction, methodValue, responseValue,
    statusCode, responseBody, contentType
  ) {
    const { Asset, Copy } = this.namespace.elements;
    const { response } = transaction;
    this.withPath('responses', statusCode, () => {
      if (responseValue.description) {
        const description = new Copy(responseValue.description);
        response.content.push(description);
        if (this.generateSourceMap) {
          this.createSourceMap(description, this.path.concat(['description']));
        }
      }
      if (contentType) {
        if (responseValue.examples && responseValue.examples[contentType]) {
          this.withPath('examples', contentType, () => {
            pushHeader('Content-Type', contentType, response, this);
          });
        } else {
          pushHeader('Content-Type', contentType, response, this, 'produces-content-type');
        }
      }
      const isJsonResponse = isJsonContentType(contentType);
      if (responseValue.headers) {
        this.updateHeaders(response, responseValue.headers);
      }
      this.withPath('examples', () => {
        if (responseBody !== undefined) {
          this.withPath(contentType, () => {
            let formattedResponseBody = responseBody;
            if (typeof responseBody !== 'string') {
              formattedResponseBody = JSON.stringify(responseBody, null, 2);
            }
            const bodyAsset = new Asset(formattedResponseBody);
            bodyAsset.classes.push('messageBody');
            if (this.generateSourceMap) {
              this.createSourceMap(bodyAsset, this.path);
            }
            response.content.push(bodyAsset);
          });
        }
        const exampleSchema = responseValue.examples && responseValue.examples.schema;
        const schema = responseValue.schema || exampleSchema;
        if (schema && schema.format !== 'binary') {
          let args;
          if (responseValue.examples && responseValue.examples.schema) {
            args = [5, 'examples', 'schema'];
          } else {
            args = [5, 'schema'];
          }
          this.withSlicedPath(...args.concat([() => {
            this.pushAssets(schema, response, contentType,
              isJsonResponse && responseBody === undefined);
          }]));
        }
        if (statusCode !== 'null') {
          response.statusCode = statusCode;
          if (this.generateSourceMap) {
            this.createSourceMap(response.attributes.get('statusCode'), this.path.slice(0, -1));
          }
        }
      });
      this.handleSwaggerVendorExtensions(response, responseValue);
      return response;
    });
  }
handleSwaggerExampleResponse ( transaction , methodValue , responseValue , statusCode , responseBody , contentType ) { const { Asset , Copy } = this . namespace . elements ; const { response } = transaction ; this . withPath ( 'responses' , statusCode , ( ) => { if ( responseValue . description ) { const description = new Copy ( responseValue . description ) ; response . content . push ( description ) ; if ( this . generateSourceMap ) { this . createSourceMap ( description , this . path . concat ( [ 'description' ] ) ) ; } } if ( contentType ) { if ( responseValue . examples && responseValue . examples [ contentType ] ) { this . withPath ( 'examples' , contentType , ( ) => { pushHeader ( 'Content-Type' , contentType , response , this ) ; } ) ; } else { pushHeader ( 'Content-Type' , contentType , response , this , 'produces-content-type' ) ; } } const isJsonResponse = isJsonContentType ( contentType ) ; if ( responseValue . headers ) { this . updateHeaders ( response , responseValue . headers ) ; } this . withPath ( 'examples' , ( ) => { if ( responseBody !== undefined ) { this . withPath ( contentType , ( ) => { let formattedResponseBody = responseBody ; if ( typeof responseBody !== 'string' ) { formattedResponseBody = JSON . stringify ( responseBody , null , 2 ) ; } const bodyAsset = new Asset ( formattedResponseBody ) ; bodyAsset . classes . push ( 'messageBody' ) ; if ( this . generateSourceMap ) { this . createSourceMap ( bodyAsset , this . path ) ; } response . content . push ( bodyAsset ) ; } ) ; } const exampleSchema = responseValue . examples && responseValue . examples . schema ; const schema = responseValue . schema || exampleSchema ; if ( schema && schema . format !== 'binary' ) { let args ; if ( responseValue . examples && responseValue . examples . schema ) { args = [ 5 , 'examples' , 'schema' ] ; } else { args = [ 5 , 'schema' ] ; } this . withSlicedPath ( ... args . concat ( [ ( ) => { this . pushAssets ( schema , response , contentType , isJsonResponse && responseBody === undefined ) ; } ] ) ) ; } if ( statusCode !== 'null' ) { response . statusCode = statusCode ; if ( this . generateSourceMap ) { this . createSourceMap ( response . attributes . get ( 'statusCode' ) , this . path . slice ( 0 , - 1 ) ) ; } } } ) ; this . handleSwaggerVendorExtensions ( response , responseValue ) ; return response ; } ) ; }
Convert a Swagger example into a Refract response.
Convert a Swagger example into a Refract response .
// Responses can have bodies // Responses can have schemas in Swagger