swagger-combine icon indicating copy to clipboard operation
swagger-combine copied to clipboard

Support for bundling without dereferencing

Open kibertoad opened this issue 7 years ago • 4 comments

JSON Schema $Ref Parser supports bundling schemas as opposed to dereferencing them: https://github.com/BigstickCarpet/json-schema-ref-parser/blob/master/docs/ref-parser.md#bundleschema-options-callback

It would be useful if swagger-combine supported this mode of operation as well.

kibertoad avatar Jan 08 '18 01:01 kibertoad

I've spent some time looking at this in the last 24 hours and think I have the beginning of a solution. Would essentially pass in an option that allows you to keep the references of first level objects. It would then do error checks in combinedSchema to detect duplicates for items such as:

  1. Paths
  2. Definitions
  3. Parameters
  4. Responses

Any other first level objects that we need to do error checking against?

There would also be the ability to add an options to sort these first level objects alphabetically: Paths

  • path a
  • path b Definitions
  • def a
  • def b

I added this second item in after combining several swagger defs together and ending up with a combined definition that was over 100,000 lines. Needed a quick and easy way to visually spot check.

jawa-the-hutt avatar Mar 22 '18 20:03 jawa-the-hutt

Especially useful for recursive schemas, they completely fail with a "Maximum call stack size exceeded" error

m-mohr avatar Dec 02 '20 22:12 m-mohr

Was this ever implemented? I see some vague references to the resolve config, but I can't see how to use these to prevent de-refefencing.

warmans avatar Apr 17 '21 12:04 warmans

Dereferencing also seems to fail for multi-level references as well.

For example, you have a data type (in components/schemas) referenced in your response type (in components/responses), that's in turn referenced in your path/method definition (in paths). The data type definition is not exported, yet all of its $ref across the exported schema remain. This totally breaks the generated schema.

Having an option to bundle some definitions without dereferencing would help to deal with these cases, as well as with circular referencing (which I have come across quite often). It'd also help to decrease the schema's size, for big and/or highly reusable base types.

flisboac avatar May 19 '21 04:05 flisboac