"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SpecGenerator31 = void 0;
const merge_anything_1 = require("merge-anything");
const ts_deepmerge_1 = require("ts-deepmerge");
const specGenerator3_1 = require("./specGenerator3");
/**
 * OpenAPI 3.1 Spec Generator
 *
 * Extends SpecGenerator3 with OpenAPI 3.1 specific features:
 * - Tuple support via prefixItems
 * - OpenAPI version 3.1.0
 *
 * Uses inheritance to reuse all building logic from SpecGenerator3,
 * only overriding the version and adding tuple type support.
 */
class SpecGenerator31 extends specGenerator3_1.SpecGenerator3 {
    constructor(metadata, config) {
        super(metadata, config);
        this.metadata = metadata;
        this.config = config;
    }
    // Override with OpenAPI 3.1 specific return type
    // The base class returns Swagger.Spec30, but this generator produces Swagger.Spec31
    GetSpec() {
        let spec = {
            openapi: '3.1.0',
            components: this.buildComponents(),
            info: this.buildInfo(),
            paths: this.buildPaths(),
            servers: this.buildServers(),
            tags: this.config.tags,
        };
        if (this.config.spec) {
            this.config.specMerging = this.config.specMerging || 'immediate';
            const mergeFuncs = {
                immediate: Object.assign,
                recursive: merge_anything_1.merge,
                deepmerge: (spec, merge) => (0, ts_deepmerge_1.merge)(spec, merge),
            };
            spec = mergeFuncs[this.config.specMerging](spec, this.config.spec);
        }
        return spec;
    }
    /**
     * Override to add tuple type support (OpenAPI 3.1 feature via prefixItems)
     */
    getSwaggerType(type, title) {
        if (this.isTupleType(type)) {
            const prefixItems = type.types.map((t) => this.getSwaggerType(t));
            const schema = {
                type: 'array',
                prefixItems,
                minItems: prefixItems.length,
                ...(type.restType
                    ? {
                        items: this.getSwaggerType(type.restType),
                    }
                    : {
                        maxItems: prefixItems.length,
                        items: false,
                    }),
            };
            return schema;
        }
        return super.getSwaggerType(type, title);
    }
    isTupleType(type) {
        return type.dataType === 'tuple';
    }
}
exports.SpecGenerator31 = SpecGenerator31;
//# sourceMappingURL=specGenerator31.js.map