handleSwaggerExampleRequest(
    transaction, methodValue, transitionParams, resourceParams,
    requestContentType, responseContentType, contentTypeFromProduces
  ) {
    let contentType = requestContentType;
    const { request } = transaction;

    this.withPath(() => {
      const consumeIsJson = contentType && isJsonContentType(contentType);
      const consumeIsMultipartFormData = contentType && isMultiPartFormData(contentType);

      if (consumeIsMultipartFormData && !hasBoundary(contentType)) {
        // When multipart/form-data conntent type doesn't have a boundary
        // add a default one `BOUNDARY` which hopefully isn't found
        // in an example content. `parseBoundary` will provide the default.
        contentType += `; boundary=${parseBoundary(contentType)}`;
      }

      if (contentType) {
        pushHeader('Content-Type', contentType, request, this, 'consumes-content-type');
      }

      if (responseContentType) {
        if (contentTypeFromProduces) {
          pushHeader('Accept', responseContentType, request, this, 'produces-accept');
        } else {
          pushHeader('Accept', responseContentType, request, this);
        }
      }

      const formParams = [];
      let formParamsSchema = { type: 'object', properties: {}, required: [] };

      const parametersGenerator = {};

      _.forEach([
        [resourceParams, '..'],
        [transitionParams, '.'],
      ], (parameters) => {
        _.forEach(parameters[0], (param, index) => {
          switch (param.in) {
            case 'header':
              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                pushHeaderObject(param.name, param, request, this);
              }));
              break;

            case 'body': {
              let bodyIsPrimitive = false;

              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                if (param['x-example']) {
                  this.withPath('x-example', () => {
                    this.createAnnotation(
                      annotations.VALIDATION_ERROR, this.path,
                      'The \'x-example\' property isn\'t allowed for body parameters - use \'schema.example\' instead'
                    );
                  });
                }

                if (param.schema) {
                  if (param.schema.format === 'binary') {
                    return;
                  }

                  bodyIsPrimitive = (param.schema.type && ['string', 'boolean', 'number'].includes(param.schema.type));
                }

                this.withPath('schema', () => {
                  const pushBody = (consumeIsJson
                      || (bodyIsPrimitive && isTextContentType(contentType)));
                  this.pushAssets(param.schema, request, contentType, pushBody);
                });
              }));
              break;
            }

            case 'formData':
              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                this.formDataParameterCheck(param);
                formParamsSchema = bodyFromFormParameter(param, formParamsSchema);
                const member = this.convertParameterToMember(param);
                formParams.push(member);
              }));
              break;

            default:
          }
        });
      });

      _.forEach(parametersGenerator, (paramType) => {
        _.forEach(paramType, (invoke) => {
          invoke();
        });
      });

      if (!contentType || consumeIsMultipartFormData || isFormURLEncoded(contentType)) {
        this.generateFormParameters(formParams, formParamsSchema, request, contentType);
      }

      // Using form parameters instead of body? We will convert those to
      // data structures and will generate form-urlencoded body.
      return request;
    });
  }
// Convert a Swagger example into a Refract request.
Convert a Swagger example into a Refract request.
Convert a Swagger example into a Refract request .
handleSwaggerExampleRequest(
    transaction, methodValue, transitionParams, resourceParams,
    requestContentType, responseContentType, contentTypeFromProduces
  ) {
    let contentType = requestContentType;
    const { request } = transaction;
    this.withPath(() => {
      const consumeIsJson = contentType && isJsonContentType(contentType);
      const consumeIsMultipartFormData = contentType && isMultiPartFormData(contentType);
      if (consumeIsMultipartFormData && !hasBoundary(contentType)) {
        contentType += `; boundary=${parseBoundary(contentType)}`;
      }
      if (contentType) {
        pushHeader('Content-Type', contentType, request, this, 'consumes-content-type');
      }
      if (responseContentType) {
        if (contentTypeFromProduces) {
          pushHeader('Accept', responseContentType, request, this, 'produces-accept');
        } else {
          pushHeader('Accept', responseContentType, request, this);
        }
      }
      const formParams = [];
      let formParamsSchema = { type: 'object', properties: {}, required: [] };
      const parametersGenerator = {};
      _.forEach([
        [resourceParams, '..'],
        [transitionParams, '.'],
      ], (parameters) => {
        _.forEach(parameters[0], (param, index) => {
          switch (param.in) {
            case 'header':
              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                pushHeaderObject(param.name, param, request, this);
              }));
              break;
            case 'body': {
              let bodyIsPrimitive = false;
              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                if (param['x-example']) {
                  this.withPath('x-example', () => {
                    this.createAnnotation(
                      annotations.VALIDATION_ERROR, this.path,
                      'The \'x-example\' property isn\'t allowed for body parameters - use \'schema.example\' instead'
                    );
                  });
                }
                if (param.schema) {
                  if (param.schema.format === 'binary') {
                    return;
                  }
                  bodyIsPrimitive = (param.schema.type && ['string', 'boolean', 'number'].includes(param.schema.type));
                }
                this.withPath('schema', () => {
                  const pushBody = (consumeIsJson
                      || (bodyIsPrimitive && isTextContentType(contentType)));
                  this.pushAssets(param.schema, request, contentType, pushBody);
                });
              }));
              break;
            }
            case 'formData':
              _.set(parametersGenerator, [param.in, param.name], _.bind(this.withPath, this, parameters[1], 'parameters', index, () => {
                this.formDataParameterCheck(param);
                formParamsSchema = bodyFromFormParameter(param, formParamsSchema);
                const member = this.convertParameterToMember(param);
                formParams.push(member);
              }));
              break;
            default:
          }
        });
      });
      _.forEach(parametersGenerator, (paramType) => {
        _.forEach(paramType, (invoke) => {
          invoke();
        });
      });
      if (!contentType || consumeIsMultipartFormData || isFormURLEncoded(contentType)) {
        this.generateFormParameters(formParams, formParamsSchema, request, contentType);
      }
      return request;
    });
  }
handleSwaggerExampleRequest ( transaction , methodValue , transitionParams , resourceParams , requestContentType , responseContentType , contentTypeFromProduces ) { let contentType = requestContentType ; const { request } = transaction ; this . withPath ( ( ) => { const consumeIsJson = contentType && isJsonContentType ( contentType ) ; const consumeIsMultipartFormData = contentType && isMultiPartFormData ( contentType ) ; if ( consumeIsMultipartFormData && ! hasBoundary ( contentType ) ) { contentType += ` ${ parseBoundary ( contentType ) } ` ; } if ( contentType ) { pushHeader ( 'Content-Type' , contentType , request , this , 'consumes-content-type' ) ; } if ( responseContentType ) { if ( contentTypeFromProduces ) { pushHeader ( 'Accept' , responseContentType , request , this , 'produces-accept' ) ; } else { pushHeader ( 'Accept' , responseContentType , request , this ) ; } } const formParams = [ ] ; let formParamsSchema = { type : 'object' , properties : { } , required : [ ] } ; const parametersGenerator = { } ; _ . forEach ( [ [ resourceParams , '..' ] , [ transitionParams , '.' ] , ] , ( parameters ) => { _ . forEach ( parameters [ 0 ] , ( param , index ) => { switch ( param . in ) { case 'header' : _ . set ( parametersGenerator , [ param . in , param . name ] , _ . bind ( this . withPath , this , parameters [ 1 ] , 'parameters' , index , ( ) => { pushHeaderObject ( param . name , param , request , this ) ; } ) ) ; break ; case 'body' : { let bodyIsPrimitive = false ; _ . set ( parametersGenerator , [ param . in , param . name ] , _ . bind ( this . withPath , this , parameters [ 1 ] , 'parameters' , index , ( ) => { if ( param [ 'x-example' ] ) { this . withPath ( 'x-example' , ( ) => { this . createAnnotation ( annotations . VALIDATION_ERROR , this . path , 'The \'x-example\' property isn\'t allowed for body parameters - use \'schema.example\' instead' ) ; } ) ; } if ( param . schema ) { if ( param . schema . format === 'binary' ) { return ; } bodyIsPrimitive = ( param . schema . type && [ 'string' , 'boolean' , 'number' ] . includes ( param . schema . type ) ) ; } this . withPath ( 'schema' , ( ) => { const pushBody = ( consumeIsJson || ( bodyIsPrimitive && isTextContentType ( contentType ) ) ) ; this . pushAssets ( param . schema , request , contentType , pushBody ) ; } ) ; } ) ) ; break ; } case 'formData' : _ . set ( parametersGenerator , [ param . in , param . name ] , _ . bind ( this . withPath , this , parameters [ 1 ] , 'parameters' , index , ( ) => { this . formDataParameterCheck ( param ) ; formParamsSchema = bodyFromFormParameter ( param , formParamsSchema ) ; const member = this . convertParameterToMember ( param ) ; formParams . push ( member ) ; } ) ) ; break ; default : } } ) ; } ) ; _ . forEach ( parametersGenerator , ( paramType ) => { _ . forEach ( paramType , ( invoke ) => { invoke ( ) ; } ) ; } ) ; if ( ! contentType || consumeIsMultipartFormData || isFormURLEncoded ( contentType ) ) { this . generateFormParameters ( formParams , formParamsSchema , request , contentType ) ; } return request ; } ) ; }
Convert a Swagger example into a Refract request.
Convert a Swagger example into a Refract request .
// When multipart/form-data conntent type doesn't have a boundary // add a default one `BOUNDARY` which hopefully isn't found // in an example content. `parseBoundary` will provide the default. // Using form parameters instead of body? We will convert those to // data structures and will generate form-urlencoded body.