MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / LoadTemplates

Function LoadTemplates

pkg/codegen/codegen.go:1253–1275  ·  view source on GitHub ↗

LoadTemplates loads all of our template files into a text/template. The path of template is relative to the templates directory.

(src embed.FS, t *template.Template)

Source from the content-addressed store, hash-verified

1251// LoadTemplates loads all of our template files into a text/template. The
1252// path of template is relative to the templates directory.
1253func LoadTemplates(src embed.FS, t *template.Template) error {
1254 return fs.WalkDir(src, "templates", func(path string, d fs.DirEntry, err error) error {
1255 if err != nil {
1256 return fmt.Errorf("error walking directory %s: %w", path, err)
1257 }
1258 if d.IsDir() {
1259 return nil
1260 }
1261
1262 buf, err := src.ReadFile(path)
1263 if err != nil {
1264 return fmt.Errorf("error reading file '%s': %w", path, err)
1265 }
1266
1267 templateName := strings.TrimPrefix(path, "templates/")
1268 tmpl := t.New(templateName)
1269 _, err = tmpl.Parse(string(buf))
1270 if err != nil {
1271 return fmt.Errorf("parsing template '%s': %w", path, err)
1272 }
1273 return nil
1274 })
1275}
1276
1277func OperationSchemaImports(s *Schema) (map[string]goImport, error) {
1278 res := map[string]goImport{}

Callers 2

renderServerURLsFunction · 0.85
GenerateFunction · 0.85

Calls

no outgoing calls

Tested by 1

renderServerURLsFunction · 0.68