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 { OasDataModelReader } from '../../io/OasDataModelReader';
/**
 * A data model reader for the OpenAPI 2.0 data model.
 * @author eric.wittmann@gmail.com
 * @class
 * @extends OasDataModelReader
 */
var Oas20DataModelReader = /** @class */ (function (_super) {
    __extends(Oas20DataModelReader, _super);
    function Oas20DataModelReader() {
        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
     */
    Oas20DataModelReader.prototype.readDocument = function (json, node) {
        var doc = node;
        JsonCompat.consumePropertyString(json, Constants.PROP_SWAGGER);
        var host = JsonCompat.consumePropertyString(json, Constants.PROP_HOST);
        var basePath = JsonCompat.consumePropertyString(json, Constants.PROP_BASE_PATH);
        var schemes = JsonCompat.consumePropertyStringArray(json, Constants.PROP_SCHEMES);
        var consumes = JsonCompat.consumePropertyStringArray(json, Constants.PROP_CONSUMES);
        var produces = JsonCompat.consumePropertyStringArray(json, Constants.PROP_PRODUCES);
        var definitions = JsonCompat.consumeProperty(json, Constants.PROP_DEFINITIONS);
        var parameters = JsonCompat.consumeProperty(json, Constants.PROP_PARAMETERS);
        var responses = JsonCompat.consumeProperty(json, Constants.PROP_RESPONSES);
        var securityDefinitions = JsonCompat.consumeProperty(json, Constants.PROP_SECURITY_DEFINITIONS);
        doc.host = host;
        doc.basePath = basePath;
        doc.schemes = schemes;
        doc.consumes = consumes;
        doc.produces = produces;
        if (definitions != null) {
            doc.definitions = doc.createDefinitions();
            this.readDefinitions(definitions, doc.definitions);
        }
        if (parameters != null) {
            doc.parameters = doc.createParameterDefinitions();
            this.readParameterDefinitions(parameters, doc.parameters);
        }
        if (responses != null) {
            doc.responses = doc.createResponseDefinitions();
            this.readResponseDefinitions(responses, doc.responses);
        }
        if (securityDefinitions != null) {
            doc.securityDefinitions = doc.createSecurityDefinitions();
            this.readSecurityDefinitions(securityDefinitions, doc.securityDefinitions);
        }
        _super.prototype.readDocument.call(this, json, doc);
    };
    /**
     * Reads the definitions.
     * @param {*} json
     * @param {Oas20Definitions} node
     */
    Oas20DataModelReader.prototype.readDefinitions = function (json, node) {
        var names = JsonCompat.keys(json);
        for (var index177 = 0; index177 < names.length; index177++) {
            var name_1 = names[index177];
            {
                var definition = JsonCompat.consumeProperty(json, name_1);
                var definitionModel = node.createSchemaDefinition(name_1);
                this.readSchema(definition, definitionModel);
                node.addDefinition(name_1, definitionModel);
            }
        }
    };
    /**
     * Reads the parameter definitions.
     * @param {*} json
     * @param {Oas20ParameterDefinitions} node
     */
    Oas20DataModelReader.prototype.readParameterDefinitions = function (json, node) {
        var names = JsonCompat.keys(json);
        for (var index178 = 0; index178 < names.length; index178++) {
            var name_2 = names[index178];
            {
                var definition = JsonCompat.consumeProperty(json, name_2);
                var definitionModel = node.createParameter(name_2);
                this.readParameterDefinition(definition, definitionModel);
                node.addParameter(name_2, definitionModel);
            }
        }
    };
    /**
     * Reads the response definitions.
     * @param {*} json
     * @param {Oas20ResponseDefinitions} node
     */
    Oas20DataModelReader.prototype.readResponseDefinitions = function (json, node) {
        var names = JsonCompat.keys(json);
        for (var index179 = 0; index179 < names.length; index179++) {
            var name_3 = names[index179];
            {
                var definition = JsonCompat.consumeProperty(json, name_3);
                var definitionModel = node.createResponse(name_3);
                this.readResponseDefinition(definition, definitionModel);
                node.addResponse(name_3, definitionModel);
            }
        }
    };
    /**
     * Reads a single parameter definition.
     * @param {*} json
     * @param {Oas20ParameterDefinition} node
     */
    Oas20DataModelReader.prototype.readParameterDefinition = function (json, node) {
        this.readParameter(json, node);
    };
    /**
     * Reads a single response definition.
     * @param {*} json
     * @param {Oas20ResponseDefinition} node
     */
    Oas20DataModelReader.prototype.readResponseDefinition = function (json, node) {
        this.readResponse(json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readResponse(java.lang.Object, io.apicurio.datamodels.openapi.models.OasResponse)
     * @param {*} json
     * @param {OasResponse} node
     */
    Oas20DataModelReader.prototype.readResponse = function (json, node) {
        var response = node;
        var headers = JsonCompat.consumeProperty(json, Constants.PROP_HEADERS);
        var schema = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMA);
        var examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
        if (headers != null) {
            response.headers = response.createHeaders();
            this.readHeaders(headers, response.headers);
        }
        if (schema != null) {
            response.schema = response.createSchema();
            this.readSchema(schema, response.schema);
        }
        if (examples != null) {
            response.examples = response.createExample();
            this.readExample(examples, response.examples);
        }
        _super.prototype.readResponse.call(this, json, node);
    };
    /**
     * Reads the headers.
     * @param {*} json
     * @param {Oas20Headers} node
     */
    Oas20DataModelReader.prototype.readHeaders = function (json, node) {
        var names = JsonCompat.keys(json);
        for (var index180 = 0; index180 < names.length; index180++) {
            var name_4 = names[index180];
            {
                var definition = JsonCompat.consumeProperty(json, name_4);
                var definitionModel = node.createHeader(name_4);
                this.readHeader(definition, definitionModel);
                node.addHeader(name_4, definitionModel);
            }
        }
    };
    /**
     * Reads a single header.
     * @param {*} json
     * @param {OasHeader} node
     */
    Oas20DataModelReader.prototype.readHeader = function (json, node) {
        var header = node;
        var type = JsonCompat.consumePropertyString(json, Constants.PROP_TYPE);
        var format = JsonCompat.consumePropertyString(json, Constants.PROP_FORMAT);
        var items = JsonCompat.consumeProperty(json, Constants.PROP_ITEMS);
        var collectionFormat = JsonCompat.consumePropertyString(json, Constants.PROP_COLLECTION_FORMAT);
        var default_ = JsonCompat.consumePropertyObject(json, Constants.PROP_DEFAULT);
        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 enum_ = JsonCompat.consumePropertyStringArray(json, Constants.PROP_ENUM);
        var multipleOf = JsonCompat.consumePropertyNumber(json, Constants.PROP_MULTIPLE_OF);
        header.type = type;
        header.format = format;
        header.collectionFormat = collectionFormat;
        header.default_ = default_;
        header.maximum = maximum;
        header.exclusiveMaximum = exclusiveMaximum;
        header.minimum = minimum;
        header.exclusiveMinimum = exclusiveMinimum;
        header.maxLength = maxLength;
        header.minLength = minLength;
        header.pattern = pattern;
        header.maxItems = maxItems;
        header.minItems = minItems;
        header.uniqueItems = uniqueItems;
        header.enum_ = enum_;
        header.multipleOf = multipleOf;
        if (items != null) {
            header.items = header.createItems();
            this.readItems(items, header.items);
        }
        _super.prototype.readHeader.call(this, json, header);
    };
    /**
     * Reads an example.
     * @param {*} json
     * @param {Oas20Example} node
     */
    Oas20DataModelReader.prototype.readExample = function (json, node) {
        var contentTypes = JsonCompat.keys(json);
        contentTypes.forEach(function (ct) {
            var example = JsonCompat.consumePropertyObject(json, ct);
            node.addExample(ct, example);
        });
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {*} json
     * @param {Parameter} node
     */
    Oas20DataModelReader.prototype.readParameter = function (json, node) {
        var param = node;
        var type = JsonCompat.consumePropertyString(json, Constants.PROP_TYPE);
        var format = JsonCompat.consumePropertyString(json, Constants.PROP_FORMAT);
        var items = JsonCompat.consumeProperty(json, Constants.PROP_ITEMS);
        var collectionFormat = JsonCompat.consumePropertyString(json, Constants.PROP_COLLECTION_FORMAT);
        var default_ = JsonCompat.consumePropertyObject(json, Constants.PROP_DEFAULT);
        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 enum_ = JsonCompat.consumePropertyStringArray(json, Constants.PROP_ENUM);
        var multipleOf = JsonCompat.consumePropertyNumber(json, Constants.PROP_MULTIPLE_OF);
        param.type = type;
        param.format = format;
        param.collectionFormat = collectionFormat;
        param.default_ = default_;
        param.maximum = maximum;
        param.exclusiveMaximum = exclusiveMaximum;
        param.minimum = minimum;
        param.exclusiveMinimum = exclusiveMinimum;
        param.maxLength = maxLength;
        param.minLength = minLength;
        param.pattern = pattern;
        param.maxItems = maxItems;
        param.minItems = minItems;
        param.uniqueItems = uniqueItems;
        param.enum_ = enum_;
        param.multipleOf = multipleOf;
        if (items != null) {
            param.items = param.createItems();
            this.readItems(items, param.items);
        }
        _super.prototype.readParameter.call(this, json, node);
    };
    /**
     * Reads an Items.
     * @param {*} json
     * @param {Oas20Items} node
     */
    Oas20DataModelReader.prototype.readItems = function (json, node) {
        var type = JsonCompat.consumePropertyString(json, Constants.PROP_TYPE);
        var format = JsonCompat.consumePropertyString(json, Constants.PROP_FORMAT);
        var items = JsonCompat.consumeProperty(json, Constants.PROP_ITEMS);
        var collectionFormat = JsonCompat.consumePropertyString(json, Constants.PROP_COLLECTION_FORMAT);
        var default_ = JsonCompat.consumePropertyObject(json, Constants.PROP_DEFAULT);
        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 enum_ = JsonCompat.consumePropertyStringArray(json, Constants.PROP_ENUM);
        var multipleOf = JsonCompat.consumePropertyNumber(json, Constants.PROP_MULTIPLE_OF);
        node.type = type;
        node.format = format;
        node.collectionFormat = collectionFormat;
        node.default_ = default_;
        node.maximum = maximum;
        node.exclusiveMaximum = exclusiveMaximum;
        node.minimum = minimum;
        node.exclusiveMinimum = exclusiveMinimum;
        node.maxLength = maxLength;
        node.minLength = minLength;
        node.pattern = pattern;
        node.maxItems = maxItems;
        node.minItems = minItems;
        node.uniqueItems = uniqueItems;
        node.enum_ = enum_;
        node.multipleOf = multipleOf;
        if (items != null) {
            node.items = node.createItems();
            this.readItems(items, node.items);
        }
        this.readExtensions(json, node);
        this.readExtraProperties(json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
     * @param {*} json
     * @param {Schema} node
     */
    Oas20DataModelReader.prototype.readSchema = function (json, node) {
        var schema = node;
        var discriminator = JsonCompat.consumePropertyString(json, Constants.PROP_DISCRIMINATOR);
        schema.discriminator = discriminator;
        _super.prototype.readSchema.call(this, json, node);
    };
    /**
     * Reads the security definitions.
     * @param {*} json
     * @param {Oas20SecurityDefinitions} node
     */
    Oas20DataModelReader.prototype.readSecurityDefinitions = function (json, node) {
        var names = JsonCompat.keys(json);
        for (var index181 = 0; index181 < names.length; index181++) {
            var name_5 = names[index181];
            {
                var schemeJson = JsonCompat.consumeProperty(json, name_5);
                var schemeModel = node.createSecurityScheme(name_5);
                this.readSecurityScheme(schemeJson, schemeModel);
                node.addSecurityScheme(name_5, schemeModel);
            }
        }
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelReader#readSecurityScheme(java.lang.Object, io.apicurio.datamodels.core.models.common.SecurityScheme)
     * @param {*} json
     * @param {SecurityScheme} node
     */
    Oas20DataModelReader.prototype.readSecurityScheme = function (json, node) {
        var scheme = node;
        var flow = JsonCompat.consumePropertyString(json, Constants.PROP_FLOW);
        var authorizationUrl = JsonCompat.consumePropertyString(json, Constants.PROP_AUTHORIZATION_URL);
        var tokenUrl = JsonCompat.consumePropertyString(json, Constants.PROP_TOKEN_URL);
        var scopes = JsonCompat.consumeProperty(json, Constants.PROP_SCOPES);
        scheme.flow = flow;
        scheme.authorizationUrl = authorizationUrl;
        scheme.tokenUrl = tokenUrl;
        if (scopes != null) {
            var scopesModel = scheme.createScopes();
            this.readScopes(scopes, scopesModel);
            scheme.scopes = scopesModel;
        }
        _super.prototype.readSecurityScheme.call(this, json, scheme);
    };
    /**
     * Reads the scopes.
     * @param {*} json
     * @param {Oas20Scopes} node
     */
    Oas20DataModelReader.prototype.readScopes = function (json, node) {
        var scopeNames = JsonCompat.keys(json);
        for (var index182 = 0; index182 < scopeNames.length; index182++) {
            var scopeName = scopeNames[index182];
            {
                if (scopeName.indexOf("x-") === 0) {
                    continue;
                }
                var scopeDescription = JsonCompat.consumePropertyString(json, scopeName);
                node.addScope(scopeName, scopeDescription);
            }
        }
        this.readExtensions(json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readOperation(java.lang.Object, io.apicurio.datamodels.core.models.common.Operation)
     * @param {*} json
     * @param {Operation} node
     */
    Oas20DataModelReader.prototype.readOperation = function (json, node) {
        var operation = node;
        var consumes = JsonCompat.consumePropertyStringArray(json, Constants.PROP_CONSUMES);
        var produces = JsonCompat.consumePropertyStringArray(json, Constants.PROP_PRODUCES);
        var schemes = JsonCompat.consumePropertyStringArray(json, Constants.PROP_SCHEMES);
        operation.consumes = consumes;
        operation.produces = produces;
        operation.schemes = schemes;
        _super.prototype.readOperation.call(this, json, node);
    };
    return Oas20DataModelReader;
}(OasDataModelReader));
export { Oas20DataModelReader };
Oas20DataModelReader["__class"] = "io.apicurio.datamodels.openapi.v2.io.Oas20DataModelReader";
//# sourceMappingURL=Oas20DataModelReader.js.map