convertParameterToElement(parameter, setAttributes = false) {
    const { Array: ArrayElement, Enum: EnumElement } = this.namespace.elements;

    const Type = this.typeForParameter(parameter);
    const schema = this.schemaForParameterValue(parameter);

    let element = new Type();

    if (parameter['x-example'] !== undefined) {
      this.withPath('x-example', () => {
        const value = this.convertValueToElement(parameter['x-example'], schema);

        if (value) {
          if (parameter.enum) {
            value.attributes.set('typeAttributes', ['fixed']);
          }

          element = value;
        }
      });
    }

    if (parameter.enum) {
      const enumerations = new ArrayElement();

      parameter.enum.forEach((value, index) => {
        this.withPath('enum', index, () => {
          const enumeration = this.convertValueToElement(value, schema);

          if (enumeration) {
            enumeration.attributes.set('typeAttributes', ['fixed']);
            enumerations.push(enumeration);
          }
        });
      });


      if (enumerations.length > 0) {
        // We should only wrap the existing element in an enumeration
        // iff there was valid enumeations. When there is enuerations
        // and they are all invalid, let's discard the enumeration.
        // The user already got a warning about it which is
        // raised from `convertValueToElement`.

        if (element.toValue()) {
          element = new EnumElement(element);
        } else {
          element = new EnumElement();
        }

        element.enumerations = enumerations;
      }
    }

    if (parameter.default) {
      this.withPath('default', () => {
        let value = this.convertValueToElement(parameter.default, schema);

        if (value) {
          if (parameter.enum) {
            value.attributes.set('typeAttributes', ['fixed']);
            value = new EnumElement(value);
          }

          element.attributes.set('default', value);
        }
      });
    }

    if (parameter.type === 'array' && parameter.items && parameter.items.type && element.content.length === 0) {
      this.withPath('items', () => {
        element.content = [this.convertParameterToElement(parameter.items, true)];
      });
    }

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

    if (setAttributes) {
      if (parameter.description) {
        element.description = parameter.description;

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

      if (parameter.required) {
        element.attributes.set('typeAttributes', ['required']);
      }
    }

    return element;
  }
// Convert a Swagger parameter into a Refract element.
Convert a Swagger parameter into a Refract element.
Convert a Swagger parameter into a Refract element .
convertParameterToElement(parameter, setAttributes = false) {
    const { Array: ArrayElement, Enum: EnumElement } = this.namespace.elements;
    const Type = this.typeForParameter(parameter);
    const schema = this.schemaForParameterValue(parameter);
    let element = new Type();
    if (parameter['x-example'] !== undefined) {
      this.withPath('x-example', () => {
        const value = this.convertValueToElement(parameter['x-example'], schema);
        if (value) {
          if (parameter.enum) {
            value.attributes.set('typeAttributes', ['fixed']);
          }
          element = value;
        }
      });
    }
    if (parameter.enum) {
      const enumerations = new ArrayElement();
      parameter.enum.forEach((value, index) => {
        this.withPath('enum', index, () => {
          const enumeration = this.convertValueToElement(value, schema);
          if (enumeration) {
            enumeration.attributes.set('typeAttributes', ['fixed']);
            enumerations.push(enumeration);
          }
        });
      });
      if (enumerations.length > 0) {
        if (element.toValue()) {
          element = new EnumElement(element);
        } else {
          element = new EnumElement();
        }
        element.enumerations = enumerations;
      }
    }
    if (parameter.default) {
      this.withPath('default', () => {
        let value = this.convertValueToElement(parameter.default, schema);
        if (value) {
          if (parameter.enum) {
            value.attributes.set('typeAttributes', ['fixed']);
            value = new EnumElement(value);
          }
          element.attributes.set('default', value);
        }
      });
    }
    if (parameter.type === 'array' && parameter.items && parameter.items.type && element.content.length === 0) {
      this.withPath('items', () => {
        element.content = [this.convertParameterToElement(parameter.items, true)];
      });
    }
    if (this.generateSourceMap) {
      this.createSourceMap(element, this.path);
    }
    if (setAttributes) {
      if (parameter.description) {
        element.description = parameter.description;
        if (this.generateSourceMap) {
          this.createSourceMap(element.meta.get('description'), this.path.concat(['description']));
        }
      }
      if (parameter.required) {
        element.attributes.set('typeAttributes', ['required']);
      }
    }
    return element;
  }
convertParameterToElement ( parameter , setAttributes = false ) { const { Array : ArrayElement , Enum : EnumElement } = this . namespace . elements ; const Type = this . typeForParameter ( parameter ) ; const schema = this . schemaForParameterValue ( parameter ) ; let element = new Type ( ) ; if ( parameter [ 'x-example' ] !== undefined ) { this . withPath ( 'x-example' , ( ) => { const value = this . convertValueToElement ( parameter [ 'x-example' ] , schema ) ; if ( value ) { if ( parameter . enum ) { value . attributes . set ( 'typeAttributes' , [ 'fixed' ] ) ; } element = value ; } } ) ; } if ( parameter . enum ) { const enumerations = new ArrayElement ( ) ; parameter . enum . forEach ( ( value , index ) => { this . withPath ( 'enum' , index , ( ) => { const enumeration = this . convertValueToElement ( value , schema ) ; if ( enumeration ) { enumeration . attributes . set ( 'typeAttributes' , [ 'fixed' ] ) ; enumerations . push ( enumeration ) ; } } ) ; } ) ; if ( enumerations . length > 0 ) { if ( element . toValue ( ) ) { element = new EnumElement ( element ) ; } else { element = new EnumElement ( ) ; } element . enumerations = enumerations ; } } if ( parameter . default ) { this . withPath ( 'default' , ( ) => { let value = this . convertValueToElement ( parameter . default , schema ) ; if ( value ) { if ( parameter . enum ) { value . attributes . set ( 'typeAttributes' , [ 'fixed' ] ) ; value = new EnumElement ( value ) ; } element . attributes . set ( 'default' , value ) ; } } ) ; } if ( parameter . type === 'array' && parameter . items && parameter . items . type && element . content . length === 0 ) { this . withPath ( 'items' , ( ) => { element . content = [ this . convertParameterToElement ( parameter . items , true ) ] ; } ) ; } if ( this . generateSourceMap ) { this . createSourceMap ( element , this . path ) ; } if ( setAttributes ) { if ( parameter . description ) { element . description = parameter . description ; if ( this . generateSourceMap ) { this . createSourceMap ( element . meta . get ( 'description' ) , this . path . concat ( [ 'description' ] ) ) ; } } if ( parameter . required ) { element . attributes . set ( 'typeAttributes' , [ 'required' ] ) ; } } return element ; }
Convert a Swagger parameter into a Refract element.
Convert a Swagger parameter into a Refract element .
// We should only wrap the existing element in an enumeration // iff there was valid enumeations. When there is enuerations // and they are all invalid, let's discard the enumeration. // The user already got a warning about it which is // raised from `convertValueToElement`.