mokkabonna / vue-vuelidate-jsonschema

Create vuelidate validation rules based on json schema
110 stars 5 forks source link

schema with refs #18

Open jhoogeboom opened 6 years ago

jhoogeboom commented 6 years ago

trying to process a schema with refs, based on your documentation I process the schema first to dereference the (internal) refs.

<script>
import jsonSchema from '@/components/Schema/europass-json-schema-v3.3.0.json'
import example from '@/components/Schema/europass-cv-example-v3.3.0.json'
import parser from 'json-schema-ref-parser';

export default {
  schema: [
    async function loadSchemaOnCreate() {
      // functions must return a promise or a schema synchronously
      return await parser.dereference(jsonSchema)
    }],
  name: 'app',
  data () {
    return {
      schema: example
    }
  }
 }
</script>

Something's not going well though

screen shot 2018-08-29 at 20 41 23

You can find the schema and example if you want to have a look: https://interop.europass.cedefop.europa.eu/data-model/json-resources/

jhoogeboom commented 6 years ago

if anyone runs into something similar, this seemed to work better for dereferencing: https://www.npmjs.com/package/json-schema-deref-local

and it seems the objects are not initiated by default, this works well to generate it: https://www.npmjs.com/package/json-schema-defaults

export default {
  schema: deref(jsonSchema),
  name: 'app',
  data () {
    return {
      schema: defaults(this.$options.schema)
      }
  }
}
</script>