Sha256: df418e478862943c6f8a0f72bde22f48d501a696bcb9329d8bd9c75684f95c27

Contents?: true

Size: 1.83 KB

Versions: 21

Compression:

Stored size: 1.83 KB

Contents

const { buildAppMap } = require('@appland/models');

function classNameToSwaggerType(className) {
  let typeName = className;
  if (!typeName || typeName === '') {
    return 'unknown';
  }
  typeName = typeName.toLowerCase();

  switch (typeName) {
    case 'hash':
    case 'activesupport::hashwithindifferentaccess':
      return 'object';
    case 'nilclass':
      return 'string';
    case 'trueclass':
    case 'falseclass':
      return 'boolean';
    default:
      return typeName;
  }
}

function messageToSwaggerSchema(message) {
  const type = classNameToSwaggerType(message.class);
  const result = { type };
  /*
  if (message.value) {
    let example;
    try {
      example = JSON.parse(message.value);
    } catch (e) {
      example = message.value;
    }
    if (example && example !== '') {
      result.example = example.toString();
    }
  }
  */
  if (type === 'array') {
    // This is our best guess right now.
    result.items = { type: 'string' };
  } else if (type === 'object' && message.properties) {
    result.properties = message.properties.reduce((memo, msgProperty) => {
      // eslint-disable-next-line no-param-reassign
      memo[msgProperty.name] = {
        type: classNameToSwaggerType(msgProperty.class),
      };
      return memo;
    }, {});
  }

  return result;
}

function parseHTTPServerRequests(source, collector) {
  const appmap = buildAppMap().source(source).normalize().build();

  appmap.events.filter((e) => e.httpServerRequest).forEach(collector);
}

function ensureString(value) {
  if (Array.isArray(value)) {
    return value.join('');
  }
  return value.toString();
}

function bestPathInfo(httpServerRequest) {
  return ensureString(
    httpServerRequest.normalized_path_info || httpServerRequest.path_info || ''
  );
}

module.exports = {
  bestPathInfo,
  messageToSwaggerSchema,
  parseHTTPServerRequests,
};

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appmap-0.72.2 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.72.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.72.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.71.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.70.2 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.70.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.70.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.69.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.68.2 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.68.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.68.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.67.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.67.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.66.2 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.66.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.66.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.65.1 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.65.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.64.0 ./node_modules/@appland/appmap/src/swagger/util.js
appmap-0.63.0 ./node_modules/@appland/appmap/src/swagger/util.js