-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add components for individual schema properties [KHCP-11732] #38
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
Merged
vaibhavrajsingh2001
merged 5 commits into
main
from
feat--property-field-components-KHCP-11732
May 7, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9714a0f
feat: add components for individual schema properties [KHCP-11732]
vaibhavrajsingh2001 12a4985
chore: add spacing in scss selectors
vaibhavrajsingh2001 6041c1c
refactor(property-field): move component and props utils to utils folder
vaibhavrajsingh2001 966cdc8
chore(model-property): remove extra check
vaibhavrajsingh2001 da34600
refactor(model-property): add component type and props as computed pr…
vaibhavrajsingh2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,60 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { shallowMount } from '@vue/test-utils' | ||
| import ModelNode from './ModelNode.vue' | ||
| import type { SchemaObject } from '@/types' | ||
|
|
||
| const data: SchemaObject = { | ||
| description: "I'm a model's description.", | ||
| type: 'object', | ||
| title: 'Todo', | ||
| example: { | ||
| id: 1, | ||
| name: 'Buy milk', | ||
| completed: true, | ||
| completed_at: '2021-01-01T00:00:00.000Z', | ||
| }, | ||
| properties: { | ||
| id: { | ||
| type: 'number', | ||
| minimum: 0, | ||
| maximum: 9999, | ||
| description: 'ID of the task', | ||
| readOnly: true, | ||
| }, | ||
| name: { | ||
| type: 'string', | ||
| minLength: 1, | ||
| maxLength: 100, | ||
| description: 'Name of the task', | ||
| }, | ||
| completed: { | ||
| type: 'boolean', | ||
| default: false, | ||
| description: 'Boolean indicating if the task has been completed or not', | ||
| }, | ||
| completed_at: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| description: 'Time when the task was completed', | ||
| readOnly: true, | ||
| }, | ||
| }, | ||
| required: ['id', 'name'], | ||
| } | ||
|
|
||
| const title = 'Todo' | ||
|
|
||
| describe('<ModelNode />', () => { | ||
| it('renders all properties of a model', () => { | ||
| const wrapper = shallowMount(ModelNode, { | ||
| props: { | ||
| data, | ||
| title, | ||
| }, | ||
| }) | ||
|
|
||
| for (const property in data.properties) { | ||
| expect(wrapper.findTestId(`model-property-${property}`).exists()).toBe(true) | ||
| } | ||
| }) | ||
| }) |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,117 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { mount } from '@vue/test-utils' | ||
| import ModelProperty from './ModelProperty.vue' | ||
|
|
||
| describe('<ModelProperty />', () => { | ||
| it('renders all fields of a property', () => { | ||
| const wrapper = mount(ModelProperty, { | ||
| props: { | ||
| property: { | ||
| type: 'integer', | ||
| format: 'int32', | ||
| description: 'sample description', | ||
| example: 'lorem ipsum', | ||
| enum: [100, 200, 300], | ||
| pattern: '^[0-9]{3}$', | ||
| maximum: 999, | ||
| minimum: 100, | ||
| items: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| propertyName: 'sample-property', | ||
| requiredFields: ['sample-property', 'property-a', 'property-b'], | ||
| }, | ||
| }) | ||
|
|
||
| const componentList = [ | ||
| 'property-field-description', | ||
| 'property-field-example', | ||
| 'property-field-enum', | ||
| 'property-field-info', | ||
| 'property-field-pattern', | ||
| 'property-field-range', | ||
| ] | ||
|
|
||
| for (const component of componentList) { | ||
| expect(wrapper.findTestId(component).exists()).toBe(true) | ||
| } | ||
| }) | ||
|
|
||
| it('renders all fields of a nested property', () => { | ||
| const wrapper = mount(ModelProperty, { | ||
| props: { | ||
| property: { | ||
| type: 'object', | ||
| description: 'Period of time data is returned for.', | ||
| properties: { | ||
| start: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| description: | ||
| "Timestamp specifying the lower bound of the query's time range.", | ||
| }, | ||
| end: { | ||
| type: 'string', | ||
| format: 'date-time', | ||
| description: | ||
| "Timestamp specifying the upper bound of the query's time range.", | ||
| }, | ||
| }, | ||
| }, | ||
| propertyName: 'time-range', | ||
| requiredFields: ['time_range', 'query_id', 'size', 'offset'], | ||
| }, | ||
| }) | ||
|
|
||
| const componentList = [ | ||
| // top level property | ||
| 'model-property-time-range', | ||
| // nested properties | ||
| 'model-property-start', | ||
| 'model-property-end', | ||
| ] | ||
|
|
||
| for (const component of componentList) { | ||
| expect(wrapper.findTestId(component).exists()).toBe(true) | ||
| } | ||
| }) | ||
|
|
||
| it('renders all fields of items of an array property', () => { | ||
| const wrapper = mount(ModelProperty, { | ||
| props: { | ||
| property: { | ||
| type: 'array', | ||
| description: 'A sample array description', | ||
| items: { | ||
| properties: { | ||
| 'sample-item-1': { | ||
| type: 'integer', | ||
| format: 'int32', | ||
| example: '34', | ||
| }, | ||
| 'sample-item-2': { | ||
| type: 'string', | ||
| example: 'abc', | ||
| }, | ||
| }, | ||
| required: ['sample-item-1'], | ||
| }, | ||
| }, | ||
| propertyName: 'sample-property', | ||
| }, | ||
| }) | ||
|
|
||
| const componentList = [ | ||
| // top level property | ||
| 'model-property-sample-property', | ||
| // nested item properties | ||
| 'model-property-sample-item-1', | ||
| 'model-property-sample-item-2', | ||
| ] | ||
|
|
||
| for (const component of componentList) { | ||
| expect(wrapper.findTestId(component).exists()).toBe(true) | ||
| } | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Background:
#33 (comment)
@adamdehaven turns out it's because
openapi3-tshas typedpropertiesas a mapped type{ [propertyName: string]: SchemaObject | ReferenceObject }, instead of aRecord<string, SchemaObject | ReferenceObject>It's a known TS quirk that keys in a mapped type will always be interpreted as
string | number. Ref: microsoft/TypeScript#48269There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have opened a PR in
openapi3-tsto fix thismetadevpro/openapi3-ts#135