You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pathPrefix not used when using self import mapping #1779
The template added in #1774 breaks when there is one import mapping of value "-":
{{ if .ImportMapping }}
pathPrefix:=path.Dir(pathToFile)
{{ end }}
{{ range $key, $value:= .ImportMapping }}
{{ range $key, $value:= .ImportMapping }}{{-ifne $value.Path "-"}}
forrawPath, rawFunc:=range {{ $value.Name }}.PathToRawSpec(path.Join(pathPrefix, "{{ $key }}")) {
if_, ok:=res[rawPath]; ok {
// it is not possible to compare functions in golang, so always overwrite the old value
}
res[rawPath] =rawFunc
}
{{-end }}
{{-end }}{{-end }}
returnres
Results in this generated code:
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.funcPathToRawSpec(pathToFilestring) map[string]func() ([]byte, error) {
res:=make(map[string]func() ([]byte, error))
iflen(pathToFile) >0 {
res[pathToFile] =rawSpec
}
pathPrefix:=path.Dir(pathToFile)
returnres
}
And this error
go build
gen.go:366:2: declared and not used: pathPrefix
Activity
[-]Broken template i[/-][+]Broken template with pathPrefix not used[/+][-]Broken template with pathPrefix not used[/-][+]pathPrefix not used when using self import mapping[/+]jamietanna commentedon Sep 24, 2024
Thanks for the report! As this is related to the last release, will try and do a quick fix + release, when I'm back from holiday later this week.
Would also welcome a PR if anyone fancies ☺
ottaviohartman commentedon Sep 24, 2024
Enjoy your vacation! Opened a PR for when you're back.
fix(import-mapping): don't produce unused variable when one mapping (o…