Skip to content

Commit

Permalink
add a "docs" field to models, parsed from schema.yml. it contains a b…
Browse files Browse the repository at this point in the history
…oolean "show" which defaults to True.
  • Loading branch information
Jacob Beck committed Feb 7, 2020
1 parent 9df123a commit ae3ef19
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
5 changes: 4 additions & 1 deletion core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from dbt.clients.system import write_file
import dbt.flags
from dbt.contracts.graph.unparsed import (
UnparsedNode, UnparsedMacro, UnparsedDocumentationFile, Quoting,
UnparsedNode, UnparsedMacro, UnparsedDocumentationFile, Quoting, Docs,
UnparsedBaseNode, FreshnessThreshold, ExternalTable,
AdditionalPropertiesAllowed, HasYamlMetadata
)
Expand Down Expand Up @@ -188,6 +188,7 @@ def patch(self, patch: 'ParsedNodePatch'):
self.columns = patch.columns
self.docrefs = patch.docrefs
self.meta = patch.meta
self.docs = patch.docs
if dbt.flags.STRICT_MODE:
assert isinstance(self, JsonSchemaMixin)
self.to_dict(validate=True)
Expand Down Expand Up @@ -225,6 +226,7 @@ class ParsedNodeDefaults(ParsedNodeMandatory):
description: str = field(default='')
columns: Dict[str, ColumnInfo] = field(default_factory=dict)
meta: Dict[str, Any] = field(default_factory=dict)
docs: Docs = field(default_factory=Docs)
patch_path: Optional[str] = None
build_path: Optional[str] = None

Expand Down Expand Up @@ -469,6 +471,7 @@ class ParsedPatch(HasYamlMetadata, Replaceable):
description: str
docrefs: List[Docref]
meta: Dict[str, Any]
docs: Docs


# The parsed node update is only the 'patch', not the test. The test became a
Expand Down
6 changes: 6 additions & 0 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ class UnparsedRunHook(UnparsedNode):
index: Optional[int] = None


@dataclass
class Docs(JsonSchemaMixin, Replaceable):
show: bool = True


@dataclass
class HasDocs(JsonSchemaMixin, Replaceable):
name: str
description: str = ''
meta: Dict[str, Any] = field(default_factory=dict)
data_type: Optional[str] = None
docs: Docs = field(default_factory=Docs)


TestDef = Union[Dict[str, Any], str]
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ def parse_patch(
columns=refs.column_info,
docrefs=refs.docrefs,
meta=block.target.meta,
docs=block.target.docs,
)
self.results.add_patch(self.yaml.file, result)

Expand Down Expand Up @@ -668,5 +669,6 @@ def parse_patch(
description=description,
docrefs=refs.docrefs,
meta=block.target.meta,
docs=block.target.docs,
)
self.results.add_macro_patch(self.yaml.file, result)
2 changes: 2 additions & 0 deletions test/integration/029_docs_generate_tests/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 2
models:
- name: model
description: "The test model"
docs:
show: false
columns:
- name: id
description: The user ID number
Expand Down
19 changes: 19 additions & 0 deletions test/integration/029_docs_generate_tests/test_docs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ def expected_seeded_manifest(self, model_database=None):
},
'patch_path': model_schema_yml_path,
'docrefs': [],
'docs': {'show': False},
'compiled': True,
'compiled_sql': ANY,
'extra_ctes_injected': True,
Expand Down Expand Up @@ -1033,6 +1034,7 @@ def expected_seeded_manifest(self, model_database=None):
},
},
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': '',
'extra_ctes_injected': True,
Expand Down Expand Up @@ -1076,6 +1078,7 @@ def expected_seeded_manifest(self, model_database=None):
'meta': {},
'unique_id': 'test.test.not_null_model_id',
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': AnyStringWith('count(*)'),
'extra_ctes_injected': True,
Expand Down Expand Up @@ -1124,6 +1127,7 @@ def expected_seeded_manifest(self, model_database=None):
'meta': {},
'unique_id': 'test.test.test_nothing_model_',
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': AnyStringWith('select 0'),
'extra_ctes_injected': True,
Expand Down Expand Up @@ -1172,6 +1176,7 @@ def expected_seeded_manifest(self, model_database=None):
'meta': {},
'unique_id': 'test.test.unique_model_id',
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': AnyStringWith('count(*)'),
'extra_ctes_injected': True,
Expand Down Expand Up @@ -1331,6 +1336,7 @@ def expected_postgres_references_manifest(self, model_database=None):
},
'description': '',
'docrefs': [],
'docs': {'show': True},
'fqn': ['test', 'ephemeral_copy'],
'name': 'ephemeral_copy',
'original_file_path': self.dir('ref_models/ephemeral_copy.sql'),
Expand Down Expand Up @@ -1409,6 +1415,7 @@ def expected_postgres_references_manifest(self, model_database=None):
'documentation_package': ''
}
],
'docs': {'show': True},
'fqn': ['test', 'ephemeral_summary'],
'name': 'ephemeral_summary',
'original_file_path': self.dir('ref_models/ephemeral_summary.sql'),
Expand Down Expand Up @@ -1489,6 +1496,7 @@ def expected_postgres_references_manifest(self, model_database=None):
'documentation_package': ''
}
],
'docs': {'show': True},
'fqn': ['test', 'view_summary'],
'name': 'view_summary',
'original_file_path': self.dir('ref_models/view_summary.sql'),
Expand Down Expand Up @@ -1571,6 +1579,7 @@ def expected_postgres_references_manifest(self, model_database=None):
'depends_on': {'macros': [], 'nodes': []},
'description': 'The test seed',
'docrefs': [],
'docs': {'show': True},
'fqn': ['test', 'seed'],
'name': 'seed',
'original_file_path': self.dir('seed/seed.csv'),
Expand Down Expand Up @@ -2472,6 +2481,7 @@ def expected_redshift_incremental_view_manifest(self):
},
'patch_path': self.dir('rs_models/schema.yml'),
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': ANY,
'extra_ctes_injected': True,
Expand Down Expand Up @@ -2554,6 +2564,7 @@ def expected_redshift_incremental_view_manifest(self):
},
'description': 'The test seed',
'docrefs': [],
'docs': {'show': True},
'compiled': True,
'compiled_sql': ANY,
'extra_ctes_injected': True,
Expand Down Expand Up @@ -2780,6 +2791,7 @@ def expected_run_results(self, quote_schema=True, quote_model=False,
},
'description': 'The test model',
'docrefs': [],
'docs': {'show': False},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'model'],
Expand Down Expand Up @@ -2868,6 +2880,7 @@ def expected_run_results(self, quote_schema=True, quote_model=False,
'depends_on': {'macros': [], 'nodes': []},
'description': 'The test seed',
'docrefs': [],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'seed'],
Expand Down Expand Up @@ -2922,6 +2935,7 @@ def expected_run_results(self, quote_schema=True, quote_model=False,
'depends_on': {'macros': [], 'nodes': ['model.test.model']},
'description': '',
'docrefs': [],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'schema_test', 'not_null_model_id'],
Expand Down Expand Up @@ -2980,6 +2994,7 @@ def expected_run_results(self, quote_schema=True, quote_model=False,
'depends_on': {'macros': [], 'nodes': ['model.test.model']},
'description': '',
'docrefs': [],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'schema_test', 'test_nothing_model_'],
Expand Down Expand Up @@ -3038,6 +3053,7 @@ def expected_run_results(self, quote_schema=True, quote_model=False,
'depends_on': {'macros': [], 'nodes': ['model.test.model']},
'description': '',
'docrefs': [],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'schema_test', 'unique_model_id'],
Expand Down Expand Up @@ -3159,6 +3175,7 @@ def expected_postgres_references_run_results(self):
'documentation_package': ''
}
],
'docs': {'show': True},
'extra_ctes': [
{'id': 'model.test.ephemeral_copy', 'sql': cte_sql},
],
Expand Down Expand Up @@ -3257,6 +3274,7 @@ def expected_postgres_references_run_results(self):
'documentation_package': ''
}
],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'view_summary'],
Expand Down Expand Up @@ -3349,6 +3367,7 @@ def expected_postgres_references_run_results(self):
'depends_on': {'macros': [], 'nodes': []},
'description': 'The test seed',
'docrefs': [],
'docs': {'show': True},
'extra_ctes': [],
'extra_ctes_injected': True,
'fqn': ['test', 'seed'],
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_contracts_graph_compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_basic_uncompiled(self):
'vars': {},
},
'docrefs': [],
'docs': {'show': True},
'columns': {},
'meta': {},
'compiled': False,
Expand Down Expand Up @@ -129,6 +130,7 @@ def test_basic_compiled(self):
'vars': {},
},
'docrefs': [],
'docs': {'show': True},
'columns': {},
'meta': {},
'compiled': True,
Expand Down Expand Up @@ -185,6 +187,7 @@ def test_invalid_extra_fields(self):
'database': 'test_db',
'schema': 'test_schema',
'alias': 'bar',
'docs': {'show': True},
'notvalid': 'nope',
}
self.assert_fails_validation(bad_extra)
Expand All @@ -203,6 +206,7 @@ def test_invalid_bad_type(self):
'database': 'test_db',
'schema': 'test_schema',
'alias': 'bar',
'docs': {'show': True},
}
self.assert_fails_validation(bad_type)

Expand Down Expand Up @@ -242,6 +246,7 @@ def test_basic_uncompiled(self):
'severity': 'error',
},
'docrefs': [],
'docs': {'show': True},
'columns': {},
'meta': {},
'compiled': False,
Expand Down Expand Up @@ -327,6 +332,7 @@ def test_basic_compiled(self):
'severity': 'warn',
},
'docrefs': [],
'docs': {'show': True},
'columns': {},
'meta': {},
'compiled': True,
Expand Down Expand Up @@ -385,6 +391,7 @@ def test_invalid_extra_fields(self):
'database': 'test_db',
'schema': 'test_schema',
'alias': 'bar',
'docs': {'show': True},
'extra': 'extra value',
}
self.assert_fails_validation(bad_extra)
Expand All @@ -403,5 +410,6 @@ def test_invalid_resource_type(self):
'database': 'test_db',
'schema': 'test_schema',
'alias': 'bar',
'docs': {'show': True},
}
self.assert_fails_validation(bad_type)
Loading

0 comments on commit ae3ef19

Please sign in to comment.