(importMapping map[string]string)
| 103 | } |
| 104 | |
| 105 | func constructImportMapping(importMapping map[string]string) importMap { |
| 106 | var ( |
| 107 | pathToImport = importMap{} |
| 108 | result = importMap{} |
| 109 | ) |
| 110 | |
| 111 | { |
| 112 | packagePaths := slices.Collect(maps.Values(importMapping)) |
| 113 | slices.Sort(packagePaths) |
| 114 | |
| 115 | for _, packagePath := range packagePaths { |
| 116 | if _, ok := pathToImport[packagePath]; !ok && packagePath != importMappingCurrentPackage { |
| 117 | split := strings.Split(packagePath, " ") |
| 118 | if len(split) == 2 { |
| 119 | // if we have 2 parts, we assume both the package name and path are provided, and we use them as is |
| 120 | pathToImport[packagePath] = goImport{ |
| 121 | Name: split[0], |
| 122 | Path: split[1], |
| 123 | } |
| 124 | } else { |
| 125 | // otherwise, we auto-generate a package name based on the order of the imports, to ensure deterministic output |
| 126 | pathToImport[packagePath] = goImport{ |
| 127 | Name: fmt.Sprintf("externalRef%d", len(pathToImport)), |
| 128 | Path: packagePath, |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | for specPath, packagePath := range importMapping { |
| 135 | if packagePath == importMappingCurrentPackage { |
| 136 | result[specPath] = goImport{ |
| 137 | Path: importMappingCurrentPackage, |
| 138 | } |
| 139 | } else { |
| 140 | result[specPath] = pathToImport[packagePath] |
| 141 | } |
| 142 | } |
| 143 | return result |
| 144 | } |
| 145 | |
| 146 | // Generate uses the Go templating engine to generate all of our server wrappers from |
| 147 | // the descriptions we've built up above from the schema objects. |
no outgoing calls