/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module RpcInterface
 */
import { RpcOperation } from "../core/RpcOperation";
/** An OpenAPI-compatible description of an RPC protocol.
 * @internal
 */
export class RpcOpenAPIDescription {
    /** The OpenAPI paths object for the protocol. */
    get paths() {
        const paths = {};
        this.protocol.configuration.interfaces().forEach((definition) => {
            RpcOperation.forEach(definition, (operation) => {
                const path = this.protocol.supplyPathForOperation(operation, undefined);
                paths[path] = this.generateDescription(operation);
            });
        });
        return paths;
    }
    /** An OpenAPI 3.0 (Swagger) description of the RESTful API that is exposed through the protocol. */
    get document() {
        return {
            openapi: "3.0.0",
            info: this.protocol.info,
            paths: this.paths,
        };
    }
    /** Creates an OpenAPI description of an RPC protocol. */
    constructor(protocol) {
        this.protocol = protocol;
    }
    /** Converts to JSON. */
    toJSON() {
        return this.document;
    }
    generateDescription(operation) {
        const requestContent = { "application/json": { schema: { type: "array" } } };
        const responseContent = { "application/json": { schema: { type: "object" } } };
        const description = {};
        description.head = {
            requestBody: { content: requestContent, required: true },
            responses: {
                200: { description: "Success", content: responseContent },
                default: { description: "Error", content: responseContent },
            },
        };
        const parameters = this.protocol.supplyPathParametersForOperation(operation);
        if (parameters.length)
            description.parameters = parameters;
        return description;
    }
}
//# sourceMappingURL=OpenAPI.js.map