<commit_before>//
//  JsonParser+Context.swift
//  ModelGen
//
//  Created by <NAME> on 2017-05-10.
//  Copyright © 2017 ModelGen. All rights reserved.
//

import Foundation

extension JsonParser {
    public func stencilContextFor(_ language: Language) throws -> JSON {
        try dicToArray()
        try mapProperties()
        try prepareContextFor(language)

        return [
            "spec": json,
            "nestedObjects": hasNestedObjects()
        ]
    }

    // MARK: Prepare JSON to be used by template

    private func dicToArray() throws {
        guard let items = json["properties"] as? JSON else {
            throw JsonParserError.missingProperties
        }

        var properties = [JSON]()
        for (key, value) in items {
            guard let value = value as? JSON else {
                throw JsonParserError.missingProperties
            }
            var nValue = value<commit_msg>Sorting attribute keys by names<commit_after>//
//  JsonParser+Context.swift
//  ModelGen
//
//  Created by <NAME> on 2017-05-10.
//  Copyright © 2017 ModelGen. All rights reserved.
//

import Foundation

extension JsonParser {
    public func stencilContextFor(_ language: Language) throws -> JSON {
        try dicToArray()
        try mapProperties()
        try prepareContextFor(language)

        return [
            "spec": json,
            "nestedObjects": hasNestedObjects()
        ]
    }

    // MARK: Prepare JSON to be used by template

    private func dicToArray() throws {
        guard let items = json["properties"] as? JSON else {
            throw JsonParserError.missingProperties
        }

        var properties = [JSON]()

        for (key, value) in items.sorted(by: { $0.key < $1.key }) {
            guard let value = value as? JSON else {
                throw JsonParserError.missingProperties
            }
            var nValue = value
{'fraction_non_alphanumeric': 0.09254362771020624, 'fraction_numerical': 0.013749338974087784, 'mean_word_length': 1.9748427672955975, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 7, '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': '3845220', 'n_tokens_mistral': 524, 'n_tokens_neox': 488, 'n_words': 161}