var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
import { JsonCompat } from '../../compat/JsonCompat';
import { Constants } from '../../core/Constants';
import { DataModelReader } from '../../core/io/DataModelReader';
/**
 * A data model reader for the OpenAPI data model.
 * @author eric.wittmann@gmail.com
 * @class
 * @extends DataModelReader
 */
var OasDataModelReader = /** @class */ (function (_super) {
    __extends(OasDataModelReader, _super);
    function OasDataModelReader() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /**
     * @see io.apicurio.datamodels.core.io.DataModelReader#readDocument(java.lang.Object, io.apicurio.datamodels.core.models.Document)
     * @param {*} json
     * @param {Document} node
     */
    OasDataModelReader.prototype.readDocument = function (json, node) {
        var _this = this;
        var doc = node;
        var paths = JsonCompat.consumeProperty(json, Constants.PROP_PATHS);
        var security = JsonCompat.consumePropertyArray(json, Constants.PROP_SECURITY);
        if (paths != null) {
            doc.paths = doc.createPaths();
            this.readPaths(paths, doc.paths);
        }
        if (security != null) {
            security.forEach((function (doc) {
                return function (sec) {
                    var secModel = doc.createSecurityRequirement();
                    _this.readSecurityRequirement(sec, secModel);
                    doc.addSecurityRequirement(secModel);
                };
            })(doc));
        }
        _super.prototype.readDocument.call(this, json, doc);
    };
    /**
     * Read the paths.
     * @param {*} json
     * @param {OasPaths} node
     */
    OasDataModelReader.prototype.readPaths = function (json, node) {
        var pathNames = JsonCompat.keys(json);
        for (var index183 = 0; index183 < pathNames.length; index183++) {
            var pathName = pathNames[index183];
            {
                if (pathName.indexOf("x-") === 0) {
                    continue;
                }
                var pathItem = JsonCompat.consumeProperty(json, pathName);
                var pathItemModel = node.createPathItem(pathName);
                this.readPathItem(pathItem, pathItemModel);
                node.addPathItem(pathName, pathItemModel);
            }
        }
        this.readExtensions(json, node);
        this.readExtraProperties(json, node);
    };
    /**
     * Reads a path item.
     * @param {*} json
     * @param {OasPathItem} node
     */
    OasDataModelReader.prototype.readPathItem = function (json, node) {
        var _this = this;
        var $ref = JsonCompat.consumePropertyString(json, Constants.PROP_$REF);
        var get = JsonCompat.consumeProperty(json, Constants.PROP_GET);
        var put = JsonCompat.consumeProperty(json, Constants.PROP_PUT);
        var post = JsonCompat.consumeProperty(json, Constants.PROP_POST);
        var __delete = JsonCompat.consumeProperty(json, Constants.PROP_DELETE);
        var options = JsonCompat.consumeProperty(json, Constants.PROP_OPTIONS);
        var head = JsonCompat.consumeProperty(json, Constants.PROP_HEAD);
        var patch = JsonCompat.consumeProperty(json, Constants.PROP_PATCH);
        var parameters = JsonCompat.consumePropertyArray(json, Constants.PROP_PARAMETERS);
        node.$ref = $ref;
        if (get != null) {
            node.get = node.createOperation(Constants.PROP_GET);
            this.readOperation(get, node.get);
        }
        if (put != null) {
            node.put = node.createOperation(Constants.PROP_PUT);
            this.readOperation(put, node.put);
        }
        if (post != null) {
            node.post = node.createOperation(Constants.PROP_POST);
            this.readOperation(post, node.post);
        }
        if (__delete != null) {
            node.delete = node.createOperation(Constants.PROP_DELETE);
            this.readOperation(__delete, node.delete);
        }
        if (options != null) {
            node.options = node.createOperation(Constants.PROP_OPTIONS);
            this.readOperation(options, node.options);
        }
        if (head != null) {
            node.head = node.createOperation(Constants.PROP_HEAD);
            this.readOperation(head, node.head);
        }
        if (patch != null) {
            node.patch = node.createOperation(Constants.PROP_PATCH);
            this.readOperation(patch, node.patch);
        }
        if (parameters != null) {
            parameters.forEach(function (parameter) {
                var parameterModel = node.createParameter();
                _this.readParameter(parameter, parameterModel);
                node.addParameter(parameterModel);
            });
        }
        this.readExtensions(json, node);
    };
    /**
     * Reads a single operation.
     * @param {*} json
     * @param {Operation} node
     */
    OasDataModelReader.prototype.readOperation = function (json, node) {
        var _this = this;
        var operation = node;
        var tags = JsonCompat.consumePropertyStringArray(json, Constants.PROP_TAGS);
        var parameters = JsonCompat.consumePropertyArray(json, Constants.PROP_PARAMETERS);
        var responses = JsonCompat.consumeProperty(json, Constants.PROP_RESPONSES);
        var deprecated = JsonCompat.consumePropertyBoolean(json, Constants.PROP_DEPRECATED);
        var security = JsonCompat.consumePropertyArray(json, Constants.PROP_SECURITY);
        operation.tags = tags;
        operation.deprecated = deprecated;
        if (parameters != null) {
            parameters.forEach((function (operation) {
                return function (parameter) {
                    var parameterModel = operation.createParameter();
                    _this.readParameter(parameter, parameterModel);
                    operation.addParameter(parameterModel);
                };
            })(operation));
        }
        if (responses != null) {
            operation.responses = operation.createResponses();
            this.readResponses(responses, operation.responses);
        }
        if (security != null) {
            security.forEach((function (operation) {
                return function (requirement) {
                    var requirementModel = operation.createSecurityRequirement();
                    _this.readSecurityRequirement(requirement, requirementModel);
                    operation.addSecurityRequirement(requirementModel);
                };
            })(operation));
        }
        _super.prototype.readOperation.call(this, json, node);
    };
    /**
     * Reads the responses.
     * @param {*} json
     * @param {OasResponses} node
     */
    OasDataModelReader.prototype.readResponses = function (json, node) {
        var _this = this;
        var default_ = JsonCompat.consumeProperty(json, Constants.PROP_DEFAULT);
        if (default_ != null) {
            node.default_ = node.createDefaultResponse();
            this.readResponse(default_, node.default_);
        }
        var responseCodes = JsonCompat.keys(json);
        responseCodes.forEach(function (code) {
            if (code.indexOf("x-") === 0) {
            }
            else {
                var response = JsonCompat.consumeProperty(json, code);
                var responseModel = node.createResponse(code);
                _this.readResponse(response, responseModel);
                node.addResponse(code, responseModel);
            }
        });
        this.readExtensions(json, node);
        this.readExtraProperties(json, node);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelReader#readSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
     * @param {*} json
     * @param {Schema} node
     */
    OasDataModelReader.prototype.readSchema = function (json, node) {
        var schema = node;
        var format = JsonCompat.consumePropertyString(json, Constants.PROP_FORMAT);
        var title = JsonCompat.consumePropertyString(json, Constants.PROP_TITLE);
        var description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
        var default_ = JsonCompat.consumePropertyObject(json, Constants.PROP_DEFAULT);
        var multipleOf = JsonCompat.consumePropertyNumber(json, Constants.PROP_MULTIPLE_OF);
        var maximum = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAXIMUM);
        var exclusiveMaximum = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM);
        var minimum = JsonCompat.consumePropertyNumber(json, Constants.PROP_MINIMUM);
        var exclusiveMinimum = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM);
        var maxLength = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_LENGTH);
        var minLength = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_LENGTH);
        var pattern = JsonCompat.consumePropertyString(json, Constants.PROP_PATTERN);
        var maxItems = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_ITEMS);
        var minItems = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_ITEMS);
        var uniqueItems = JsonCompat.consumePropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS);
        var maxProperties = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_PROPERTIES);
        var minProperties = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_PROPERTIES);
        var required = JsonCompat.consumePropertyStringArray(json, Constants.PROP_REQUIRED);
        var enum_ = JsonCompat.consumePropertyStringArray(json, Constants.PROP_ENUM);
        var type = JsonCompat.consumePropertyString(json, Constants.PROP_TYPE);
        var items = JsonCompat.consumeProperty(json, Constants.PROP_ITEMS);
        var allOf = JsonCompat.consumePropertyArray(json, Constants.PROP_ALL_OF);
        var properties = JsonCompat.consumeProperty(json, Constants.PROP_PROPERTIES);
        var additionalProperties = JsonCompat.consumeProperty(json, Constants.PROP_ADDITIONAL_PROPERTIES);
        var readOnly = JsonCompat.consumePropertyBoolean(json, Constants.PROP_READ_ONLY);
        var xml = JsonCompat.consumeProperty(json, Constants.PROP_XML);
        var externalDocs = JsonCompat.consumeProperty(json, Constants.PROP_EXTERNAL_DOCS);
        var example = JsonCompat.consumePropertyObject(json, Constants.PROP_EXAMPLE);
        schema.format = format;
        schema.title = title;
        schema.description = description;
        schema.default_ = default_;
        schema.multipleOf = multipleOf;
        schema.maximum = maximum;
        schema.exclusiveMaximum = exclusiveMaximum;
        schema.minimum = minimum;
        schema.exclusiveMinimum = exclusiveMinimum;
        schema.maxLength = maxLength;
        schema.minLength = minLength;
        schema.pattern = pattern;
        schema.maxItems = maxItems;
        schema.minItems = minItems;
        schema.uniqueItems = uniqueItems;
        schema.maxProperties = maxProperties;
        schema.minProperties = minProperties;
        schema.required = required;
        schema.enum_ = enum_;
        schema.type = type;
        schema.readOnly = readOnly;
        schema.example = example;
        if (items != null) {
            if (JsonCompat.isArray(items)) {
                var schemaModels = ([]);
                var itemList = JsonCompat.toList(items);
                for (var index184 = 0; index184 < itemList.length; index184++) {
                    var item = itemList[index184];
                    {
                        var itemsSchemaModel = schema.createItemsSchema();
                        this.readSchema(item, itemsSchemaModel);
                        /* add */ (schemaModels.push(itemsSchemaModel) > 0);
                    }
                }
                schema.items = schemaModels;
            }
            else {
                schema.items = schema.createItemsSchema();
                this.readSchema(items, schema.items);
            }
        }
        if (allOf != null) {
            var schemaModels = ([]);
            for (var index185 = 0; index185 < allOf.length; index185++) {
                var allOfSchema = allOf[index185];
                {
                    var allOfSchemaModel = schema.createAllOfSchema();
                    this.readSchema(allOfSchema, allOfSchemaModel);
                    /* add */ (schemaModels.push(allOfSchemaModel) > 0);
                }
            }
            schema.allOf = schemaModels;
        }
        if (properties != null) {
            var propertyNames = JsonCompat.keys(properties);
            for (var index186 = 0; index186 < propertyNames.length; index186++) {
                var propertyName = propertyNames[index186];
                {
                    var propertySchema = JsonCompat.consumeProperty(properties, propertyName);
                    var propertySchemaModel = schema.createPropertySchema(propertyName);
                    this.readSchema(propertySchema, propertySchemaModel);
                    schema.addProperty(propertyName, propertySchemaModel);
                }
            }
        }
        if (additionalProperties != null) {
            if (JsonCompat.isBoolean(additionalProperties)) {
                schema.additionalProperties = JsonCompat.toBoolean(additionalProperties);
            }
            else {
                var additionalPropertiesModel = schema.createAdditionalPropertiesSchema();
                this.readSchema(additionalProperties, additionalPropertiesModel);
                schema.additionalProperties = additionalPropertiesModel;
            }
        }
        if (xml != null) {
            schema.xml = schema.createXML();
            this.readXML(xml, schema.xml);
        }
        if (externalDocs != null) {
            schema.externalDocs = schema.createExternalDocumentation();
            this.readExternalDocumentation(externalDocs, schema.externalDocs);
        }
        _super.prototype.readSchema.call(this, json, schema);
    };
    /**
     * Reads an XML.
     * @param {*} json
     * @param {OasXML} node
     */
    OasDataModelReader.prototype.readXML = function (json, node) {
        var name = JsonCompat.consumePropertyString(json, Constants.PROP_NAME);
        var namespace = JsonCompat.consumePropertyString(json, Constants.PROP_NAMESPACE);
        var prefix = JsonCompat.consumePropertyString(json, Constants.PROP_PREFIX);
        var attribute = JsonCompat.consumePropertyBoolean(json, Constants.PROP_ATTRIBUTE);
        var wrapped = JsonCompat.consumePropertyBoolean(json, Constants.PROP_WRAPPED);
        node.name = name;
        node.namespace = namespace;
        node.prefix = prefix;
        node.attribute = attribute;
        node.wrapped = wrapped;
        this.readExtensions(json, node);
        this.readExtraProperties(json, node);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelReader#readParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {*} json
     * @param {Parameter} node
     */
    OasDataModelReader.prototype.readParameter = function (json, node) {
        var param = node;
        var __in = JsonCompat.consumePropertyString(json, Constants.PROP_IN);
        var required = JsonCompat.consumePropertyBoolean(json, Constants.PROP_REQUIRED);
        var allowEmptyValue = JsonCompat.consumePropertyBoolean(json, Constants.PROP_ALLOW_EMPTY_VALUE);
        param.in = __in;
        param.required = required;
        param.allowEmptyValue = allowEmptyValue;
        _super.prototype.readParameter.call(this, json, node);
    };
    /**
     * Reads a single response.
     * @param {*} json
     * @param {OasResponse} node
     */
    OasDataModelReader.prototype.readResponse = function (json, node) {
        var $ref = JsonCompat.consumePropertyString(json, Constants.PROP_$REF);
        var description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
        node.$ref = $ref;
        node.description = description;
        this.readExtensions(json, node);
        this.readExtraProperties(json, node);
    };
    /**
     * Reads a single header.
     * @param {*} json
     * @param {OasHeader} node
     */
    OasDataModelReader.prototype.readHeader = function (json, node) {
        node.description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
    };
    return OasDataModelReader;
}(DataModelReader));
export { OasDataModelReader };
OasDataModelReader["__class"] = "io.apicurio.datamodels.openapi.io.OasDataModelReader";
//# sourceMappingURL=OasDataModelReader.js.map