// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. /* * Copyright (c) 杭州颉创科技有限公司 2025. All rights reserved. * This source file is licensed under the MIT License found in the * LICENSE file in the root directory of this source tree. */ package simcu::simapi.openapi import std.collection.* import simcu::simapi.openapi.models.* import soulsoft_extensions_options.* import soulsoft_extensions_injection.* /** * @brief 提供 OpenAPI 文档创建能力。 */ protected class OpenApiDocumentProvider <: IDocumentProvider { private let _services: IServiceProvider private let _options: IOptionsMonitor /** * @brief 创建 OpenAPI 文档提供器实例。 * @param services 服务提供器。 * @param options OpenAPI 选项监视器。 * @param provider OpenAPI 文档生成服务。 */ public init(services: IServiceProvider, options: IOptionsMonitor) { _services = services _options = options } /** * @brief 返回已注册的文档名称集合。 * @return 当前可用的文档名称集合。 */ public func getDooucmentNames(): Collection { _services.getAll() |> map {f => f.name} |> collectArray } /** * @brief 按名称创建 OpenAPI 文档。 * @param documentName 要创建的文档名称。 * @param services 请求作用域的服务提供器。 * @return OpenAPI 文档。 */ public func create(documentName: String, services: IServiceProvider): OpenApiDocument { let options = _options.get(documentName) let schemaService = OpenApiSchemaService(options, services, documentName) let parameterService = OpenApiParameterService(schemaService) let provider = ActivatorUtilities.createInstance( services, documentName, schemaService, parameterService ) return provider.getOpenApiDocument(services) } }