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

feat: add support for vendor extensions #245

Merged
merged 8 commits into from
Mar 11, 2024

Conversation

weyert
Copy link
Contributor

@weyert weyert commented Dec 12, 2023

Motivation and Context

Adds support for rendering vendor extensions as part of a schema row or the top level schema

Fixes #236

Description

Introduces support to custom renderer for vendor extensions, by adding a new property named renderExtensionAddon which will call when vendor properties (properties prefixed with x-) are find the schema definition.

How Has This Been Tested?

Tested in production for our internal documentation

Screenshot(s)/recordings(s)

Rendering of a vendor extension that shows the x-stoplight extension, in this example, it only returns a React element for any extensions with a nesting level higher than 0
CleanShot 2024-02-20 at 15 28 52@2x

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

Introduces support to custom renderer for vendor extensions, by adding
a new property named `renderExtensionAddon` which will call when
vendor properties (properties prefixed with `x-`) are find the schema
definition.
@weyert
Copy link
Contributor Author

weyert commented Jan 5, 2024

@billiegoose @daniel-white @brendarearden If someone could have a look at this would be great!

@weyert
Copy link
Contributor Author

weyert commented Jan 22, 2024

@P0lip Can you have a look?

Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Looks good overall! Thanks for the PR.
I'd appreciate it if you added a test - LMK if you have a question regarding that. Happy to help if needed

src/components/SchemaRow/SchemaRow.tsx Outdated Show resolved Hide resolved
* @returns VendorExtensionsResult
*/
export function extractVendorExtensions(fragment: SchemaFragment = {}): VendorExtensionsResult {
const extensionKeys = Object.keys(fragment).filter(key => key.toLowerCase().startsWith('x-'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should lower-case the key. If a key starts with an upper-cased X-, then IMHO it shouldn't be considered a spec ext.

src/components/SchemaRow/TopLevelSchemaRow.tsx Outdated Show resolved Hide resolved
src/__fixtures__/real-world/vendor-extensions.json Outdated Show resolved Hide resolved
@weyert
Copy link
Contributor Author

weyert commented Jan 23, 2024

Thanks, I will update the PR ASAP. I need to solve some work tasks first

* master:
  fix: improve handling of array + dictionary combo (stoplightio#251)
  feat: support dictionaries (stoplightio#249)

# Conflicts:
#	src/components/SchemaRow/TopLevelSchemaRow.tsx
@weyert
Copy link
Contributor Author

weyert commented Feb 20, 2024

@P0lip Sorry, I was on vacation for Chinese New Year. I have updated the PR now.

Please let me know, what you think of it :)

@weyert
Copy link
Contributor Author

weyert commented Mar 4, 2024

Anymore changes needed? I would love to be able to stop maintaining a fork of elements and json-schema-viewer
cc @P0lip @billiegoose @daniel-white @brendarearden @kaylachun

Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Thank you!

@P0lip
Copy link
Contributor

P0lip commented Mar 5, 2024

I'll merge it tomorrow.
Apologies for dropping a ball - I had time off last week too.

@weyert
Copy link
Contributor Author

weyert commented Mar 5, 2024

Awesome excited 👯‍♀️ :) Thank you! 🙏

@weyert
Copy link
Contributor Author

weyert commented Mar 7, 2024

@P0lip Would you be able to merge it? Love to raise a PR in Elements to bump with this support :)

@P0lip P0lip merged commit 129d05c into stoplightio:master Mar 11, 2024
@stoplight-bot
Copy link
Collaborator

🎉 This PR is included in version 4.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@weyert weyert deleted the vendor-extensions branch March 11, 2024 12:11
@weyert
Copy link
Contributor Author

weyert commented Mar 11, 2024

Awesome thank you 👯

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

Successfully merging this pull request may close these issues.

Add support for rendering vendor extensions
3 participants