-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: nodeHasChanged option + diff annotations (#204)
- Loading branch information
Showing
14 changed files
with
532 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"title": "User", | ||
"type": "object", | ||
"x-stoplight": { "id": "root-id" }, | ||
"properties": { | ||
"billing_address": { | ||
"type": "string", | ||
"title": "Billing Address", | ||
"x-stoplight": { "id": "billing_address-id" }, | ||
"$ref": "#/$defs/Address" | ||
} | ||
}, | ||
"$defs": { | ||
"Address": { | ||
"type": "object", | ||
"title": "Address", | ||
"x-stoplight": { "id": "address-id" }, | ||
"properties": { | ||
"street": { | ||
"type": "string", | ||
"x-stoplight": { "id": "address-street-id" } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"title": "User", | ||
"type": "object", | ||
"x-stoplight": { "id": "root-id" }, | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"const": "Constant name", | ||
"examples": ["Example name", "Different name"], | ||
"x-stoplight": { "id": "name-id" } | ||
}, | ||
"age": { | ||
"type": "number", | ||
"minimum": 10, | ||
"maximum": 40, | ||
"x-stoplight": { "id": "age-id" } | ||
}, | ||
"completed_at": { | ||
"type": "string", | ||
"format": "date-time", | ||
"x-stoplight": { "id": "completed_at-id" } | ||
}, | ||
"list": { | ||
"type": ["null", "array"], | ||
"items": { | ||
"type": ["string", "number"], | ||
"x-stoplight": { "id": "list-items-id" } | ||
}, | ||
"minItems": 1, | ||
"maxItems": 4, | ||
"x-stoplight": { "id": "list-id" } | ||
}, | ||
"email": { | ||
"type": "string", | ||
"format": "email", | ||
"examples": ["[email protected]", "[email protected]"], | ||
"deprecated": true, | ||
"default": "[email protected]", | ||
"minLength": 2, | ||
"x-stoplight": { "id": "email-id" } | ||
}, | ||
"list-of-objects": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"x-stoplight": { "id": "list-of-objects-items-id" }, | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"x-stoplight": { "id": "list-of-objects-items-id-id" } | ||
}, | ||
"friend": { | ||
"type": "object", | ||
"x-stoplight": { "id": "list-of-objects-items-friend-id" }, | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"x-stoplight": { "id": "list-of-objects-items-friend-id-id" } | ||
}, | ||
"name": { | ||
"type": "object", | ||
"x-stoplight": { "id": "list-of-objects-items-friend-name-id" }, | ||
"properties": { | ||
"first": { | ||
"type": "string", | ||
"x-stoplight": { "id": "list-of-objects-items-friend-name-first-id" } | ||
}, | ||
"last": { | ||
"type": "string", | ||
"x-stoplight": { "id": "list-of-objects-items-friend-name-last-id" } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"minItems": 1, | ||
"maxItems": 4, | ||
"x-stoplight": { "id": "list-of-objects-id" } | ||
}, | ||
"friend": { | ||
"type": "object", | ||
"x-stoplight": { "id": "friend-id" }, | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"x-stoplight": { "id": "friend-id-id" } | ||
}, | ||
"name": { | ||
"type": "string", | ||
"x-stoplight": { "id": "friend-name-id" } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { NodeHasChangedFn } from '@stoplight/types'; | ||
import { Story } from '@storybook/react'; | ||
import { JSONSchema4 } from 'json-schema'; | ||
import React from 'react'; | ||
|
||
import { JsonSchemaProps, JsonSchemaViewer } from '../components/JsonSchemaViewer'; | ||
|
||
const defaultSchema = require('../__fixtures__/default-schema.json'); | ||
const simpleExample = require('../__fixtures__/diff/simple-example.json'); | ||
const rootRefExample = require('../__fixtures__/diff/root-ref.json'); | ||
|
||
export default { | ||
component: JsonSchemaViewer, | ||
argTypes: {}, | ||
}; | ||
|
||
const changed: Record<string, ReturnType<NodeHasChangedFn>> = { | ||
'age-id': { type: 'removed' }, | ||
'list-id': { type: 'modified', selfAffected: true }, | ||
'list-of-objects-id': { type: 'modified', isBreaking: true }, | ||
'list-of-objects-items-friend-id': { type: 'modified', isBreaking: true }, | ||
'list-of-objects-items-friend-name-id': { type: 'modified', selfAffected: true, isBreaking: true }, | ||
'list-of-objects-items-friend-name-last-id': { type: 'added', isBreaking: true }, | ||
'friend-id': { type: 'added', isBreaking: true }, | ||
'address-street-id': { type: 'added' }, | ||
}; | ||
const nodeHasChanged: NodeHasChangedFn = ({ nodeId }) => { | ||
const change = changed[nodeId!]; | ||
return change || false; | ||
}; | ||
|
||
const Template: Story<JsonSchemaProps> = ({ schema = defaultSchema as JSONSchema4, ...args }) => ( | ||
<JsonSchemaViewer schema={schema} {...args} nodeHasChanged={nodeHasChanged} /> | ||
); | ||
|
||
export const SimpleAllOf = Template.bind({}); | ||
SimpleAllOf.args = { schema: simpleExample as JSONSchema4 }; | ||
|
||
export const RootRef = Template.bind({}); | ||
RootRef.args = { schema: rootRefExample as JSONSchema4 }; |
Oops, something went wrong.