{"size": 1371, "ext": "js", "max_stars_repo_path": "lib/utils/specification.js", "max_stars_repo_name": "jersonlopez/silk-paper-node", "max_stars_repo_stars_event_min_datetime": "2020-10-07T18:32:15.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-07T18:32:15.000Z", "max_issues_repo_path": "lib/utils/specification.js", "max_issues_repo_name": "jersonlopez/silk-paper-node", "max_issues_repo_issues_event_min_datetime": "2020-04-22T14:13:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-25T15:35:37.000Z", "max_forks_repo_path": "lib/utils/specification.js", "max_forks_repo_name": "jersonlopez/silk-paper-node", "max_forks_repo_forks_event_min_datetime": "2020-02-26T16:39:36.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-26T16:39:36.000Z"}
{"max_stars_count": 1, "max_issues_count": 20, "max_forks_count": 1, "avg_line_length": 26.8823529412, "max_line_length": 110, "alphanum_fraction": 0.6819839533}
const { createDescription } = require('./data');
const { generateAndAddBodychema } = require('./schemas');
const { addAllParams } = require('./params');
const { readFile } = require('./files');
const { schemaTypes, EXAMPLE_SERVER_DESCRIPTION, EXAMPLE_SERVER_URL, PACKAGE_JSON } = require('../constants');

exports.initGeneralSpecification = options => {
  const packageJson = readFile(`${process.cwd()}/${PACKAGE_JSON}`);

  return {
    openapi: options.openapi,
    info: {
      title: packageJson.name,
      description: packageJson.description,
      version: packageJson.version
    },
    servers: [
      {
        url: EXAMPLE_SERVER_URL,
        description: EXAMPLE_SERVER_DESCRIPTION
      }
    ]
  };
};

exports.initPathSpecification = data => ({
  [data.path]: {
    [data.method]: {
      description: createDescription(data),
      parameters: []
    }
  },
  components: { schemas: {} }
});

exports.createSpecification = data => {
  const spec = this.initPathSpecification(data);

  generateAndAddBodychema(spec, data, schemaTypes.REQUEST);
  generateAndAddBodychema(spec, data, schemaTypes.RESPONSE);
  addAllParams(spec, data);

  return spec;
};

exports.updateSpecification = (spec, data) => {
  generateAndAddBodychema(spec, data, schemaTypes.REQUEST);
  generateAndAddBodychema(spec, data, schemaTypes.RESPONSE);
  addAllParams(spec, data);
};
