Skip to content

feat: add components for individual schema properties [KHCP-11732]#38

Merged
vaibhavrajsingh2001 merged 5 commits intomainfrom
feat--property-field-components-KHCP-11732
May 7, 2024
Merged

feat: add components for individual schema properties [KHCP-11732]#38
vaibhavrajsingh2001 merged 5 commits intomainfrom
feat--property-field-components-KHCP-11732

Conversation

@vaibhavrajsingh2001
Copy link
Copy Markdown
Contributor

@vaibhavrajsingh2001 vaibhavrajsingh2001 commented May 6, 2024

Summary

Here is an example SchemaObject :

const sampleSchemaObject: SchemaObject = {
  title: 'sample-title',
  properties: {
    name: {
      type: 'string',
      description: 'sample-description',
      example: 'lorem ipsum',
      enum: ['sample-enum'],
      pattern: '^[0-9]{3}$',
      minimum: 100,
    },
  },
}

here, name is one of the properties of the sampleSchemaObject. The name property has fields like type, description, enum, example, etc.

This PR aims to add individual components for these fields of the property of a Schema Object.

Changes

  • Add components for fields of a property
  • ModelProperties component →
    • Rename the ModelProperties component to ModelProperty, since now it handles a single property instead of the entire properties object
    • Refactor it to iterate over the fields of a single property and dynamically render components for those fields
    • Add a map of field name to component type, and a method to compute props for that component
    • Merge rendering of properties of nested object and array items into a single detail-summary
    • Add a orderedFieldList util to fix the order in which fields are rendered
  • Move out various util methods out of components to utils/schema-model.ts
  • Add tests for components and utils

@@ -0,0 +1,74 @@
import type { SchemaObject } from '@/types'
import { isValidSchemaObject } from '@/utils'
import PropertyDescription from '@/components/document/property-fields/PropertyDescription.vue'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is do not like: utils importing components ....

Copy link
Copy Markdown
Contributor Author

@vaibhavrajsingh2001 vaibhavrajsingh2001 May 7, 2024

Choose a reason for hiding this comment

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

Fixed. Moved it to be a computed property inside ModelProperty

:key="propertyName"
:data-testid="`model-property-${propertyName}`"
:property="property"
:property-name="propertyName.toString()"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Background:
#33 (comment)

if the type of propertyName is a string, why do we need toString here?

@adamdehaven turns out it's because openapi3-ts has typed properties as a mapped type { [propertyName: string]: SchemaObject | ReferenceObject }, instead of a Record<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#48269

Copy link
Copy Markdown
Contributor Author

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-ts to fix this

metadevpro/openapi3-ts#135

@vaibhavrajsingh2001 vaibhavrajsingh2001 force-pushed the feat--property-field-components-KHCP-11732 branch from 46ccf15 to da34600 Compare May 7, 2024 16:26
@vaibhavrajsingh2001 vaibhavrajsingh2001 merged commit c11b469 into main May 7, 2024
@vaibhavrajsingh2001 vaibhavrajsingh2001 deleted the feat--property-field-components-KHCP-11732 branch May 7, 2024 16:29
kongponents-bot pushed a commit that referenced this pull request May 7, 2024
# [1.3.0](v1.2.1...v1.3.0) (2024-05-07)

### Features

* add components for individual schema properties [KHCP-11732] ([#38](#38)) ([c11b469](c11b469))
@kongponents-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.3.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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants