├── .browserslistrc ├── .coveralls.yml ├── .editorconfig ├── .env ├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── pull_request_template.md ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── docs ├── .vuepress │ ├── components │ │ ├── CustomWrapper.vue │ │ ├── Demo.vue │ │ └── SourceCode.vue │ ├── config.js │ ├── customComponentsConfig.js │ ├── customWrapperConfig.js │ ├── enhanceApp.js │ ├── public │ │ └── logo.png │ ├── schemas │ │ ├── arrayOfObjects.js │ │ ├── basic.js │ │ ├── conditions.js │ │ ├── conditionsAllOf.js │ │ ├── conditionsAllOfSeveral.js │ │ ├── conditionsOneOf.js │ │ ├── customComponents.js │ │ ├── defaults.js │ │ ├── home.js │ │ ├── index.js │ │ ├── nested.js │ │ ├── order.js │ │ ├── radio.js │ │ └── selectTitles.js │ ├── shims-vue.d.ts │ ├── styles.css │ └── ui-schemas.js ├── README.md ├── examples │ └── README.md └── guide │ └── README.md ├── jest.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── favicon.ico └── index.html ├── rollup.config.js ├── src ├── App.vue ├── JsonSchema │ ├── JsonSchema.vue │ ├── JsonSchemaArray.vue │ ├── JsonSchemaArrayFormWrap.vue │ ├── JsonSchemaForm.vue │ ├── __tests__ │ │ └── JsonSchema.spec.ts │ └── index.ts ├── __tests__ │ ├── App.spec.ts │ ├── entry.spec.ts │ └── main.spec.ts ├── components │ ├── Checkbox.vue │ ├── InputWrapper.vue │ ├── Radio.vue │ ├── Select.vue │ ├── TextInput.vue │ ├── __tests__ │ │ ├── Checkbox.spec.ts │ │ ├── InputWrapper.spec.ts │ │ ├── Radio.spec.ts │ │ ├── Select.spec.ts │ │ ├── TextInput.spec.ts │ │ └── restrict-directive.spec.ts │ └── restrict-directive.ts ├── entry.ts ├── main.ts ├── nanoclone.d.ts ├── shims-tsx.d.ts ├── shims-vue.d.ts ├── types.ts ├── utils │ ├── __testData__.ts │ ├── __tests__ │ │ ├── defaultComponents.spec.ts │ │ ├── errorMessages.spec.ts │ │ ├── generateDefaultValue.spec.ts │ │ ├── getComponent.spec.ts │ │ ├── getErrorText.spec.ts │ │ ├── mergeDeep.spec.ts │ │ ├── processConditions.spec.ts │ │ ├── processSchema.spec.ts │ │ ├── setValidators.spec.ts │ │ └── unrefSchema.spec.ts │ ├── defaultComponents.ts │ ├── errorMessages.ts │ ├── generateDefaultValue.ts │ ├── getComponent.ts │ ├── getErrorText.ts │ ├── mergeDeep.ts │ ├── processConditions.ts │ ├── processSchema.ts │ ├── setValidators.ts │ └── unrefSchema.ts └── vuelidate.d.ts ├── tests └── unit │ └── .eslintrc.js ├── tsconfig.json └── vue.config.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-pro 2 | repo_token: DOfEgBH8FE8dVHr6vfj6F1csFhQCjDafR -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,ts,tsx,vue}] 2 | indent_style = space 3 | indent_size = 2 4 | trim_trailing_whitespace = true 5 | insert_final_newline = true 6 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | BUILD=hz -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | 'extends': [ 7 | 'plugin:vue/essential', 8 | '@vue/standard', 9 | '@vue/typescript' 10 | ], 11 | rules: { 12 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 13 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 14 | 'vue/valid-v-on': ['error', { 15 | 'modifiers': ['eventname]'] 16 | }] 17 | }, 18 | parserOptions: { 19 | parser: '@typescript-eslint/parser' 20 | }, 21 | overrides: [ 22 | { 23 | files: [ 24 | '**/__tests__/*.{j,t}s?(x)' 25 | ], 26 | env: { 27 | jest: true 28 | } 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | #### What's this PR do? 2 | #### Where should the reviewer start? 3 | #### How should this be manually tested? 4 | #### Any background context you want to provide? 5 | #### What are the relevant tickets? 6 | #### Screenshots (if appropriate) 7 | #### Questions: -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | /docs/.vuepress/dist 5 | /coverage 6 | stats.html 7 | 8 | # local env files 9 | .env.local 10 | .env.*.local 11 | 12 | # Log files 13 | npm-debug.log* 14 | yarn-debug.log* 15 | yarn-error.log* 16 | 17 | # Editor directories and files 18 | .idea 19 | .vscode 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/* 4 | install: 5 | - npm ci 6 | script: 7 | - npm run lint 8 | - npm run test:unit 9 | - npm run build 10 | - npm run docs:build 11 | after_script: 12 | - cat ./coverage/lcov.info | coveralls 13 | deploy: 14 | provider: pages 15 | skip_cleanup: true 16 | local_dir: docs/.vuepress/dist 17 | github_token: $GITHUB_TOKEN # A token generated on GitHub allowing Travis to push code on you repository. Set in the Travis settings page of your repository, as a secure variable 18 | keep_history: true 19 | on: 20 | branch: master -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at . All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | TBA 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Roman Sabirov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/roma219/vue-jsonschema-form.svg?branch=master)](https://travis-ci.com/roma219/vue-jsonschema-form) [![Coverage Status](https://coveralls.io/repos/github/roma219/vue-jsonschema-form/badge.svg?branch=master&service=github&kill_cache=1)](https://coveralls.io/github/roma219/vue-jsonschema-form?branch=master&service=github&kill_cache=1) [![dependencies Status](https://david-dm.org/roma219/vue-jsonschema-form/status.svg)](https://david-dm.org/roma219/vue-jsonschema-form) [![Known Vulnerabilities](https://snyk.io/test/github/roma219/vue-jsonschema-form/badge.svg)](https://snyk.io/test/github/roma219/vue-jsonschema-form) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/roma219/vue-jsonschema-form.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/roma219/vue-jsonschema-form/context:javascript) ![last commit](https://badgen.net/github/last-commit/roma219/vue-jsonschema-form) 2 |   3 | 4 | ![minified size](https://badgen.net/bundlephobia/min/@roma219/vue-jsonschema-form) 5 | ![](https://badgen.net/bundlephobia/minzip/@roma219/vue-jsonschema-form) 6 | 7 | # vue-jsonschema-form 8 | JSON Schema based form generator built with Vue.js. Currently Work in Progress. 9 | 10 | ### Full Guide and Examples 11 | https://roma219.github.io/vue-jsonschema-form/guide/ 12 | 13 | [![Demo on Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/vue-jsonschema-form-basic-example-ulwwy?fontsize=14&hidenavigation=1&module=%2Fsrc%2FApp.vue&theme=dark) 14 | 15 | ### Installation 16 | ``` 17 | npm install @roma219/vue-jsonschema-form 18 | ``` 19 | 20 | ### Usage 21 | ``` 22 | 23 | 24 | schema = { 25 | type: 'object', 26 | properties: { 27 | aaa: { type: 'string', minLength: 1 }, 28 | bbb: { type: 'boolean' }, 29 | ccc: { type: 'string', enum: ['1', '2', '3'] }, 30 | ddd: { 31 | type: 'object', 32 | title: '', 33 | properties: { 34 | a1: { type: 'string', minLength: 1, maxLength: 5 }, 35 | b2: { type: 'boolean', default: true }, 36 | ddd: { 37 | type: 'object', 38 | properties: { 39 | a1: { type: 'string', default: 'aaa' }, 40 | b2: { type: 'boolean' } 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | ``` 48 | 49 | 50 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ [ '@vue/app', { useBuiltIns: 'entry' } ] ] 3 | } 4 | -------------------------------------------------------------------------------- /docs/.vuepress/components/CustomWrapper.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 19 | 20 | 34 | -------------------------------------------------------------------------------- /docs/.vuepress/components/Demo.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 134 | 135 | 184 | -------------------------------------------------------------------------------- /docs/.vuepress/components/SourceCode.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 24 | 25 | 53 | -------------------------------------------------------------------------------- /docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config() 2 | const webpack = require('webpack') 3 | 4 | module.exports = { 5 | title: 'Vue JSON Schema Form', 6 | description: 'Form Generator based on JSON Schema', 7 | base: '/vue-jsonschema-form/', 8 | head: [ 9 | ['link', { rel: 'icon', href: '/logo.png' }] 10 | ], 11 | themeConfig: { 12 | repo: 'roma219/vue-jsonschema-form', 13 | docsDir: 'docs', 14 | search: true, 15 | displayAllHeaders: true, 16 | nav: [ 17 | { text: 'Home', link: '/' }, 18 | { text: 'Guide', link: '/guide/' }, 19 | { text: 'Examples', link: '/examples/' } 20 | ], 21 | sidebar: [ 22 | { 23 | title: 'Guide', 24 | path: '/guide/', 25 | collapsable: false, 26 | sidebarDepth: 1 27 | }, 28 | { 29 | title: 'Examples', 30 | path: '/examples/' 31 | } 32 | ] 33 | }, 34 | plugins: [ 35 | [ 36 | 'vuepress-plugin-typescript', 37 | { 38 | tsLoaderOptions: { 39 | // All options of ts-loader 40 | }, 41 | } 42 | ] 43 | ], 44 | configureWebpack: (config) => { 45 | return { plugins: [ 46 | new webpack.EnvironmentPlugin({ ...process.env }) 47 | ]} 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /docs/.vuepress/customComponentsConfig.js: -------------------------------------------------------------------------------- 1 | [{ 2 | componentName: 'VSelect', 3 | contains: 'enum', 4 | props: (propName, schema, uiSchema) => ({ 5 | label: schema.title || propName, 6 | items: schema.enum, 7 | outlined: true 8 | }), 9 | eventName: 'change' 10 | }, { 11 | componentName: 'VSwitch', 12 | matcher: { type: 'boolean' }, 13 | eventName: 'change', 14 | props: (propName, schema, uiSchema) => ({ 15 | label: schema.title || propName 16 | }) 17 | },{ 18 | componentName: 'VTextField', 19 | matcher: { type: 'string' }, 20 | props: (propName, schema, uiSchema) => ({ 21 | label: schema.title || propName, 22 | outlined: true, 23 | clearable: true, 24 | hint: schema.description, 25 | 'persistent-hint': true 26 | }) 27 | }, { 28 | componentName: 'VDatePicker', 29 | uiSchemaMatcher: { uiType: 'datepicker' }, 30 | eventName: 'change', 31 | props: (propName, schema, uiSchema) => ({ 32 | 'full-width': true 33 | }) 34 | }] 35 | -------------------------------------------------------------------------------- /docs/.vuepress/customWrapperConfig.js: -------------------------------------------------------------------------------- 1 | { 2 | componentName: 'CustomWrapper', 3 | props: (propName, schema, uiSchema) => ({ 4 | title: schema.title || propName 5 | }) 6 | } 7 | -------------------------------------------------------------------------------- /docs/.vuepress/enhanceApp.js: -------------------------------------------------------------------------------- 1 | import JsonSchema from './../../src/JsonSchema/JsonSchema.vue' 2 | import JsonSchemaForm from './../../src/JsonSchema/JsonSchemaForm.vue' 3 | import JsonSchemaArray from './../../src/JsonSchema/JsonSchemaArray.vue' 4 | import TextInput from './../../src/components/TextInput.vue' 5 | import Checkbox from './../../src/components/Checkbox.vue' 6 | import Radio from './../../src/components/Radio.vue' 7 | import Select from './../../src/components/Select.vue' 8 | import InputWrapper from './../../src/components/InputWrapper.vue' 9 | import VueHighlightJS from 'vue-highlightjs' 10 | import javascript from 'highlight.js/lib/languages/javascript'; 11 | import json from 'highlight.js/lib/languages/json'; 12 | import Vuetify, { VTextField, VSwitch, VSelect, VApp, VDatePicker } from 'vuetify/lib' 13 | import '@mdi/font/css/materialdesignicons.css' 14 | import 'highlight.js/styles/ocean.css'; 15 | import './styles.css' 16 | 17 | export default ({ Vue, options, router, siteData }) => { 18 | Vue.use(Vuetify, { 19 | components: { VTextField, VSwitch, VSelect, VDatePicker, VApp } 20 | }) 21 | Vue.use(VueHighlightJS, { 22 | languages: { 23 | javascript, 24 | json 25 | } 26 | }) 27 | options.vuetify = new Vuetify({}) 28 | Vue.component('JsonSchema', JsonSchema) 29 | Vue.component('JsonSchemaArray', JsonSchemaArray) 30 | Vue.component('JsonSchemaForm', JsonSchemaForm) 31 | Vue.component('TextInput', TextInput) 32 | Vue.component('Checkbox', Checkbox) 33 | Vue.component('Radio', Radio) 34 | Vue.component('Select', Select) 35 | Vue.component('InputWrapper', InputWrapper) 36 | } 37 | -------------------------------------------------------------------------------- /docs/.vuepress/public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roma219/vue-jsonschema-form/dcc87157b7773fdc9d0ffe975dfc356d462f1463/docs/.vuepress/public/logo.png -------------------------------------------------------------------------------- /docs/.vuepress/schemas/arrayOfObjects.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | array: { 5 | type: 'array', 6 | title: 'Users', 7 | items: { 8 | type: 'object', 9 | properties: { name: { type: 'string', title: 'Username' } } 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/basic.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Username' }, 5 | b: { type: 'boolean', title: 'Use Avatar' }, 6 | mySelect: { 7 | type: 'string', 8 | title: 'Account Type', 9 | enum: ['User', 'Editor', 'Admin'] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/conditions.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 5 | b: { type: 'number', title: 'Amount of likes' } 6 | }, 7 | if: { 8 | properties: { 9 | a: { 10 | const: 'Vue' 11 | } 12 | } 13 | }, 14 | then: { 15 | properties: { 16 | b: { 17 | minimum: 1 18 | }, 19 | c: { type: 'boolean', title: 'Are you sure?' } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/conditionsAllOf.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 5 | b: { type: 'number', title: 'Amount of likes' }, 6 | c: { type: 'boolean', title: 'Are you sure?' } 7 | }, 8 | if: { 9 | allOf: [{ 10 | properties: { 11 | a: { 12 | const: 'Vue' 13 | } 14 | } 15 | }, { 16 | properties: { 17 | c: { 18 | const: true 19 | } 20 | } 21 | }] 22 | }, 23 | then: { 24 | properties: { 25 | x: { 26 | type: 'string', title: 'Field' 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/conditionsAllOfSeveral.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 5 | b: { type: 'number', title: 'Amount of likes' }, 6 | c: { type: 'boolean', title: 'Are you sure?' } 7 | }, 8 | allOf: [{ 9 | if: { 10 | properties: { 11 | a: { 12 | const: 'Vue' 13 | } 14 | } 15 | }, 16 | then: { 17 | properties: { 18 | x: { 19 | type: 'string', title: 'Field' 20 | } 21 | } 22 | } 23 | }, { 24 | if: { 25 | properties: { 26 | a: { 27 | const: 'React' 28 | } 29 | } 30 | }, 31 | then: { 32 | properties: { 33 | y: { 34 | type: 'boolean', title: 'Another' 35 | } 36 | } 37 | } 38 | }] 39 | } 40 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/conditionsOneOf.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 5 | b: { type: 'number', title: 'Amount of likes' } 6 | }, 7 | if: { 8 | oneOf: [{ 9 | properties: { 10 | a: { 11 | const: 'Vue' 12 | } 13 | } 14 | }, { 15 | properties: { 16 | a: { 17 | const: 'React' 18 | } 19 | } 20 | } 21 | ] 22 | }, 23 | then: { 24 | properties: { 25 | b: { 26 | minimum: 1 27 | }, 28 | c: { type: 'boolean', title: 'Are you sure?' } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/customComponents.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { title: 'Name', type: 'string', description: 'Very important field' }, 5 | confirm: { type: 'boolean' }, 6 | c: { title: 'Planet', type: 'string', enum: ['Earth', 'Mars', 'Jupiter'], default: 'Mars' }, 7 | date: { type: 'string' } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/defaults.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { title: 'User Provider', type: 'string', default: 'Fabric №1' }, 5 | b: { type: 'boolean', title: 'Yes?' } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/home.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Name', minLength: 1 }, 5 | b: { type: 'number', title: 'Age', maximum: 99 }, 6 | c: { type: 'boolean', title: 'Agree' } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/index.js: -------------------------------------------------------------------------------- 1 | import arrayOfObjects from './arrayOfObjects.js' 2 | import basic from './basic.js' 3 | import conditions from './conditions.js' 4 | import conditionsAllOf from './conditionsAllOf.js' 5 | import conditionsAllOfSeveral from './conditionsAllOfSeveral.js' 6 | import conditionsOneOf from './conditionsOneOf.js' 7 | import customComponents from './customComponents.js' 8 | import defaults from './defaults.js' 9 | import home from './home.js' 10 | import nested from './nested.js' 11 | import order from './order.js' 12 | import radio from './radio.js' 13 | import selectTitles from './selectTitles.js' 14 | 15 | export default { 16 | arrayOfObjects, 17 | basic, 18 | conditions, 19 | conditionsAllOf, 20 | conditionsAllOfSeveral, 21 | conditionsOneOf, 22 | customComponents, 23 | defaults, 24 | home, 25 | nested, 26 | order, 27 | radio, 28 | selectTitles 29 | } 30 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/nested.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Username' }, 5 | b: { 6 | type: 'object', 7 | title: '', 8 | properties: { 9 | c: { type: 'boolean', title: 'Is Admin' } 10 | } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/order.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { type: 'string', title: 'Name' }, 5 | b: { type: 'boolean', title: 'Superuser' }, 6 | c: { type: 'string', title: 'Surname' } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/radio.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'object', 3 | properties: { 4 | a: { 5 | type: 'string', 6 | title: 'User Type', 7 | enum: ['User', 'Editor', 'Admin'] 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /docs/.vuepress/schemas/selectTitles.js: -------------------------------------------------------------------------------- 1 | export default { 2 | home: { 3 | type: 'object', 4 | properties: { 5 | a: { type: 'string', title: 'Name', minLength: 1 }, 6 | b: { type: 'number', title: 'Age', maximum: 99 }, 7 | c: { type: 'boolean', title: 'Agree' } 8 | } 9 | }, 10 | basic: { 11 | type: 'object', 12 | properties: { 13 | a: { type: 'string', title: 'Username' }, 14 | b: { type: 'boolean', title: 'Use Avatar' }, 15 | mySelect: { 16 | type: 'string', 17 | title: 'Account Type', 18 | enum: ['User', 'Editor', 'Admin'], 19 | default: 'User' 20 | } 21 | } 22 | }, 23 | nested: { 24 | type: 'object', 25 | properties: { 26 | a: { type: 'string', title: 'Username' }, 27 | b: { 28 | type: 'object', 29 | title: '', 30 | properties: { 31 | c: { type: 'boolean', title: 'Is Admin' } 32 | } 33 | } 34 | } 35 | }, 36 | arrayOfObjects: { 37 | type: 'object', 38 | properties: { 39 | array: { 40 | type: 'array', 41 | title: 'Users', 42 | items: { 43 | type: 'object', 44 | properties: { name: { type: 'string', title: 'Username' } } 45 | } 46 | } 47 | } 48 | }, 49 | conditions: { 50 | type: 'object', 51 | properties: { 52 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 53 | b: { type: 'number', title: 'Amount of likes' } 54 | }, 55 | if: { 56 | properties: { 57 | a: { 58 | const: 'Vue' 59 | } 60 | } 61 | }, 62 | then: { 63 | properties: { 64 | b: { 65 | minimum: 1 66 | }, 67 | c: { type: 'boolean', title: 'Are you sure?' } 68 | } 69 | } 70 | }, 71 | conditionsOneOf: { 72 | type: 'object', 73 | properties: { 74 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 75 | b: { type: 'number', title: 'Amount of likes' } 76 | }, 77 | if: { 78 | oneOf: [{ 79 | properties: { 80 | a: { 81 | const: 'Vue' 82 | } 83 | } 84 | }, { 85 | properties: { 86 | a: { 87 | const: 'React' 88 | } 89 | } 90 | } 91 | ] 92 | }, 93 | then: { 94 | properties: { 95 | b: { 96 | minimum: 1 97 | }, 98 | c: { type: 'boolean', title: 'Are you sure?' } 99 | } 100 | } 101 | }, 102 | conditionsAllOf: { 103 | type: 'object', 104 | properties: { 105 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 106 | b: { type: 'number', title: 'Amount of likes' }, 107 | c: { type: 'boolean', title: 'Are you sure?' } 108 | }, 109 | if: { 110 | allOf: [{ 111 | properties: { 112 | a: { 113 | const: 'Vue' 114 | } 115 | } 116 | }, { 117 | properties: { 118 | c: { 119 | const: true 120 | } 121 | } 122 | }] 123 | }, 124 | then: { 125 | properties: { 126 | x: { 127 | type: 'string', title: 'Field' 128 | } 129 | } 130 | } 131 | }, 132 | conditionsAllOfSeveral: { 133 | type: 'object', 134 | properties: { 135 | a: { type: 'string', title: 'Your favourite front-end framework?' }, 136 | b: { type: 'number', title: 'Amount of likes' }, 137 | c: { type: 'boolean', title: 'Are you sure?' } 138 | }, 139 | allOf: [{ 140 | if: { 141 | properties: { 142 | a: { 143 | const: 'Vue' 144 | } 145 | } 146 | }, 147 | then: { 148 | properties: { 149 | x: { 150 | type: 'string', title: 'Field' 151 | } 152 | } 153 | } 154 | }, { 155 | if: { 156 | properties: { 157 | a: { 158 | const: 'React' 159 | } 160 | } 161 | }, 162 | then: { 163 | properties: { 164 | y: { 165 | type: 'boolean', title: 'Another' 166 | } 167 | } 168 | } 169 | }] 170 | }, 171 | defaults: { 172 | type: 'object', 173 | properties: { 174 | a: { title: 'User Provider', type: 'string', default: 'Fabric №1' }, 175 | b: { type: 'boolean', title: 'Yes?' } 176 | } 177 | }, 178 | radio: { 179 | type: 'object', 180 | properties: { 181 | a: { 182 | type: 'string', 183 | title: 'User Type', 184 | enum: ['User', 'Editor', 'Admin'] 185 | } 186 | } 187 | }, 188 | order: { 189 | type: 'object', 190 | properties: { 191 | a: { type: 'string', title: 'Name' }, 192 | b: { type: 'boolean', title: 'Superuser' }, 193 | c: { type: 'string', title: 'Surname' } 194 | } 195 | }, 196 | selectTitles: { 197 | type: 'object', 198 | properties: { 199 | a: { 200 | type: 'string', 201 | enum: ['option 1', 'option 2', 'option 3'] 202 | } 203 | } 204 | }, 205 | customComponents: { 206 | type: 'object', 207 | properties: { 208 | a: { title: 'Name', type: 'string', description: 'Very important field' }, 209 | confirm: { type: 'boolean' }, 210 | c: { title: 'Planet', type: 'string', enum: ['Earth', 'Mars', 'Jupiter'], default: 'Mars' }, 211 | date: { type: 'string' } 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /docs/.vuepress/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue' 3 | export default Vue 4 | } 5 | -------------------------------------------------------------------------------- /docs/.vuepress/styles.css: -------------------------------------------------------------------------------- 1 | .theme-default-content:not(.custom), 2 | .page-nav { 3 | max-width: 960px!important; 4 | } 5 | 6 | .hljs { 7 | color: hsl(219, 13%, 78%)!important; 8 | } 9 | 10 | .v-application--wrap { 11 | min-height: auto!important; 12 | } 13 | -------------------------------------------------------------------------------- /docs/.vuepress/ui-schemas.js: -------------------------------------------------------------------------------- 1 | export default { 2 | order: { 3 | properties: { 4 | c: { order: 3 }, 5 | b: { order: 2 }, 6 | a: { order: 1 } 7 | } 8 | }, 9 | radio: { 10 | properties: { 11 | a: { 12 | uiType: 'radio' 13 | } 14 | } 15 | }, 16 | selectTitles: { 17 | properties: { 18 | a: { 19 | titles: ['custom title', 'second', 'third one'] 20 | } 21 | } 22 | }, 23 | customComponents: { 24 | properties: { 25 | date: { 26 | uiType: 'datepicker' 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | heroImage: /logo.png 4 | actionText: Get Started → 5 | actionLink: /guide/ 6 | features: 7 | - title: Zero Configuration 8 | details: Just provide a JSON Schema, and the form will be generated via built-in components 9 | - title: Validation Support 10 | details: Powered by Vuelidate, has built-it validation mechanism and validation errors display 11 | - title: Customizable 12 | details: You can use your own UI components 13 | footer: Vue JSON Schema Form 2020 14 | --- 15 | 16 | ### Example 17 | 18 | ``` vue 19 | 20 | ``` 21 | 22 | 23 | 24 | Feel free to play with it on [Codesandbox](https://codesandbox.io/s/vue-jsonschema-form-basic-example-zid04?fontsize=14&hidenavigation=1&module=%2Fsrc%2FApp.vue&theme=dark) 25 | 26 | --- -------------------------------------------------------------------------------- /docs/examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | ## Basic Inputs 3 | Full list of built-it components can be found [here](/guide/#built-in-components). 4 | 5 | 6 | 7 | [![Edit on Codesandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/vue-jsonschema-form-basic-example-ulwwy?fontsize=14&hidenavigation=1&module=%2Fsrc%2FApp.vue&theme=dark) 8 | 9 | ## Nested Object 10 | Nesting objects is supported. If you want to omit nested object's property name displayed - set it's `title` property to empty string. 11 | 12 | 13 | ## Array of Objects 14 | To specify schema for each array element, provide `items` parameter inside array parameter schema. 15 | 16 | 17 | ## Validations 18 | Supported rules: `minLength` and `maxLength` for strings, `minimum` and `maximum` for numbers. 19 | 20 | 21 | ## Conditions 22 | If condition is met, schema is merged with schema inside `then`. Minimum length (`minLength`) and equality (`const`) conditions are supported. Also `oneOf` (condition is met if only one `if` is met) and `allOf` (condition is met if all `if`s are met) combinations can be used. This is usefull when you want to display different parts of schema based on some parameter's value or when you want to validate some parts of the schema conditionally. 23 | 24 | Try typing in `Vue`. 25 | 26 | 27 | `oneOf` usage example. Condition is met when `a` is `Vue` or `React`. 28 | 29 | 30 | `allOf` usage example. Condition is met when a is `Vue` and `c` is `true`. 31 | 32 | 33 | `allOf` can also be used on the top level to implement multiple conditions. Try setting `a` to `Vue` and to `React`. 34 | 35 | 36 | ## Default Values 37 | Sometimes, usually when initializing a new data instance, you would want to use some default values. Full data model object with default values is emitted after initialization through a `@init-default` event. 38 | ``` vue 39 | 40 | ``` 41 | 42 | 43 | ## UI Schema 44 | ### Using specific UI component 45 | 46 | ### Setting display order 47 | Setting `order` property in UI schema will set the order for displaying corresponding components. The bigger `order` - the higher the component will be displayed. 48 | 49 | 50 | ## Custom Components 51 | Example showcases usage with some [Vuetify](https://vuetifyjs.com/) components. Using `uiSchema` is a convinient way to use specific components for some use-cases (e.g. Datepicker). 52 | 53 | 54 | 55 | <<< @/docs/.vuepress/customComponentsConfig.js 56 | 57 | 58 | ## Custom Wrapper Component 59 | In this case we use `CustomWrapper.vue` as componet to align labels and inputs horizontally. 60 | 61 | 62 | 63 | <<< @/docs/.vuepress/components/CustomWrapper.vue 64 | 65 | 66 | 67 | <<< @/docs/.vuepress/customWrapperConfig.js 68 | -------------------------------------------------------------------------------- /docs/guide/README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | Vue JSON Schema Form library uses JSON presented in a [JSON Schema Standard](https://json-schema.org/) to generate an input form and update provided data model. 3 | 4 | ## Installation 5 | ``` 6 | npm install --save @roma219/vue-jsonschema-form 7 | ``` 8 | 9 | ## Usage 10 | ``` vue 11 | 12 | ``` 13 | 14 | ## JSON Schema 15 | Schema should follow [JSON Schema Standard](https://json-schema.org/). Root shema type should be `object`. 16 | 17 | ## Props 18 | | Prop Name | Value Type | Description | 19 | | ------------- |:-------------:| -----:| 20 | | schema | object | JSON Schema | 21 | | ui-schema | object | [UI Schema](/guide/#custom-components) | 22 | | value | object | Data model object | 23 | | components | array | [Custom Components](/guide/#custom-components) | 24 | | wrapper | object | [Custom Wrapper Component](/guide/#custom-wrapper-component) | 25 | 26 | ## Events 27 | | Event Name | Emitted Value Type | Description | 28 | | ------------- |:-------------:| -----:| 29 | | input | object | Emitted on every data change. The argument is updated data model object (`:value` prop). | 30 | | init-default | object | Initial data model object generated with `default` values provided in schema. Usefull when you have an empty data model at the start. See [example](/examples/#default-values). | 31 | | validated | boolean | Emitted on every validation status change. `true` - data model is valid, `false` - data model is not valid. Usefull when you need to have some indicator of form validity, for example to disable `Save` button.| 32 | 33 | ## Built-in Components 34 | This is the list of built-in components and corresponding JSON Schema blocks. If you want to use different (your own or some UI kit) components, see [Custom Components](/guide/#custom-components). 35 | 36 | ### String Input 37 | ```js 38 | { 39 | type: 'string' 40 | } 41 | ``` 42 |
43 | 44 |
45 | 46 | ### Number Input 47 | ```js 48 | { 49 | type: 'number' 50 | } 51 | ``` 52 |
53 | 54 |
55 | 56 | ### Boolean Input 57 | ```js 58 | { 59 | type: 'boolean' 60 | } 61 | ``` 62 |
63 | 64 |
65 | 66 | 67 | ### Select 68 | ```js 69 | { 70 | enum: ['option 1', 'option 2', 'option 3'] 71 | } 72 | ``` 73 |
74 |