<commit_before>'use strict';

var _ = require('lodash');
var Inherits = require('util').inherits;
var URI = require('URIjs');

var BaseType = require('./base-type.js');
var Types = require('./types.js');
var Util = require('./util.js');

var Swagger2 = module.exports = function() {
  Swagger2.super_.apply(this, arguments);
  this.type = 'swagger_2';
}

Inherits(Swagger2, BaseType);

Swagger2.prototype.formatName = 'swagger';
Swagger2.prototype.supportedVersions = ['2.0'];
Swagger2.prototype.getFormatVersion = function () {
  return this.spec.swagger;
}

Swagger2.prototype.fixSpec = function () {
  var version = this.spec.swagger;
  //Typical mistake is to make version number insted of string
  if (_.isNumber(version))
    this.spec.swagger = version % 1 ? version.toString() : version.toFixed(1);

  if (this.url) {
    var url = URI(this.url);
    var swagger = this.spec;
    swagger.host = swagger.host || url.host();
    swagger.schemes = swagger.schemes || [url.scheme()];
    //TODO: deside what to do with base path
  }
};

Swagger2.prototype.parsers = [Util.parseJSON, Util.parseYAML];

Swagger2.prototype.checkFormat = function (spec) {<commit_msg>Swagger_2: normalize 'basePath'<commit_after>'use strict';

var _ = require('lodash');
var Inherits = require('util').inherits;
var URI = require('URIjs');

var BaseType = require('./base-type.js');
var Types = require('./types.js');
var Util = require('./util.js');

var Swagger2 = module.exports = function() {
  Swagger2.super_.apply(this, arguments);
  this.type = 'swagger_2';
}

Inherits(Swagger2, BaseType);

Swagger2.prototype.formatName = 'swagger';
Swagger2.prototype.supportedVersions = ['2.0'];
Swagger2.prototype.getFormatVersion = function () {
  return this.spec.swagger;
}

Swagger2.prototype.fixSpec = function () {
  var version = this.spec.swagger;
  //Typical mistake is to make version number insted of string
  if (_.isNumber(version))
    this.spec.swagger = version % 1 ? version.toString() : version.toFixed(1);

  if (this.url) {
    var url = URI(this.url);
    var swagger = this.spec;
    swagger.host = swagger.host || url.host();
    swagger.schemes = swagger.schemes || [url.scheme()];
    //TODO: deside what to do with base path
  }

  var basePath = this.spec.basePath
  if (_.isString(basePath))
    this.spec.basePath = URI().path(basePath).normalize().toString();
};

Swagger2.prototype.parsers = [Util.parseJSON, Util.parseYAML];

Swagger2.prototype.checkFormat = function (spec) {
{'fraction_non_alphanumeric': 0.15761962203457983, 'fraction_numerical': 0.01166063530357861, 'mean_word_length': 4.1941544885177455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6163565', 'n_tokens_mistral': 842, 'n_tokens_neox': 831, 'n_words': 183}