-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JSON schema descriptions for BQ and ES #18
Changes from 15 commits
dcb5085
90a5397
b14cbd8
9d1ec4e
dece722
7d36532
e5d0263
b61f45a
909ab52
0ad3719
6f60bfd
83809cd
87952a2
69be485
1b0cfb7
eaef702
62a58a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,11 @@ def __init__(self, | |
es_index=None, | ||
es_analyzer=None, | ||
doc=None, | ||
examples=None, | ||
es_include_raw=None, | ||
deprecated=False, | ||
ignore=False, | ||
autocomplete_include=True, | ||
autocomplete_category=None, | ||
autocomplete_icon=None, | ||
category=None, | ||
exclude=None, | ||
metadata=None, | ||
units=None, | ||
|
@@ -30,6 +29,7 @@ def __init__(self, | |
self.es_index = es_index | ||
self.es_analyzer = es_analyzer | ||
self.doc = doc | ||
self.examples = examples if examples else [] | ||
if es_include_raw is not None: | ||
self.es_include_raw = es_include_raw | ||
else: | ||
|
@@ -40,9 +40,7 @@ def __init__(self, | |
e = "WARN: %s is deprecated and will be removed in a "\ | ||
"future release\n" % self.__class__.__name__ | ||
sys.stderr.write(e) | ||
self.autocomplete_category = autocomplete_category | ||
self.autocomplete_category = autocomplete_category | ||
self.autocomplete_icon = autocomplete_icon | ||
self.category = category | ||
self._exclude = set(exclude) if exclude else set([]) | ||
self.metadata = metadata if metadata else {} | ||
self.units = units | ||
|
@@ -56,7 +54,8 @@ def to_dict(self): | |
"type":self.__class__.__name__, | ||
"es_type":self.ES_TYPE, | ||
"bq_type":self.BQ_TYPE, | ||
"metadata":self.metadata | ||
"metadata":self.metadata, | ||
"examples": self.examples, | ||
} | ||
if self.units is not None: | ||
retv["units"] = self.units | ||
|
@@ -72,13 +71,36 @@ def to_es(self): | |
self.add_es_var(retv, "analyzer", "es_analyzer", "ES_ANALYZER") | ||
self.add_es_var(retv, "search_analyzer", "es_search_analyzer", | ||
"ES_SEARCH_ANALYZER") | ||
|
||
if self.es_include_raw: | ||
retv["fields"] = { | ||
"raw":{"type":"keyword"} | ||
} | ||
return retv | ||
|
||
def _docs_common(self, parent_category): | ||
retv = { | ||
"detail_type": self.__class__.__name__, | ||
"category": self.category or parent_category, | ||
"doc": self.doc, | ||
"required": self.required, | ||
} | ||
if hasattr(self, "values_s") and len(self.values_s): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are It would be nice if the values could be individually documented (something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It se ms reasonable to let different types define their own type of '.doc' property. The default could be to just hand back._doc but could also do something else like compilea list of enumerated values into a doc string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If there is an exhaustive list of possible values, I see no reason to support a list of example values as well.
Maybe, though I'm unconvinced this is worth the work to implement. The two examples of enums I recall offhand in our schema are elliptic curves and certificate types (leaf/intermediate/root), both of which seem plenty self-explanatory given the existence of a docstring for the field and a list of possible values.
@zakird I'm not sure I follow what you're suggesting here. As of this PR, types can have a docstring and a list of example values (or a list of possible values, for enums). What are you suggesting should change? |
||
retv["values"] = list(self.values_s) | ||
else: | ||
retv["examples"] = self.examples | ||
return retv | ||
|
||
def docs_es(self, parent_category=None): | ||
retv = self._docs_common(parent_category) | ||
self.add_es_var(retv, "analyzer", "es_analyzer", "ES_ANALYZER") | ||
retv["type"] = self.ES_TYPE | ||
return retv | ||
|
||
def docs_bq(self, parent_category=None): | ||
retv = self._docs_common(parent_category) | ||
retv["type"] = self.BQ_TYPE | ||
return retv | ||
|
||
def to_bigquery(self, name): | ||
if not self._check_valid_name(name): | ||
raise Exception("Invalid field name: %s" % name) | ||
|
@@ -118,9 +140,6 @@ def to_flat(self, parent, name, repeated=False): | |
"mode":mode | ||
} | ||
|
||
def to_autocomplete(self, parent, name, repated=False): | ||
pass | ||
|
||
def print_indent_string(self, name, indent): | ||
val = self.key_to_string(name) | ||
if indent: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it would be nice if this could be overridden...
__class__.__name__
doesn't keep package information (?)Beyond the scope of this PR, but I just noticed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, @justinbastress. It looks like coupling to
__class__.__name__
has been the idiom for a while (e.g., an initial commit for the CLI), but an area for future improvement.