visitFieldType()

in lib/generator.js [1463:1503]


  visitFieldType(node, structName, fields, structMap, level) {
    let type = '', omitemptyEnable = true;
    if (node.fieldValue.fieldType === 'array') {
      type = `type:"Repeated"`;
      if (this.config.go && this.config.go.mapAndSliceWithoutOmitempty === true) {
        omitemptyEnable = false;
      }
      if (_name(node.fieldValue.fieldItemType)) {
        this.emit(`[]${this.getType(_name(node.fieldValue.fieldItemType))} `);
      } else if (node.fieldValue.fieldItemType.type === 'map') {
        this.emit(`[]`);
        this.visitType(node.fieldValue.fieldItemType);
        this.emit(` `);
      } else if (node.fieldValue.fieldItemType.type === 'modelBody') {
        structMap.push(structName);
        this.emit(`[]*${structName} `);
        fields.push(node.fieldValue);
      } else if (node.fieldValue.fieldItemType.fieldType === 'array') {
        this.emit(`[][]`);
        this.emitModelArray(node.fieldValue.fieldItemType, structMap, fields, structName);
      }
    } else if (node.fieldValue.type === 'modelBody') {
      this.emit(`*${structName} `);
      structMap.push(structName);
      fields.push(node.fieldValue);
      type = `type:"Struct"`;
    } else {
      const fieldType = node.fieldValue.fieldType;
      if (!_name(fieldType) && (fieldType === 'map' || fieldType === 'object')) {
        if (this.config.go && this.config.go.mapAndSliceWithoutOmitempty === true) {
          omitemptyEnable = false;
        }
        this.visitPointerType(node.fieldValue, level);
        this.emit(` `);
      } else {
        this.visitPointerType(fieldType, level);
        this.emit(` `);
      }
    }
    return { type, omitemptyEnable };
  }