Giter Site home page Giter Site logo

dbt-jsonschema's Introduction

dbt YAML validator using JSON Schema

JSON Schema is a way to define the expected shape of JSON (or YAML) documents. This enables live checking of your files, as well as Intellisense/autocomplete as you type.

60 second demo video:

What does it do?

This repository contains schemata for:

  • Project definition files (dbt_project.yml)
  • Package files (packages.yml)
  • Selectors files (selectors.yml)
  • Property files (models/whatever.yml)

Installation in VS Code

  1. Install the VSCode-YAML extension
  2. Inside of your dbt project's directory, create a .vscode/settings.json file containing the following data. This is what tells the extension which schema to associate with each file.
{    
    "yaml.schemas": {
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_yml_files.json": [
            "/**/*.yml",
            "!profiles.yml",
            "!dbt_project.yml",
            "!packages.yml",
            "!selectors.yml",
            "!profile_template.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_project.json": [
            "dbt_project.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/selectors.json": [
            "selectors.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/packages.json": [
            "packages.yml"
        ]
    },
}
  1. To prompt other users to install the YAML extension, create a .vscode/extensions.json file containing the following data inside of your dbt project's directory:
{
    "recommendations": [
        "redhat.vscode-yaml"
    ]
}

Installation in Vim

  1. Install the coc.nvim plugin
  2. Install coc-yaml: :CocInstall coc-yaml
  3. Add JSON Schema (there might be a better way to do this, but adding directly to coc-settings.json using :CocConfig works):
{    
    "yaml.schemas": {
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_yml_files.json": [
            "/**/*.yml",
            "!profiles.yml",
            "!dbt_project.yml",
            "!packages.yml",
            "!selectors.yml",
            "!profile_template.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_project.json": [
            "dbt_project.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/selectors.json": [
            "selectors.yml"
        ],
        "https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/packages.json": [
            "packages.yml"
        ]
    },
}

Installation in JetBrains

IDEs by JetBrains like PyCharm and IntelliJ enable us to use the JSON Schema, using the JSON schema mapping feature.

  1. Open the preferences of JSON schema mapping in JetBrains
  2. Add custom schema mappings

There is no way to add the preferences with a configuration file like VS Code. As we have to manually configure them one by one, we just describe values of the configurations below. If you want to know the details, the dbt YAML validator in JetBrains article describes how to configure the JSON schema mapping in details.

  • Project definition files
    • URL: https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_project.json
    • Schema version: JSON schema version 7
    • Mapping: dbt_project.yml
  • Package files
    • URL: https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/packages.json
    • Schema version: JSON schema version 7
    • Mapping: packages.yml
  • Selectors files
    • URL: https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/selectors.json
    • Schema version: JSON schema version 7
    • Mapping: selectors.yml
  • Property files
    • URL: https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_yml_files.json
    • Schema version: JSON schema version 7
    • Mapping: models/**/*.yml, analysis/**/*.yml, snapshots/**/*.yml

A screenshot of a JetBrains Preferences panel showing the correct mapping of the dbt_yml_files JSON Schema

Do you use a different IDE which also supports JSON Schema? Please open a PR with setup instructions and links to any extensions!

Contributing

PRs that improve these schemata are welcome!

Please ensure that JSON keys are sorted by vscode-sort-json according to the rules in .vscode/settings.

dbt-jsonschema's People

Contributors

dave-connors-3 avatar joellabes avatar b-per avatar clrcrl avatar kodaho avatar lyschoening avatar dbeatty10 avatar evgeniybobok avatar jgillies avatar brunocostalopes avatar mitchellacohen avatar yu-iskw avatar syou6162 avatar will-sargent-dbtlabs avatar vchetyrkine avatar mtilda avatar stuartmiddleton avatar stephen84s avatar patkearns10 avatar h-max avatar grahamwetzler avatar aaroncoquet-easypark avatar dwreeves avatar ben-wade-olo avatar kochalex avatar aksestok avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.