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

Function processPath

packages/tools/openapi-generator/src/OpenApiGenerator.ts:1634–1668  ·  view source on GitHub ↗
(path: string, parameters: ReadonlyArray<OpenApiParameter>)

Source from the content-addressed store, hash-verified

1632)
1633
1634const processPath = (path: string, parameters: ReadonlyArray<OpenApiParameter>): {
1635 readonly pathIds: Array<string>
1636 readonly pathTemplate: string
1637 readonly pathSchema: JsonSchema.JsonSchema | undefined
1638} => {
1639 const pathIds: Array<string> = []
1640 const fragments: Array<string> = []
1641 const properties: Record<string, JsonSchema.JsonSchema> = {}
1642 const required: Array<string> = []
1643 let offset = 0
1644 for (const match of path.matchAll(/{([^}]+)}/g)) {
1645 fragments.push(JSON.stringify(path.slice(offset, match.index)))
1646 const name = match[1]
1647 const parameter = parameters.find((parameter) => parameter.in === "path" && parameter.name === name)
1648 const style = parameter?.style ?? "simple"
1649 if (style !== "simple" && style !== "label" && style !== "matrix") {
1650 throw new Error(`Unsupported path parameter style "${style}" for "${name}" in "${path}"`)
1651 }
1652 const id = Utils.camelize(name)
1653 pathIds.push(id)
1654 fragments.push(
1655 `__encodePathParam(${JSON.stringify(name)}, ${id}, ${JSON.stringify(style)}, ${parameter?.explode === true})`
1656 )
1657 Rec.assignProperty(properties, name, parameter?.schema as JsonSchema.JsonSchema ?? { type: "string" })
1658 required.push(name)
1659 offset = match.index + match[0].length
1660 }
1661 fragments.push(JSON.stringify(path.slice(offset)))
1662 const pathTemplate = fragments.join(" + ")
1663 return {
1664 pathIds,
1665 pathTemplate,
1666 pathSchema: pathIds.length === 0 ? undefined : { type: "object", properties, required, additionalProperties: false }
1667 }
1668}

Callers 1

parseOpenApiFunction · 0.85

Calls 4

sliceMethod · 0.80
pushMethod · 0.65
findMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected