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

Refactor circular ref feature #35

Open
kostyazgara opened this issue Mar 25, 2021 · 1 comment
Open

Refactor circular ref feature #35

kostyazgara opened this issue Mar 25, 2021 · 1 comment

Comments

@kostyazgara
Copy link
Contributor

kostyazgara commented Mar 25, 2021

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Sometimes schemas require to refer to each other

const schema1 = S.object().prop('foo', schema2);
const schema2 = S.object().prop('bar', schema1);

In this case we created special helper that resolves cirluar dependencies

const schema1 = S.object().prop('foo', createRef(() => schema2));
const schema2 = S.object().prop('bar', createRef(() => schema1));

Now circular dependencies successfully resolving with direct ref to fluent-json-schema schemas, but here some pitfalls with the approach when we extracting schema and validate payload on the fly:

  1. Circular schemas are dynamic and extracting at the moment when need to validate data. In this way the ajv compiling schema at the moment when data is arrived and need to be validated
  2. Swagger doesn't output the schema of dynamic ref

Expected behavior

Need to refactor ref functionality without changing the API of createRef and other additional actions from client-side

  1. Compile ref schemas on startup, when we are loading all controller schemas
  2. Swagger should output the schema correctly in swagger document

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@kostyazgara
Copy link
Contributor Author

Maybe this one https://github.com/ajv-validator/ajv-keywords examples will be useful when developing forwardRef functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant