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 { OasDataModelWriter } from '../../io/OasDataModelWriter';
/**
 * @author eric.wittmann@gmail.com
 * @class
 * @extends OasDataModelWriter
 */
var Oas20DataModelWriter = /** @class */ (function (_super) {
    __extends(Oas20DataModelWriter, _super);
    function Oas20DataModelWriter() {
        return _super.call(this) || this;
    }
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeDocument(io.apicurio.datamodels.core.models.Document, java.lang.Object)
     * @param {Document} node
     * @param {*} json
     */
    Oas20DataModelWriter.prototype.writeDocument = function (node, json) {
        var doc = node;
        JsonCompat.setPropertyString(json, Constants.PROP_SWAGGER, doc.swagger);
        JsonCompat.setPropertyNull(json, Constants.PROP_INFO);
        JsonCompat.setPropertyString(json, Constants.PROP_HOST, doc.host);
        JsonCompat.setPropertyString(json, Constants.PROP_BASE_PATH, doc.basePath);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_SCHEMES, doc.schemes);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_CONSUMES, doc.consumes);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_PRODUCES, doc.produces);
        JsonCompat.setPropertyNull(json, Constants.PROP_PATHS);
        JsonCompat.setPropertyNull(json, Constants.PROP_DEFINITIONS);
        JsonCompat.setPropertyNull(json, Constants.PROP_PARAMETERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_RESPONSES);
        JsonCompat.setPropertyNull(json, Constants.PROP_SECURITY_DEFINITIONS);
        JsonCompat.setPropertyNull(json, Constants.PROP_SECURITY);
        JsonCompat.setPropertyNull(json, Constants.PROP_TAGS);
        JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
        this.writeExtraProperties(json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitItems(io.apicurio.datamodels.openapi.v2.models.Oas20Items)
     * @param {Oas20Items} node
     */
    Oas20DataModelWriter.prototype.visitItems = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_TYPE, node.type);
        JsonCompat.setPropertyString(json, Constants.PROP_FORMAT, node.format);
        JsonCompat.setPropertyNull(json, Constants.PROP_ITEMS);
        JsonCompat.setPropertyString(json, Constants.PROP_COLLECTION_FORMAT, node.collectionFormat);
        JsonCompat.setProperty(json, Constants.PROP_DEFAULT, node.default_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAXIMUM, node.maximum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM, node.exclusiveMaximum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MINIMUM, node.minimum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM, node.exclusiveMinimum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_LENGTH, node.maxLength);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_LENGTH, node.minLength);
        JsonCompat.setPropertyString(json, Constants.PROP_PATTERN, node.pattern);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_ITEMS, node.maxItems);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_ITEMS, node.minItems);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS, node.uniqueItems);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_ENUM, node.enum_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MULTIPLE_OF, node.multipleOf);
        this.writeExtraProperties(json, node);
        JsonCompat.setProperty(parent, Constants.PROP_ITEMS, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitSecurityDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityDefinitions)
     * @param {Oas20SecurityDefinitions} node
     */
    Oas20DataModelWriter.prototype.visitSecurityDefinitions = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writeExtraProperties(json, node);
        JsonCompat.setProperty(parent, Constants.PROP_SECURITY_DEFINITIONS, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeSecurityScheme(java.lang.Object, io.apicurio.datamodels.core.models.common.SecurityScheme)
     * @param {*} json
     * @param {SecurityScheme} node
     */
    Oas20DataModelWriter.prototype.writeSecurityScheme = function (json, node) {
        var node20 = node;
        JsonCompat.setPropertyString(json, Constants.PROP_FLOW, node20.flow);
        JsonCompat.setPropertyString(json, Constants.PROP_AUTHORIZATION_URL, node20.authorizationUrl);
        JsonCompat.setPropertyString(json, Constants.PROP_TOKEN_URL, node20.tokenUrl);
        JsonCompat.setPropertyNull(json, Constants.PROP_SCOPES);
        _super.prototype.writeSecurityScheme.call(this, json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitScopes(io.apicurio.datamodels.openapi.v2.models.Oas20Scopes)
     * @param {Oas20Scopes} node
     */
    Oas20DataModelWriter.prototype.visitScopes = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        {
            var array185 = node.getScopeNames();
            for (var index184 = 0; index184 < array185.length; index184++) {
                var scope = array185[index184];
                {
                    var description = node.getScopeDescription(scope);
                    JsonCompat.setPropertyString(json, scope, description);
                }
            }
        }
        JsonCompat.setProperty(parent, Constants.PROP_SCOPES, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20Definitions)
     * @param {Oas20Definitions} node
     */
    Oas20DataModelWriter.prototype.visitDefinitions = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        if ( /* size */node.getDefinitionNames().length > 0) {
            JsonCompat.setProperty(parent, Constants.PROP_DEFINITIONS, json);
            this.updateIndex(node, json);
        }
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelWriter#writeSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
     * @param {*} json
     * @param {Schema} node
     */
    Oas20DataModelWriter.prototype.writeSchema = function (json, node) {
        _super.prototype.writeSchema.call(this, json, node);
        var schema = node;
        JsonCompat.setPropertyString(json, Constants.PROP_DISCRIMINATOR, schema.discriminator);
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelWriter#writeOperation(java.lang.Object, io.apicurio.datamodels.core.models.common.Operation)
     * @param {*} json
     * @param {Operation} node
     */
    Oas20DataModelWriter.prototype.writeOperation = function (json, node) {
        var operation = node;
        JsonCompat.setPropertyStringArray(json, Constants.PROP_CONSUMES, operation.consumes);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_PRODUCES, operation.produces);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_SCHEMES, operation.schemes);
        _super.prototype.writeOperation.call(this, json, node);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitParameterDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinitions)
     * @param {Oas20ParameterDefinitions} node
     */
    Oas20DataModelWriter.prototype.visitParameterDefinitions = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        if ( /* size */node.getParameterNames().length > 0) {
            JsonCompat.setProperty(parent, Constants.PROP_PARAMETERS, json);
            this.updateIndex(node, json);
        }
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {*} json
     * @param {Parameter} node
     */
    Oas20DataModelWriter.prototype.writeParameter = function (json, node) {
        _super.prototype.writeParameter.call(this, json, node);
        var param = node;
        JsonCompat.setPropertyString(json, Constants.PROP_TYPE, param.type);
        JsonCompat.setPropertyString(json, Constants.PROP_FORMAT, param.format);
        JsonCompat.setPropertyNull(json, Constants.PROP_ITEMS);
        JsonCompat.setPropertyString(json, Constants.PROP_COLLECTION_FORMAT, param.collectionFormat);
        JsonCompat.setProperty(json, Constants.PROP_DEFAULT, param.default_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAXIMUM, param.maximum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM, param.exclusiveMaximum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MINIMUM, param.minimum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM, param.exclusiveMinimum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_LENGTH, param.maxLength);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_LENGTH, param.minLength);
        JsonCompat.setPropertyString(json, Constants.PROP_PATTERN, param.pattern);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_ITEMS, param.maxItems);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_ITEMS, param.minItems);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS, param.uniqueItems);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_ENUM, param.enum_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MULTIPLE_OF, param.multipleOf);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
     * @param {*} node
     */
    Oas20DataModelWriter.prototype.visitExample = function (node) {
        var example20 = node;
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(example20);
        var json = JsonCompat.objectNode();
        var contentTypes = example20.getExampleContentTypes();
        contentTypes.forEach((function (json, example20) {
            return function (ct) {
                var example = example20.getExample(ct);
                JsonCompat.setProperty(json, ct, example);
            };
        })(json, example20));
        JsonCompat.setProperty(parent, Constants.PROP_EXAMPLES, json);
        this.updateIndex(example20, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitHeaders(io.apicurio.datamodels.openapi.v2.models.Oas20Headers)
     * @param {Oas20Headers} node
     */
    Oas20DataModelWriter.prototype.visitHeaders = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        if ( /* size */node.getHeaderNames().length > 0) {
            JsonCompat.setProperty(parent, Constants.PROP_HEADERS, json);
            this.updateIndex(node, json);
        }
    };
    /**
     * @see io.apicurio.datamodels.openapi.io.OasDataModelWriter#writeHeader(java.lang.Object, io.apicurio.datamodels.openapi.models.OasHeader)
     * @param {*} json
     * @param {OasHeader} node
     */
    Oas20DataModelWriter.prototype.writeHeader = function (json, node) {
        _super.prototype.writeHeader.call(this, json, node);
        var header = node;
        JsonCompat.setPropertyString(json, Constants.PROP_TYPE, header.type);
        JsonCompat.setPropertyString(json, Constants.PROP_FORMAT, header.format);
        JsonCompat.setPropertyNull(json, Constants.PROP_ITEMS);
        JsonCompat.setPropertyString(json, Constants.PROP_COLLECTION_FORMAT, header.collectionFormat);
        JsonCompat.setProperty(json, Constants.PROP_DEFAULT, header.default_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAXIMUM, header.maximum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM, header.exclusiveMaximum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MINIMUM, header.minimum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM, header.exclusiveMinimum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_LENGTH, header.maxLength);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_LENGTH, header.minLength);
        JsonCompat.setPropertyString(json, Constants.PROP_PATTERN, header.pattern);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_ITEMS, header.maxItems);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_ITEMS, header.minItems);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS, header.uniqueItems);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_ENUM, header.enum_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MULTIPLE_OF, header.multipleOf);
    };
    /**
     * @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitResponseDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinitions)
     * @param {Oas20ResponseDefinitions} node
     */
    Oas20DataModelWriter.prototype.visitResponseDefinitions = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        if ( /* size */node.getResponseNames().length > 0) {
            JsonCompat.setProperty(parent, Constants.PROP_RESPONSES, json);
            this.updateIndex(node, json);
        }
    };
    return Oas20DataModelWriter;
}(OasDataModelWriter));
export { Oas20DataModelWriter };
Oas20DataModelWriter["__class"] = "io.apicurio.datamodels.openapi.v2.io.Oas20DataModelWriter";
Oas20DataModelWriter["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
//# sourceMappingURL=Oas20DataModelWriter.js.map