当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ProblemReporter.report方法代码示例

本文整理汇总了TypeScript中@maxxton/microdocs-core/helpers.ProblemReporter.report方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ProblemReporter.report方法的具体用法?TypeScript ProblemReporter.report怎么用?TypeScript ProblemReporter.report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@maxxton/microdocs-core/helpers.ProblemReporter的用法示例。


在下文中一共展示了ProblemReporter.report方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

 clientParams.forEach(clientParam => {
   if (producerParam.name == clientParam.name && producerParam.in == clientParam.in) {
     exists = true;
     if (!matchType(producerParam, clientParam)) {
       problemReport.report(ProblemLevels.WARNING, "Type mismatches query parameter '" + producerParam.name + "', expected: '" + producerParam.type + "', found: '" + clientParam.type + "'", clientEndpoint.controller, clientEndpoint.method);
     }
     return true;
   }
   return false;
 });
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:10,代码来源:endpoint-check.func.ts

示例2: checkPathParameters

export function checkPathParameters(clientEndpoint: Path, producerEndpoint: Path, clientProject: Project, producerProject: Project, problemReport: ProblemReporter): void {
  // match via wildcards in regexp
  var expression = '^' + producerEndpoint.path.replace(new RegExp("\/", 'g'), '\/').replace(new RegExp("\\{.*?\\}", 'g'), '(.+)') + '$';
  var clientExp = new RegExp(expression);
  var producerExp = new RegExp("\\{.*?\\}", 'g');
  var clientMatches: string[] = clientEndpoint.path.match(clientExp);
  var producerMatches: string[] = producerEndpoint.path.match(producerExp);

  if (clientMatches && producerMatches && clientMatches.length == producerMatches.length + 1 && clientMatches.length >= 1) {
    for (let i = 1; i < clientMatches.length; i++) {
      let producerParamName = producerMatches[i - 1].substr(1, producerMatches[i - 1].length - 2);
      let producerParam = getPathVariable(producerParamName, producerEndpoint);
      if (producerParam == null) {
        problemReport.report(ProblemLevels.ERROR, "path variable '" + producerParamName + "' is missing on the controller", clientEndpoint.controller, clientEndpoint.method);
      } else {
        let clientParamName = clientMatches[i];
        if (clientParamName.match(/^\{.*?\}$/)) {
          var clientParam = getPathVariable(clientParamName.substr(1, clientParamName.length - 2), clientEndpoint);
          if (clientParam == null) {
            problemReport.report(ProblemLevels.ERROR, "path variable '" + clientParamName.substr(1, clientParamName.length - 2) + "' is missing", clientEndpoint.controller, clientEndpoint.method);
          }
          if (clientParam != null && producerParam != null) {
            if (!matchType(producerParam, clientParam)) {
              problemReport.report(ProblemLevels.WARNING, "Type mismatches path variable '" + clientParamName.substr(1, clientParamName.length - 2) + "', expected: " + producerParam.type + ", found: " + clientParam.type, clientEndpoint.controller, clientEndpoint.method);
            }
          }
        } else {
          var value = clientParamName;
          switch (producerParam.type.toLowerCase()) {
            case SchemaTypes.NUMBER:
            case SchemaTypes.INTEGER:
              if (!parseInt(value)) {
                problemReport.report(ProblemLevels.WARNING, "Type mismatches path variable '" + producerParamName + "' is not a number', expected: " + producerParam.type + ", found: number", clientEndpoint.controller, clientEndpoint.method);
              }
              break;
          }
        }
      }
    }
  }
}
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:41,代码来源:endpoint-check.func.ts

示例3: ProblemReporter

            clientViews.forEach(clientView => {
              let reporter = new ProblemReporter(problemReport.getRootObject());
              problemReporters.push(reporter);

              let producerProperties = producerView.properties;
              let clientProperties = clientView.properties;

              // Check each producer properties
              if (producerProperties) {
                for (let key in producerProperties) {
                  // Find client Property by name
                  let producerProperty = producerProperties[key];
                  if (!isProducerIgnored(producerProperty)) {
                    let propertyName = getProducerPropertyMappingName(key, producerProperty);
                    let clientProperty = findClientPropertyByName(propertyName, clientProperties);

                    checkSchema(endpoint, clientProperty, producerProperty, clientProject, producerProject, reporter, path + (path == '' ? '' : '.') + key, placing);
                  }
                }
              }

              // Check unknown client properties
              if (clientProperties) {
                for (let key in clientProperties) {
                  let clientProperty = clientProperties[key];
                  if (!isClientIgnored(clientProperty)) {
                    let name = getClientPropertyMappingName(key, clientProperty);

                    let producerProperty:Schema = null;
                    if(producerProperties) {
                      producerProperty = findProducerPropertyByName(name, producerProperties);
                    }
                      if (!producerProperty) {
                        let keyPath = path + (path ? '.' : '') + key;
                        reporter.report(ProblemLevels.WARNING, `Unknown property '${keyPath}' in ${placing} body`, endpoint.controller, endpoint.method);
                      }
                  }
                }
              }

              // Decorate problems with view info
              if(producerViews.length > 1 || clientViews.length > 1) {
                reporter.getRawProblems().forEach(problem => {
                  problem.message = "[" + clientView.name + " > " + producerView.name + "] " + problem.message;
                });
              }
            });
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:47,代码来源:endpoint-check.func.ts

示例4: checkResponseBody

export function checkResponseBody(clientEndpoint: Path, producerEndpoint: Path, clientProject: Project, producerProject: Project, problemReport: ProblemReporter): void {
  if (clientEndpoint.responses != undefined && clientEndpoint.responses != null &&
    clientEndpoint.responses['default'] != undefined && clientEndpoint.responses['default'] != null &&
    clientEndpoint.responses['default'].schema != undefined && clientEndpoint.responses['default'].schema != null) {

    if (producerEndpoint.responses != undefined && producerEndpoint.responses != null &&
      producerEndpoint.responses['default'] != undefined && producerEndpoint.responses['default'] != null &&
      producerEndpoint.responses['default'].schema != undefined && producerEndpoint.responses['default'].schema != null) {

      // let producerSchema = SchemaHelper.collect(producerEndpoint.responses['default'].schema, [], producerProject);
      // let clientSchema = SchemaHelper.collect(clientEndpoint.responses['default'].schema, [], clientProject);
      // checkSchema(clientEndpoint, clientSchema, producerSchema, clientProject, producerProject, problemReport, '', 'response');
    } else {
      problemReport.report(ProblemLevels.ERROR, "There is no response body", clientEndpoint.controller, clientEndpoint.method);
    }
  }
}
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:17,代码来源:endpoint-check.func.ts

示例5: checkSchema

function checkSchema(endpoint: Path, clientSchema: Schema, producerSchema: Schema, clientProject: Project, producerProject: Project, problemReport: ProblemReporter, path: string, placing: 'request'|'response'): void {
  if (producerSchema != null && producerSchema != undefined) {
    if (clientSchema != null && clientSchema != undefined) {
      if (!matchType(clientSchema, producerSchema)) {
        let position = "";
        if (path != '') {
          position = ' at ' + path;
        }
        problemReport.report(ProblemLevels.WARNING, "Type mismatches in " + placing + " body" + position + ", expected: " + producerSchema.type + ", found: " + clientSchema.type, endpoint.controller, endpoint.method);
      } else {
        if (producerSchema.type == SchemaTypes.OBJECT) {
          let producerViews = collectViews(producerSchema);
          let clientViews = collectViews(clientSchema);

          // Check each view for problems
          let problemReporters: ProblemReporter[] = [];
          producerViews.forEach(producerView => {
            clientViews.forEach(clientView => {
              let reporter = new ProblemReporter(problemReport.getRootObject());
              problemReporters.push(reporter);

              let producerProperties = producerView.properties;
              let clientProperties = clientView.properties;

              // Check each producer properties
              if (producerProperties) {
                for (let key in producerProperties) {
                  // Find client Property by name
                  let producerProperty = producerProperties[key];
                  if (!isProducerIgnored(producerProperty)) {
                    let propertyName = getProducerPropertyMappingName(key, producerProperty);
                    let clientProperty = findClientPropertyByName(propertyName, clientProperties);

                    checkSchema(endpoint, clientProperty, producerProperty, clientProject, producerProject, reporter, path + (path == '' ? '' : '.') + key, placing);
                  }
                }
              }

              // Check unknown client properties
              if (clientProperties) {
                for (let key in clientProperties) {
                  let clientProperty = clientProperties[key];
                  if (!isClientIgnored(clientProperty)) {
                    let name = getClientPropertyMappingName(key, clientProperty);

                    let producerProperty:Schema = null;
                    if(producerProperties) {
                      producerProperty = findProducerPropertyByName(name, producerProperties);
                    }
                      if (!producerProperty) {
                        let keyPath = path + (path ? '.' : '') + key;
                        reporter.report(ProblemLevels.WARNING, `Unknown property '${keyPath}' in ${placing} body`, endpoint.controller, endpoint.method);
                      }
                  }
                }
              }

              // Decorate problems with view info
              if(producerViews.length > 1 || clientViews.length > 1) {
                reporter.getRawProblems().forEach(problem => {
                  problem.message = "[" + clientView.name + " > " + producerView.name + "] " + problem.message;
                });
              }
            });
          });

          if (problemReporters.filter(reporter => !reporter.hasProblems()).length == 0) {
            // No matching view
            if (problemReporters.length > 1) {
              let position = "";
              if (path != '') {
                position = ' at ' + path;
              }
              problemReport.report(ProblemLevels.ERROR, `No matching view in ${placing} body${position}`, endpoint.controller, endpoint.method);
            }
            problemReporters.forEach(r => {
              r.getRawProblems().forEach(problem => {
                problemReport.getRawProblems().push(problem);
              });
            });
          }

        } else if (producerSchema.type == SchemaTypes.ARRAY) {
          let producerItems = producerSchema.items;
          let clientItems = clientSchema.items;
          checkSchema(endpoint, clientItems, producerItems, clientProject, producerProject, problemReport, path + (path == '' ? '' : '.') + "0", placing);
        }
      }
    } else {
      if (producerSchema.required) {
        problemReport.report(ProblemLevels.ERROR, `Missing required property '${path}' in ${placing} body`, endpoint.controller, endpoint.method);
      }
    }
  }
}
开发者ID:MaxxtonGroup,项目名称:microdocs,代码行数:95,代码来源:endpoint-check.func.ts


注:本文中的@maxxton/microdocs-core/helpers.ProblemReporter.report方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。