<commit_before>//
//  Generator.swift
//  jsonschema2swift
//
//  Created by hayato.iida on 2016/08/29.
//  Copyright © 2016年 Speee, Inc. All rights reserved.
//

import Foundation

class Generator {
  let rootJSON: JSON
  let rootSchema: Schema

  init(rootJSON: JSON) {
    self.rootJSON = rootJSON
    self.rootSchema = Schema(byRootJSON: rootJSON)!
  }

  func generate(path: String) {
    let fileManager: FileManager = FileManager()

    try! fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
    let entityPath = path + "/Entity"
    if fileManager.fileExists(atPath: entityPath) {
      try! fileManager.removeItem(atPath: entityPath)
    }
    try! fileManager.createDirectory(atPath: entityPath, withIntermediateDirectories: true, attributes: nil)

    let beGenerated = SchemaGenerated(rootJSON: rootJSON)

    // generate Entities
    beGenerated.entities().forEach {
          let fileName = fixEntitySuffix(code: "\($0.0.snake2Camel)Entity")
          try! $0.1.write(toFile: "\(path)/Entity/\(fileName).swift",
                          atomically: true, encoding: String.Encoding.utf8)
        }


    // generate API.swift
    let links = rootJSON["definitions"].flatMap {
      $0.1["links"].arrayValue
    }.map {
      LinkSchema(json: $0, rootJSON: rootJSON)
    }
    let api = APIGenerator(rootSchema: rootSchema, links: links).generate()
    try! api.write(toFile: "\(path)/API.swift", atomically: true, encoding: String.Encoding.utf8)


    // generate APIKey.swift
    let apiKey = APIGenerator(rootSchema: rootSchema, links: links).generateKey()
    try! apiKey.write(toFile: "\(path)/APIKey.swift", atomically: true, encoding: String.Encoding.utf8)

  }

}<commit_msg>fix api sort<commit_after>//
//  Generator.swift
//  jsonschema2swift
//
//  Created by hayato.iida on 2016/08/29.
//  Copyright © 2016年 Speee, Inc. All rights reserved.
//

import Foundation

class Generator {
  let rootJSON: JSON
  let rootSchema: Schema

  init(rootJSON: JSON) {
    self.rootJSON = rootJSON
    self.rootSchema = Schema(byRootJSON: rootJSON)!
  }

  func generate(path: String) {
    let fileManager: FileManager = FileManager()

    try! fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
    let entityPath = path + "/Entity"
    if fileManager.fileExists(atPath: entityPath) {
      try! fileManager.removeItem(atPath: entityPath)
    }
    try! fileManager.createDirectory(atPath: entityPath, withIntermediateDirectories: true, attributes: nil)

    let beGenerated = SchemaGenerated(rootJSON: rootJSON)

    // generate Entities
    beGenerated.entities().forEach {
          let fileName = fixEntitySuffix(code: "\($0.0.snake2Camel)Entity")
          try! $0.1.write(toFile: "\(path)/Entity/\(fileName).swift",
                          atomically: true, encoding: String.Encoding.utf8)
        }


    // generate API.swift
    let links = rootJSON["definitions"].flatMap {
      $0.1["links"].arrayValue
    }.map {
      LinkSchema(json: $0, rootJSON: rootJSON)
    }.sorted { (schema0: LinkSchema, schema1: LinkSchema) in
      (schema0.title ?? "") < (schema1.title ?? "")
    }
    let api = APIGenerator(rootSchema: rootSchema, links: links).generate()
    try! api.write(toFile: "\(path)/API.swift", atomically: true, encoding: String.Encoding.utf8)


    // generate APIKey.swift
    let apiKey = APIGenerator(rootSchema: rootSchema, links: links).generateKey()
    try! apiKey.write(toFile: "\(path)/APIKey.swift", atomically: true, encoding: String.Encoding.utf8)

  }

}
{'fraction_non_alphanumeric': 0.12778396436525613, 'fraction_numerical': 0.014476614699331848, 'mean_word_length': 3.3185096153846154, 'pattern_counts': {'":': 0, '<': 4, '<?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': '5205484', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1106, 'n_words': 252}