express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

feat: support cyclical schema references

Open petermetz opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe.

Yes, I have a schema that has cyclical references and because of this two things are happening with the current version:

  1. The serialization used to generate the cache keys crashes (easy to solve if you pass in the right parameter to the underlying library to not choke on cycles)
  2. Bigger problem: json-schema-traverse only supports cyclical references in the schema if they are unresolved (e.g. left as $ref) => https://github.com/epoberezkin/json-schema-traverse/issues/43

Describe the solution you'd like

Support cyclical references either by

  1. using a different library for traversal that does not choke on cyclical JS object references
  2. (big) refactoring of this lib so that it doesn't resolve $refs prior to traversal
  3. (small) refactoring of this lib so that it detects cycles and breaks them somehow (multiple ideas but I'm not a 100% sure of either of them being robust because I'm not that familiar with the rest of the codebase of express-openapi-validator)

Describe alternatives you've considered

  1. Eliminate cycles from the API schema. No go unfortunately.

Additional context

https://github.com/hyperledger/cactus/blob/main/packages/cactus-plugin-ledger-connector-corda/src/main/json/openapi.json#L180

You can see that the JvmType and the JvmObject schema components are referencing each other, but one of the references is optional so an infinite loop is not a problem with regards the reference chain.

petermetz avatar Apr 13 '22 19:04 petermetz