Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smondet committed Dec 27, 2024
1 parent c5822da commit 174a1e6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
54 changes: 50 additions & 4 deletions tests/grok.t
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Generate ATD types from grok (Grafana Object Development Kit) dashboard types
type matcherConfig = {
~id <doc text="The matcher id. This is used to find the matcher implementation from registry."> <ocaml default="\"\"">: string;
?options <doc text="The matcher options. This is specific to the matcher implementation.">: json option;
?options <doc text="The matcher options. This is specific to the matcher implementation.">: json (* MatcherConfig/options *) option;
} <doc text="Matcher is a predicate configuration. Based on the config a set of field(s) or values is filtered in order to apply override / transformation.\nIt comes with in id ( to resolve implementation from registry) and a configuration that\226\128\153s specific to a particular matcher type.">
type mappingType = [
Expand Down Expand Up @@ -388,7 +388,7 @@ Generate ATD types from grok (Grafana Object Development Kit) dashboard types
?mappings <doc text="Convert input values into a display string">: valueMapping list option;
?thresholds : thresholdsConfig option;
?color : fieldColor option;
?links <doc text="The behavior when clicking on a result">: json list option;
?links <doc text="The behavior when clicking on a result">: json (* FieldConfig/links *) list option;
?noValue <doc text="Alternative to empty string">: string option;
?custom <doc text="custom is specified by the FieldConfig field\nin panel plugin schemas.">: json option;
} <doc text="The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.\nEach column within this structure is called a field. A field can represent a single time series or table column.\nField options allow you to change how the data is displayed in your visualizations.">
Expand Down Expand Up @@ -425,14 +425,14 @@ Generate ATD types from grok (Grafana Object Development Kit) dashboard types
type dynamicConfigValue = {
~id <ocaml default="\"\"">: string;
?value : json option;
?value : json (* DynamicConfigValue/value *) option;
}
type dataTransformerConfig = {
id <doc text="Unique identifier of transformer">: string;
?disabled <doc text="Disabled transformations are skipped">: bool option;
?filter : matcherConfig option;
options <doc text="Options to be passed to the transformer\nValid options depend on the transformer id">: json;
options <doc text="Options to be passed to the transformer\nValid options depend on the transformer id">: json (* DataTransformerConfig/options *);
} <doc text="Transformations allow to manipulate data returned by a query before the system applies a visualization.\nUsing transformations you can: rename fields, join time series data, perform mathematical operations across queries,\nuse the output of one transformation as the input to another transformation, etc.">
type dataSourceRef = {
Expand Down Expand Up @@ -487,3 +487,49 @@ Generate ATD types from grok (Grafana Object Development Kit) dashboard types
type annotationContainer = {
?list <doc text="List of annotations">: annotationQuery list option;
} <doc text="Contains the list of annotations that are associated with the dashboard.\nAnnotations are used to overlay event markers and overlay event tags on graphs.\nGrafana comes with a native annotation store and the ability to add annotation events directly from the graph panel or via the HTTP API.\nSee https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/annotate-visualizations/">
Generate ATD types from grok, only partially using `--only-matching`
$ jsonschema2atd --format openapi --only-matching 'Annotation.*' ./mocks/dashboard_types_gen.json
(* Generated by jsonschema2atd from dashboard_types_gen.json *)
type json <ocaml module="Yojson.Basic" t="t"> = abstract
type int64 = int <ocaml repr="int64">
type annotationTarget = {
limit <doc text="Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change">: int64;
matchAny <doc text="Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change">: bool;
tags <doc text="Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change">: string list;
type_ <json name="type"> <doc text="Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change">: string;
} <doc text="TODO: this should be a regular DataQuery that depends on the selected dashboard\nthese match the properties of the \"grafana\" datasouce that is default in most dashboards">
type annotationQuery = {
name <doc text="Name of annotation.">: string;
datasource : dataSourceRef;
~enable <doc text="When enabled the annotation query is issued with every dashboard refresh"> <ocaml default="true">: bool;
~hide <doc text="Annotation queries can be toggled on or off at the top of the dashboard.\nWhen hide is true, the toggle is not shown in the dashboard."> <ocaml default="false">: bool;
iconColor <doc text="Color to use for the annotation event markers">: string;
?filter : annotationPanelFilter option;
?target : annotationTarget option;
?type_ <json name="type"> <doc text="TODO -- this should not exist here, it is based on the --grafana-- datasource">: string option;
~builtIn <doc text="Set to 1 for the standard annotation query all dashboards have by default."> <ocaml default="0">: float;
} <doc text="TODO docs\nFROM: AnnotationQuery in grafana-data/src/types/annotations.ts">
type annotationPanelFilter = {
~exclude <doc text="Should the specified panels be included or excluded"> <ocaml default="false">: bool;
ids <doc text="Panel IDs that should be included or excluded">: int list;
}
type annotationContainer = {
?list <doc text="List of annotations">: annotationQuery list option;
} <doc text="Contains the list of annotations that are associated with the dashboard.\nAnnotations are used to overlay event markers and overlay event tags on graphs.\nGrafana comes with a native annotation store and the ability to add annotation events directly from the graph panel or via the HTTP API.\nSee https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/annotate-visualizations/">
Generate ATD types from grok, only partially using `--only-matching`, `--avoid-dangling` and with a custom JSON type
$ jsonschema2atd --format openapi --only-matching 'FieldColor' --json-ocaml-type from:CustomJson:json --avoid-dangling-refs ./mocks/dashboard_types_gen.json
(* Generated by jsonschema2atd from dashboard_types_gen.json *)
type json <ocaml from="CustomJson" t="json"> = abstract
type int64 = int <ocaml repr="int64">
type fieldColor = {
mode : json (* #/components/schemas/FieldColorModeId *);
?fixedColor <doc text="The fixed color value for fixed or shades color modes.">: string option;
?seriesBy : json (* #/components/schemas/FieldColorSeriesByMode *) option;
} <doc text="Map a field to a color.">
7 changes: 7 additions & 0 deletions tests/smoke.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ Generate ATD out of JSON Schema that uses references
?ff : address option;
}

Generate ATD out of JSON Schema that uses references
$ jsonschema2atd --format=jsonschema --only-matching nothing ./mocks/jsonschema_refs.json
(* Generated by jsonschema2atd from jsonschema_refs.json *)
type json <ocaml module="Yojson.Basic" t="t"> = abstract
type int64 = int <ocaml repr="int64">


Generate ATD out of JSON Schema that uses enums
$ jsonschema2atd --format=jsonschema ./mocks/jsonschema_enums.json
(* Generated by jsonschema2atd from jsonschema_enums.json *)
Expand Down

0 comments on commit 174a1e6

Please sign in to comment.