Skip to content
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

Add example \ support for embedded files #72

Open
scriptdealer opened this issue Jun 18, 2024 · 1 comment
Open

Add example \ support for embedded files #72

scriptdealer opened this issue Jun 18, 2024 · 1 comment
Labels

Comments

@scriptdealer
Copy link

Hi, I'm trying to serve embedded yaml file, but this is not possible ?
Can't see any example or intuitively clear way to do so.

@fredbi
Copy link
Member

fredbi commented Mar 12, 2025

This is an interesting use case.

It looks like that is not possible to load directly this as a file at the moment, since the current loaders use os.ReadFile for local files.

There are in my view 2 ways to work this out:

  1. Define a custom loader (e.g. with NewDoucLoaderWithMatch()" that uses a somewhat modified version of swag.LoadFromFileOrHTTP (this is where os.ReadFile is used), then add it to the spec load with "WithDocLoader(myLoader)" as a LoadOption.
  2. Serve the embedded file locally then to use the loader as a http loader to that local server.

fredbi added a commit to fredbi/swag that referenced this issue Mar 18, 2025
This PR deprecates package-level configurations for the HTTP or file
loader utility, by introducing a set of options.

It is a non-breaking change, as package-level variables are still
consumed as the default options.

Besides existing configurations (timeout, basic auth, custom headers),
we add the possibility to inject a custom http client.

For the local file loader, we add the possibility to inject a FS,
for example to be used with a dir-rooted FS or an embedded FS.

* contributes go-openapi/loads#72
* refactored and augmented loading tests, with t.Run for improved
  test readability

Signed-off-by: Frederic BIDON <[email protected]>

Signed-off-by: Frederic BIDON <[email protected]>
fredbi added a commit to fredbi/swag that referenced this issue Mar 19, 2025
This PR deprecates package-level configurations for the HTTP or file
loader utility, by introducing a set of options.

It is a non-breaking change, as package-level variables are still
consumed as the default options.

Besides existing configurations (timeout, basic auth, custom headers),
we add the possibility to inject a custom http client.

For the local file loader, we add the possibility to inject a FS,
for example to be used with a dir-rooted FS or an embedded FS.

* contributes go-openapi/loads#72
* refactored and augmented loading tests, with t.Run for improved
  test readability

Signed-off-by: Frederic BIDON <[email protected]>

Signed-off-by: Frederic BIDON <[email protected]>
fredbi added a commit to go-openapi/swag that referenced this issue Mar 22, 2025
…104)

* feat(loading): HTTP or file loader configurable with LoadingOptions

This PR deprecates package-level configurations for the HTTP or file
loader utility, by introducing a set of options.

It is a non-breaking change, as package-level variables are still
consumed as the default options.

Besides existing configurations (timeout, basic auth, custom headers),
we add the possibility to inject a custom http client.

For the local file loader, we add the possibility to inject a FS,
for example to be used with a dir-rooted FS or an embedded FS.

* contributes go-openapi/loads#72
* refactored and augmented loading tests, with t.Run for improved
  test readability

Signed-off-by: Frederic BIDON <[email protected]>

Signed-off-by: Frederic BIDON <[email protected]>

* Update loading.go

Co-authored-by: ccoVeille <[email protected]>

---------

Signed-off-by: Frederic BIDON <[email protected]>
Co-authored-by: ccoVeille <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants