@itwin/core-common
Version:
iTwin.js components common to frontend and backend
63 lines • 2.5 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RpcOpenAPIDescription = void 0;
const RpcOperation_1 = require("../core/RpcOperation");
/** An OpenAPI-compatible description of an RPC protocol.
* @internal
*/
class RpcOpenAPIDescription {
/** The protocol for this description. */
protocol;
/** The OpenAPI paths object for the protocol. */
get paths() {
const paths = {};
this.protocol.configuration.interfaces().forEach((definition) => {
RpcOperation_1.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;
}
}
exports.RpcOpenAPIDescription = RpcOpenAPIDescription;
//# sourceMappingURL=OpenAPI.js.map