Skip to content

pathPrefix not used when using self import mapping #1779

Closed

Description

@ottaviohartman

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 }}{{- if ne $value.Path "-"}}
    for rawPath, 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 }}
    return res

Results in this generated code:

// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
	res := make(map[string]func() ([]byte, error))
	if len(pathToFile) > 0 {
		res[pathToFile] = rawSpec
	}

	pathPrefix := path.Dir(pathToFile)

	return res
}

And this error

go build
gen.go:366:2: declared and not used: pathPrefix

Activity

  1. changed the title [-]Broken template i[/-] [+]Broken template with pathPrefix not used[/+] on Sep 23, 2024
  2. changed the title [-]Broken template with pathPrefix not used[/-] [+]pathPrefix not used when using self import mapping[/+] on Sep 23, 2024
  3. added
    bug
    on Sep 24, 2024
  4. self-assigned this
    on Sep 24, 2024
  5. jamietanna commented on Sep 24, 2024

    @jamietanna
    Member

    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 ☺

  6. ottaviohartman commented on Sep 24, 2024

    @ottaviohartman
    ContributorAuthor

    Enjoy your vacation! Opened a PR for when you're back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions