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

Function generate

packages/tools/openapi-generator/src/JsonSchemaGenerator.ts:67–127  ·  view source on GitHub ↗
(
    source: Source,
    components: JsonSchema.Definitions,
    typeOnly: boolean,
    options?: GenerateOptions
  )

Source from the content-addressed store, hash-verified

65 }
66
67 function generate(
68 source: Source,
69 components: JsonSchema.Definitions,
70 typeOnly: boolean,
71 options?: GenerateOptions
72 ) {
73 const generated = makeCodeDocument(source, components, options)
74 if (generated === undefined) {
75 return ""
76 }
77
78 const nonRecursiveReferences = generated.codeDocument.references.nonRecursives
79 const recursiveReferences = Object.entries(generated.codeDocument.references.recursives)
80
81 const nonRecursives = nonRecursiveReferences.map(({ $ref, code }) =>
82 renderSchemaTypeAndRuntime($ref, code, typeOnly)
83 )
84
85 const recursiveDeclarations: Array<string> = []
86 const recursives: Array<string> = []
87
88 if (typeOnly) {
89 for (const [$ref, code] of recursiveReferences) {
90 recursives.push(renderSchemaTypeAndRuntime($ref, code, true))
91 }
92 } else {
93 const recursivelyForwardReferenced = collectForwardReferencedRecursives(
94 nonRecursiveReferences,
95 recursiveReferences
96 )
97 const recursiveInternalNames = makeRecursiveInternalNameMap(
98 recursivelyForwardReferenced,
99 [
100 ...nonRecursiveReferences.map(({ $ref }) => $ref),
101 ...recursiveReferences.map(([$ref]) => $ref),
102 ...generated.nameMap
103 ]
104 )
105
106 for (const [$ref, code] of recursiveReferences) {
107 if (recursivelyForwardReferenced.has($ref)) {
108 const internalName = recursiveInternalNames.get($ref)!
109 recursiveDeclarations.push(renderRecursiveReferenceDeclaration($ref, code, internalName))
110 recursives.push(`const ${internalName} = ${code.runtime}`)
111 continue
112 }
113
114 recursives.push(renderSchemaTypeAndRuntime($ref, code, false))
115 }
116 }
117
118 const codes = generated.codeDocument.codes.map((code, i) =>
119 renderSchemaTypeAndRuntime(generated.nameMap[i], code, typeOnly)
120 )
121
122 return renderImportArtifacts(generated.codeDocument, !typeOnly) +
123 render("recursive declarations", recursiveDeclarations) +
124 render("non-recursive definitions", nonRecursives) +

Callers

nothing calls this directly

Calls 11

makeCodeDocumentFunction · 0.85
renderImportArtifactsFunction · 0.85
pushMethod · 0.80
renderFunction · 0.70
getMethod · 0.65
mapMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected