function visitUrls()

in compiler/src/model/build-model.ts [623:686]


function visitUrls (member: PropertyDeclaration | PropertySignature): model.UrlTemplate[] {
  const value = member.getTypeNode()

  // Literal arrays are exposed as tuples by ts-morph
  assert(value, Node.isTupleTypeNode(value), '"urls" should be an array')

  const result: model.UrlTemplate[] = []

  value.forEachChild(urlNode => {
    assert(urlNode, Node.isTypeLiteral(urlNode), '"urls" members should be objects')

    const urlTemplate: any = {}

    urlNode.forEachChild(node => {
      assert(node, Node.isPropertySignature(node), "Expecting 'path' and 'methods' properties")

      const name = node.getName()
      const propValue = node.getTypeNode()

      if (name === 'path') {
        assert(propValue, Node.isLiteralTypeNode(propValue), '"path" should be a string')

        const pathLit = propValue.getLiteral()
        assert(pathLit, Node.isStringLiteral(pathLit), '"path" should be a string')

        urlTemplate.path = pathLit.getLiteralValue()

        // Deprecation
        const jsDoc = node.getJsDocs()
        const tags = parseJsDocTags(jsDoc)
        const deprecation = parseDeprecation(tags, jsDoc)
        if (deprecation != null) {
          urlTemplate.deprecation = deprecation
        }
        if (Object.keys(tags).length > 0) {
          assert(jsDoc, false, `Unknown annotations: ${Object.keys(tags).join(', ')}`)
        }
      } else if (name === 'methods') {
        assert(propValue, Node.isTupleTypeNode(propValue), '"methods" should be an array')

        const methods: string[] = []
        propValue.forEachChild(node => {
          assert(node, Node.isLiteralTypeNode(node), '"methods" should contain strings')

          const nodeLit = node.getLiteral()
          assert(nodeLit, Node.isStringLiteral(nodeLit), '"methods" should contain strings')

          methods.push(nodeLit.getLiteralValue())
        })
        assert(node, methods.length > 0, "'methods' should not be empty")
        urlTemplate.methods = methods
      } else {
        assert(node, false, "Expecting 'path' or 'methods'")
      }
    })

    assert(urlTemplate, urlTemplate.path, "Missing required property 'path'")
    assert(urlTemplate, urlTemplate.methods, "Missing required property 'methods'")

    result.push(urlTemplate)
  })

  return result
}