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 { NodeCompat } from '../../compat/NodeCompat';
import { Constants } from '../../core/Constants';
import { DataModelWriter } from '../../core/io/DataModelWriter';
/**
 * Data model writer for OpenAPI data models (base class).
 * @author eric.wittmann@gmail.com
 * @class
 * @extends DataModelWriter
 */
var OasDataModelWriter = /** @class */ (function (_super) {
    __extends(OasDataModelWriter, _super);
    function OasDataModelWriter() {
        return _super.call(this) || this;
    }
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPaths(io.apicurio.datamodels.openapi.models.OasPaths)
     * @param {OasPaths} node
     */
    OasDataModelWriter.prototype.visitPaths = 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_PATHS, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)
     * @param {OasPathItem} node
     */
    OasDataModelWriter.prototype.visitPathItem = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writePathItem(json, node);
        this.writeExtraProperties(json, node);
        JsonCompat.setProperty(parent, node.getPath(), json);
        this.updateIndex(node, json);
    };
    OasDataModelWriter.prototype.writePathItem = function (json, node) {
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyNull(json, Constants.PROP_GET);
        JsonCompat.setPropertyNull(json, Constants.PROP_PUT);
        JsonCompat.setPropertyNull(json, Constants.PROP_POST);
        JsonCompat.setPropertyNull(json, Constants.PROP_DELETE);
        JsonCompat.setPropertyNull(json, Constants.PROP_OPTIONS);
        JsonCompat.setPropertyNull(json, Constants.PROP_HEAD);
        JsonCompat.setPropertyNull(json, Constants.PROP_PATCH);
        JsonCompat.setPropertyNull(json, Constants.PROP_PARAMETERS);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponse(io.apicurio.datamodels.openapi.models.OasResponse)
     * @param {OasResponse} node
     */
    OasDataModelWriter.prototype.visitResponse = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writeResponse(json, node);
        this.writeExtraProperties(json, node);
        var responseCode = node.getName();
        if (responseCode == null) {
            responseCode = Constants.PROP_DEFAULT;
        }
        JsonCompat.setProperty(parent, responseCode, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponses(io.apicurio.datamodels.openapi.models.OasResponses)
     * @param {OasResponses} node
     */
    OasDataModelWriter.prototype.visitResponses = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyNull(json, Constants.PROP_DEFAULT);
        this.writeExtraProperties(json, node);
        JsonCompat.setProperty(parent, Constants.PROP_RESPONSES, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitXML(io.apicurio.datamodels.openapi.models.OasXML)
     * @param {OasXML} node
     */
    OasDataModelWriter.prototype.visitXML = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        JsonCompat.setPropertyString(json, Constants.PROP_NAME, node.name);
        JsonCompat.setPropertyString(json, Constants.PROP_NAMESPACE, node.namespace);
        JsonCompat.setPropertyString(json, Constants.PROP_PREFIX, node.prefix);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_ATTRIBUTE, node.attribute);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_WRAPPED, node.wrapped);
        this.writeExtraProperties(json, node);
        JsonCompat.setProperty(parent, Constants.PROP_XML, json);
        this.updateIndex(node, json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    OasDataModelWriter.prototype.visitAllOfSchema = function (node) {
        this.doVisitSchema(node, Constants.PROP_ALL_OF, true);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitItemsSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    OasDataModelWriter.prototype.visitItemsSchema = function (node) {
        var parentSchema = node;
        this.doVisitSchema(node, Constants.PROP_ITEMS, NodeCompat.isList(parentSchema.items));
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAdditionalPropertiesSchema(io.apicurio.datamodels.openapi.models.OasSchema)
     * @param {OasSchema} node
     */
    OasDataModelWriter.prototype.visitAdditionalPropertiesSchema = function (node) {
        this.doVisitSchema(node, Constants.PROP_ADDITIONAL_PROPERTIES, false);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPropertySchema(io.apicurio.datamodels.openapi.models.IOasPropertySchema)
     * @param {*} node
     */
    OasDataModelWriter.prototype.visitPropertySchema = function (node) {
        var schema = node;
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(schema);
        var json = JsonCompat.objectNode();
        this.writeSchema(json, schema);
        this.writeExtraProperties(json, schema);
        var properties = JsonCompat.getProperty(parent, Constants.PROP_PROPERTIES);
        if (properties == null) {
            properties = JsonCompat.objectNode();
            JsonCompat.setProperty(parent, Constants.PROP_PROPERTIES, properties);
        }
        JsonCompat.setProperty(properties, node.getPropertyName(), json);
        this.updateIndex(schema, json);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
     * @param {*} json
     * @param {Schema} node
     */
    OasDataModelWriter.prototype.writeSchema = function (json, node) {
        var schema = node;
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, schema.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_FORMAT, schema.format);
        JsonCompat.setPropertyString(json, Constants.PROP_TITLE, schema.title);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, schema.description);
        JsonCompat.setProperty(json, Constants.PROP_DEFAULT, schema.default_);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MULTIPLE_OF, schema.multipleOf);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAXIMUM, schema.maximum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM, schema.exclusiveMaximum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MINIMUM, schema.minimum);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM, schema.exclusiveMinimum);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_LENGTH, schema.maxLength);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_LENGTH, schema.minLength);
        JsonCompat.setPropertyString(json, Constants.PROP_PATTERN, schema.pattern);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_ITEMS, schema.maxItems);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_ITEMS, schema.minItems);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS, schema.uniqueItems);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_PROPERTIES, schema.maxProperties);
        JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_PROPERTIES, schema.minProperties);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_REQUIRED, schema.required);
        JsonCompat.setPropertyStringArray(json, Constants.PROP_ENUM, schema.enum_);
        JsonCompat.setPropertyString(json, Constants.PROP_TYPE, schema.type);
        JsonCompat.setPropertyNull(json, Constants.PROP_ITEMS);
        JsonCompat.setPropertyNull(json, Constants.PROP_ALL_OF);
        JsonCompat.setPropertyNull(json, Constants.PROP_PROPERTIES);
        if (NodeCompat.isNode(schema.additionalProperties)) {
            JsonCompat.setPropertyNull(json, Constants.PROP_ADDITIONAL_PROPERTIES);
        }
        else {
            JsonCompat.setPropertyBoolean(json, Constants.PROP_ADDITIONAL_PROPERTIES, schema.additionalProperties);
        }
        JsonCompat.setPropertyBoolean(json, Constants.PROP_READ_ONLY, schema.readOnly);
        JsonCompat.setPropertyNull(json, Constants.PROP_XML);
        JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
        JsonCompat.setProperty(json, Constants.PROP_EXAMPLE, schema.example);
        _super.prototype.writeSchema.call(this, json, schema);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeOperation(java.lang.Object, io.apicurio.datamodels.core.models.common.Operation)
     * @param {*} json
     * @param {Operation} node
     */
    OasDataModelWriter.prototype.writeOperation = function (json, node) {
        var operation = node;
        JsonCompat.setPropertyStringArray(json, Constants.PROP_TAGS, operation.tags);
        JsonCompat.setPropertyNull(json, Constants.PROP_PARAMETERS);
        JsonCompat.setPropertyNull(json, Constants.PROP_RESPONSES);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_DEPRECATED, operation.deprecated);
        JsonCompat.setPropertyNull(json, Constants.PROP_SECURITY);
        _super.prototype.writeOperation.call(this, json, node);
    };
    /**
     * @see io.apicurio.datamodels.core.io.DataModelWriter#writeParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
     * @param {*} json
     * @param {Parameter} node
     */
    OasDataModelWriter.prototype.writeParameter = function (json, node) {
        _super.prototype.writeParameter.call(this, json, node);
        var param = node;
        JsonCompat.setPropertyString(json, Constants.PROP_IN, param.in);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_REQUIRED, param.required);
        JsonCompat.setPropertyBoolean(json, Constants.PROP_ALLOW_EMPTY_VALUE, param.allowEmptyValue);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitHeader(io.apicurio.datamodels.openapi.models.OasHeader)
     * @param {OasHeader} node
     */
    OasDataModelWriter.prototype.visitHeader = function (node) {
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(node);
        var json = JsonCompat.objectNode();
        this.writeHeader(json, node);
        this.writeExtraProperties(json, node);
        this.addHeaderToParent(parent, json, node);
        this.updateIndex(node, json);
    };
    OasDataModelWriter.prototype.writeHeader = function (json, node) {
        JsonCompat.setProperty(json, Constants.PROP_DESCRIPTION, node.description);
    };
    OasDataModelWriter.prototype.addHeaderToParent = function (parent, json, node) {
        JsonCompat.setProperty(parent, node.getName(), json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponseDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
     * @param {*} node
     */
    OasDataModelWriter.prototype.visitResponseDefinition = function (node) {
        var response = node;
        var parent = this.lookupParentJson$io_apicurio_datamodels_core_models_Node(response);
        var json = JsonCompat.objectNode();
        this.writeResponse(json, response);
        this.writeExtraProperties(json, response);
        this.addResponseDefinitionToParent(parent, json, node);
        this.updateIndex(response, json);
    };
    OasDataModelWriter.prototype.writeResponse = function (json, node) {
        JsonCompat.setPropertyString(json, Constants.PROP_$REF, node.$ref);
        JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, node.description);
    };
    OasDataModelWriter.prototype.addResponseDefinitionToParent = function (parent, json, node) {
        JsonCompat.setProperty(parent, node.getName(), json);
    };
    /**
     * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
     * @param {*} node
     */
    OasDataModelWriter.prototype.visitExample = function (node) {
        throw Object.defineProperty(new Error("Must be implemented by subclasses."), '__classes', { configurable: true, value: ['java.lang.Throwable', 'java.lang.Object', 'java.lang.RuntimeException', 'java.lang.Exception'] });
    };
    return OasDataModelWriter;
}(DataModelWriter));
export { OasDataModelWriter };
OasDataModelWriter["__class"] = "io.apicurio.datamodels.openapi.io.OasDataModelWriter";
OasDataModelWriter["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
//# sourceMappingURL=OasDataModelWriter.js.map