Skip to content

Conversation

@mallachari
Copy link

Fixes stoplightio/elements#1026

Adds hideExamples property to JSV that prevents rendering example validations.

@mallachari mallachari requested review from a team and paulatulis April 14, 2021 12:08
@mallachari mallachari self-assigned this Apr 14, 2021
@mallachari
Copy link
Author

@P0lip adding that property was an issue requirement, is it acceptable from your side? We were considering just modifying schema object but that would require lot of additional processing.

@P0lip
Copy link
Contributor

P0lip commented Apr 14, 2021

Yeah, seems okay.

We were considering just modifying schema object but that would require lot of additional processing.

Hmm, it should be quite easy actually.
I haven't the snippet below, but it should work.

  jsonSchemaTree.walker.on('exitNode', node => {
      if (!isRegularNode(node)) return;
      for (const field of ['examples', 'example', 'x-example']) {
         if (Array.isArray(node.annotations[field])) {
           node.validations[field] = node.annotations[field];
           delete node.annotations[field];
        }
    });

annotations and validations might be readonly though, so um, TS will scream :D

Anyhoo, what you have here is totally fine.

Copy link
Contributor

@paulatulis paulatulis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I pulled this down and played around with it, it worked for me, so I am going to approve, but @P0lip it might make everyone feel more secure if you also give your stamp of approval ;)

I guess my only more general question is related to the issue and understanding why this particular thing would necessitate an extra prop when other items are deemed appropriate to alter the schema. Maybe this doesn't come up very often and it looks like it was already sussed out in the issue anyway. Just curious if this is a common occurrence.

@mallachari
Copy link
Author

I guess my only more general question is related to the issue and understanding why this particular thing would necessitate an extra prop when other items are deemed appropriate to alter the schema. Maybe this doesn't come up very often and it looks like it was already sussed out in the issue anyway. Just curious if this is a common occurrence.

The reason is that we need to have possibility to not display example validations from Elements to not duplicate it as it already includes examples in different component. We could do it by feeding jsv with modified schema but that would need to be done from elements and require some additional computation on each schema change that might decrease performance. That is the only optional validation that might exist so we definitely won't be adding any more weird props.

@paulatulis
Copy link
Contributor

The reason is that we need to have possibility to not display example validations from Elements to not duplicate it as it already includes examples in different component. We could do it by feeding jsv with modified schema but that would need to be done from elements and require some additional computation on each schema change that might decrease performance. That is the only optional validation that might exist so we definitely won't be adding any more weird props.

That makes sense! Thanks @mallachari :)

@mallachari mallachari merged commit a22e20f into beta Apr 14, 2021
@mallachari mallachari deleted the feat/hide-examples-option branch April 14, 2021 21:59
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 4.0.0-beta.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove examples from JSV

5 participants