libopenapi icon indicating copy to clipboard operation
libopenapi copied to clipboard

Add support for different bundling modes

Open felixjung opened this issue 1 year ago • 6 comments

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 components section 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.

felixjung avatar Nov 11 '24 08:11 felixjung

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

califlower avatar Dec 11 '24 20:12 califlower

Had very little time to work on this lately, but still want to do it.

felixjung avatar Dec 12 '24 18:12 felixjung

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 ;-)

PR Ref

JemDay avatar Dec 19 '24 17:12 JemDay

I love when ideas converge!

ccoVeille avatar Dec 19 '24 19:12 ccoVeille

@JemDay thanks. Yeah, familiar with that.

felixjung avatar Dec 20 '24 08:12 felixjung

continuing on the work here in case @felixjung doesn't return to it https://github.com/pb33f/libopenapi/pull/401

stcalica avatar Apr 17 '25 23:04 stcalica

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.

daveshanley avatar May 24 '25 11:05 daveshanley

Oh that's great news! Thanks!

felixjung avatar May 26 '25 08:05 felixjung