Repository navigation
feat: iterate through all the schemas and handle circular references - #391
Conversation
jonaslagoni
left a comment
There was a problem hiding this comment.
The tests are starting to get a bit ridiculous 😆
Only two small changes 👏 Looking good 👍
|
@magicmatatjahu I see @jonaslagoni did a good review so I will not really engage more than just saying it should be |
|
@jonaslagoni Thanks for review! Changes are propagated. @derberg Thanks! Title is changed. However I missed to update Readme's section about circular references - could you check https://github.com/asyncapi/parser-js/pull/391/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R212 ? |
| - `x-parser-original-schema-format` holds information about the original schema format of the payload. You can use different schema formats with the AsyncAPI documents and the parser converts them to AsyncAPI schema. This is why different schema format is set, and the original one is preserved in the extension. | ||
| - `x-parser-original-payload` holds the original payload of the message. You can use different formats for payloads with the AsyncAPI documents and the parser converts them to. For example, it converts payload described with Avro schema to AsyncAPI schema. The original payload is preserved in the extension. | ||
| - [`x-parser-circular`](#circular-references) | ||
| - [`x-parser-circular-props`](#circular-references) |
There was a problem hiding this comment.
why do you remove those? these extensions are still there, right?
There was a problem hiding this comment.
Yes and no. The old implementation had this to itself, that it marked extensions in places where they should not and gave false information what is circular and what is not - I described it in more detail in issue #293 (case with items in RecursiveAncestor schema).
This PR no longer uses these extensions to determine what is circular and what is not, however it has made fallbacks to return identical values if someone uses extensions - you can see the fallbacks here, so templates which use the function like circularProps(), hasCircularProps() in theory shouldn't be broken :)
The only exception may be when someone uses those extensions inline and not through functions, then there is a problem, but apart from html-template and markdown-template I don't know any other that use information what is circular and what is not.
Also x-parser-circular is still injected in AsyncAPI root document, so I will revert this extension :)
There was a problem hiding this comment.
can you explain how is it better to call this operation every time you want to get a list of circular props? instead of having this info always on extension level and just read an array?
I also see you remove from docs info about hasCircularProps and cCircularProps but these are still there
There was a problem hiding this comment.
ok :) The circularProps() function itself does not currently return any needed information - it was needed in the previous implementation, but no longer is, but I left this function in case some template uses it.
To check why it's not needed (and it didn't work as expected) here is an example:
schemas:
Circular1:
props:
circular2:
$ref: '#/schemas/Circular2'
Circular2:
props:
circular1:
$ref: '#/schemas/Circular1'so we have case when we have circular references:
- Circular1 -> Circular2 -> Circular1
- Circular2 -> Circular1 -> Circular2
Problem with old implementation for x-circular-props is that it injects that extension to Circular1 with values ['circular2'] and in Circular2 it injects with values ['circular1']. With the above statement of what is circular this information for developer is wrong - the information that property circular1/2 is circular should appear in at least 2 second sub-tree of JSON and not, as now, in 1 sub-tree.
So it is better to define dynamically what is circular and what is not - have in mind that after dereferencing you operate on this same object in places where you used reference to it.
There was a problem hiding this comment.
ok so you basically do not want to document hasCircularProps and circularProps as they are there for legacy, to not be forced to release 2.0 of the library, right?
shouldn't we mark them as @deprecated or something like that?
There was a problem hiding this comment.
do we need an issue to discuss it? isn't it how it should be just clearly stated in this PR, that all properties, including parser extensions, MUST be accessed by parser helpers and never directly unless helper doesn't exist?
Or that 😄
There was a problem hiding this comment.
https://github.com/search?q=x-parser-circular-props&type=code so we have usage of it only in our tooling, html-template (in tests), markdown-template (in tests) and in event gateway @smoya 😅 Rest are generated html-docs and pushed to repos.
There was a problem hiding this comment.
Implementation in event-gateway is because follows https://github.com/asyncapi/parser-api/blob/master/docs/v1.md#schema. But internally is not used. If you plan to remove it, would you mind updating https://github.com/asyncapi/parser-api/blob/master/docs/v1.md?
There was a problem hiding this comment.
@smoya I created PR asyncapi/parser-api#23
@derberg @jonaslagoni in latest commit I added note:
NOTE: All extensions added by the parser (including all properties) should be retrieved using special functions. Names of extensions and their location may change, and their eventual changes will not be announced.
Is it enough or you wanna add something more?
There was a problem hiding this comment.
@derberg Jonas accepted my changes. Do you have any other objections (including with NOTE)?
|
@magicmatatjahu only some code smells are there 😉 |
|
@derberg please look at what these smell codes are :) I'm not going to shorten this function, because splitting it will only make it more confusing - identical to the test file. |
|
@magicmatatjahu sure, make sense, but we should not merge with code smells as then we start ignoring them, as simple as that. Just ignore them with proper comments |
|
@derberg Done, thanks! |
|
Kudos, SonarCloud Quality Gate passed!
|
|
🎉 This PR is included in version 1.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |








Description
Iterate through all the schemas:
not,definitions,dependencies,definitions,patternProperties,propertyNames,contains,if,then,elsetraverseSchemafunctionparametersandmessageTraitsin/componentsRelated issue(s)
Resolves #293
Resolves #229