-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support loading external files in OpenAPI #8067
Comments
My OpenAPI YAMLs are getting pretty big, would be appreciated |
Question: I assume that you by external (mostly) mean files on the same file system (and not remote files)? |
As for me, yes on the same file system. |
Same for me, all on the same file system. |
OK, I hadded the initial OpenAPi support in Hugo, and the project I used it in has the API source mounted as a Hugo Module. So, this is what we need to do:
|
I was able to hack something together that works for my specific use-case, but isn't production ready. There are a number of issues
loader := kopenapi3.NewSwaggerLoader()
loader.IsExternalRefsAllowed = true
loader.ReadFromURIFunc = func(loader *kopenapi3.SwaggerLoader, url *url.URL) ([]byte, error) {
if url.Scheme != "" || url.Host != "" || url.RawQuery != "" {
return nil, errors.Errorf("unsupported URI: %q", url.String())
}
fullpath := filepath.Join(filepath.Dir(key), url.Path)
assetpath := ns.deps.SourceFilesystems.Assets.RealDirs(fullpath)[0]
return ioutil.ReadFile(assetpath)
}
err = loader.ResolveRefsIn(s, nil) |
@illeatmyhat It's hard for me to debug your example/code without additional context, but I'll try:
There may be discussions about the details above, but the first is simple (use |
Regarding the updates made in 0.74.0: https://gohugo.io/news/0.74.0-relnotes/
The current implementation doesn't appear to allow isExternalRefsAllowed to be configured anywhere and it is false by default. This causes any attempt to unmarshal an openapi spec using external references to fail: https://github.com/getkin/kin-openapi/blob/9b9280d707773bb764ec07ac7363248d8240343d/openapi3/swagger_loader.go#L67
This could be a really fantastic feature for some of us building documentation sites in Hugo based on the OpenAPI spec, but due to the above, it's at present only useful for smaller and non-complex openapi specifications.
Could this either be set to true by default when initializing the kin-openapi library, or could this be designed so that we can set it to true in config.toml or somewhere else that makes sense?
The text was updated successfully, but these errors were encountered: