MCPcopy Create free account
hub / github.com/Effect-TS/effect / fromApi

Function fromApi

packages/platform/src/OpenApi.ts:229–450  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<Id, Groups, E, R>,
  options?: {
    readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy | undefined
  } | undefined
)

Source from the content-addressed store, hash-verified

227 * @since 1.0.0
228 */
229export const fromApi = <Id extends string, Groups extends HttpApiGroup.Any, E, R>(
230 api: HttpApi.HttpApi<Id, Groups, E, R>,
231 options?: {
232 readonly additionalPropertiesStrategy?: AdditionalPropertiesStrategy | undefined
233 } | undefined
234): OpenAPISpec => {
235 const cached = apiCache.get(api)
236 if (cached !== undefined) {
237 return cached
238 }
239 const jsonSchemaDefs: Record<string, JsonSchema.JsonSchema> = {}
240 let spec: OpenAPISpec = {
241 openapi: "3.1.0",
242 info: {
243 title: Context.getOrElse(api.annotations, Title, () => "Api"),
244 version: Context.getOrElse(api.annotations, Version, () => "0.0.1")
245 },
246 paths: {},
247 components: {
248 schemas: jsonSchemaDefs,
249 securitySchemes: {}
250 },
251 security: [],
252 tags: []
253 }
254
255 function processAST(ast: AST.AST): JsonSchema.JsonSchema {
256 return JsonSchema.fromAST(ast, {
257 defs: jsonSchemaDefs,
258 additionalPropertiesStrategy: options?.additionalPropertiesStrategy
259 })
260 }
261
262 function processHttpApiSecurity(
263 name: string,
264 security: HttpApiSecurity
265 ) {
266 if (spec.components.securitySchemes[name] !== undefined) {
267 return
268 }
269 spec.components.securitySchemes[name] = makeSecurityScheme(security)
270 }
271
272 processAnnotation(api.annotations, HttpApi.AdditionalSchemas, (componentSchemas) => {
273 componentSchemas.forEach((componentSchema) => processAST(componentSchema.ast))
274 })
275 processAnnotation(api.annotations, Description, (description) => {
276 spec.info.description = description
277 })
278 processAnnotation(api.annotations, License, (license) => {
279 spec.info.license = license
280 })
281 processAnnotation(api.annotations, Summary, (summary) => {
282 spec.info.summary = summary
283 })
284 processAnnotation(api.annotations, Servers, (servers) => {
285 spec.servers = [...servers]
286 })

Callers

nothing calls this directly

Calls 6

processAnnotationFunction · 0.85
processASTFunction · 0.85
processHttpApiSecurityFunction · 0.85
entriesMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected