Add support for different bundling modes
The current bundling approach in libopenapi automatically inlines all refs in files other than the root file. The BundleInlineRefs option in datamodel.DocumentConfiguration appears to only affect the root file. When set to true, refs in the root file are inlined. When set to false, refs within the root file, i.e. to the components section, are kept where they are, while refs made to other files are inlined nevertheless.
The goal of this PR is to introduce different bundling modes.
- The first mode inlines all references.
- The second mode tracks all references across all files and ensures that they are moved to the appropriate sub-section of the
componentssection or other sections (as necessary) in the bundled spec.
The bundle mode can be configured in a new BundlerOptions struct passed to the bundling functions of the bundler package.
If this gets done this would be amazing. I think this is what redocly-cli does. Basically preserves the refs as local refs but moves them to their correct location in a single file. Bonus is that it'll work correctly for recursive items.
Even better if there's support for unique naming of refs as well
Had very little time to work on this lately, but still want to do it.
FYI ... I have a PR open in the libvalidator project where I was 'nudged' to follow the "Options pattern" model which enables a more fluent style to configuration options. My initial submission followed a very similar "options model" to the one you've got here ;-)
I love when ideas converge!
@JemDay thanks. Yeah, familiar with that.
continuing on the work here in case @felixjung doesn't return to it https://github.com/pb33f/libopenapi/pull/401
Hi folks, I decided to pick this up and build this feature.
It's a work in progress, but will be ready very soon, it's 85% done.
You can see the code here: https://github.com/pb33f/libopenapi/blob/v0.21.13/bundler/bundler_composer.go ( will be deleted when merged)
using the following sample: https://github.com/pb33f/libopenapi/blob/v0.21.13/bundler/test/specs/main.yaml
And the resulting output https://github.com/pb33f/libopenapi/blob/v0.21.13/bundler/test/specs/bundled.yaml
I did not use any existing PRs (including this one) because I had a design in my head already.
Oh that's great news! Thanks!