Skip to content
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

Propagate unparsed objects #1425

Merged
merged 4 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .generator/src/generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def cli(input, output):
model_path = output / filename
model_path.parent.mkdir(parents=True, exist_ok=True)
with model_path.open("w") as fp:
fp.write(model_j2.render(name=name, model=model))
fp.write(model_j2.render(name=name, model=model, models=models))

for name, operations in apis.items():
filename = "api_" + formatter.snake_case(name) + ".go"
Expand Down
10 changes: 10 additions & 0 deletions .generator/src/generator/templates/model_simple.j2
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,16 @@ func (o *{{ name }}) UnmarshalJSON(bytes []byte) (err error) {
{%- endfor %}
{%- for attr, spec in model.get("properties", {}).items() %}
{%- set propertyName = attr|attribute_name %}
{%- set dataType = get_type(spec, alternative_name=name + propertyName, render_nullable=True) %}
{%- if dataType in models and not spec.enum and not spec.oneOf %}
if {% if model|is_reference(attr) %} all.{{ propertyName }} != nil && {% endif %}all.{{ propertyName }}.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
{%- endif %}
o.{{ propertyName }} = all.{{ propertyName }}
{%- endfor %}
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_alert_graph_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ func (o *AlertGraphWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) {
return nil
}
o.AlertId = all.AlertId
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_api_key_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (o *ApiKeyResponse) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.ApiKey != nil && all.ApiKey.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ApiKey = all.ApiKey
return nil
}
7 changes: 7 additions & 0 deletions api/v1/datadog/model_application_key_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ func (o *ApplicationKeyResponse) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.ApplicationKey != nil && all.ApplicationKey.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ApplicationKey = all.ApplicationKey
return nil
}
7 changes: 7 additions & 0 deletions api/v1/datadog/model_change_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ func (o *ChangeWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) {
}
o.CustomLinks = all.CustomLinks
o.Requests = all.Requests
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
Expand Down
56 changes: 56 additions & 0 deletions api/v1/datadog/model_change_widget_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,22 +783,78 @@ func (o *ChangeWidgetRequest) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.ApmQuery != nil && all.ApmQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ApmQuery = all.ApmQuery
o.ChangeType = all.ChangeType
o.CompareTo = all.CompareTo
if all.EventQuery != nil && all.EventQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.EventQuery = all.EventQuery
o.Formulas = all.Formulas
o.IncreaseGood = all.IncreaseGood
if all.LogQuery != nil && all.LogQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.LogQuery = all.LogQuery
if all.NetworkQuery != nil && all.NetworkQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.NetworkQuery = all.NetworkQuery
o.OrderBy = all.OrderBy
o.OrderDir = all.OrderDir
if all.ProcessQuery != nil && all.ProcessQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ProcessQuery = all.ProcessQuery
if all.ProfileMetricsQuery != nil && all.ProfileMetricsQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ProfileMetricsQuery = all.ProfileMetricsQuery
o.Q = all.Q
o.Queries = all.Queries
o.ResponseFormat = all.ResponseFormat
if all.RumQuery != nil && all.RumQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.RumQuery = all.RumQuery
if all.SecurityQuery != nil && all.SecurityQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.SecurityQuery = all.SecurityQuery
o.ShowPresent = all.ShowPresent
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_check_can_delete_monitor_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ func (o *CheckCanDeleteMonitorResponse) UnmarshalJSON(bytes []byte) (err error)
o.UnparsedObject = raw
return nil
}
if all.Data.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Data = all.Data
o.Errors = all.Errors
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_check_can_delete_slo_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ func (o *CheckCanDeleteSLOResponse) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.Data != nil && all.Data.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Data = all.Data
o.Errors = all.Errors
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_check_status_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ func (o *CheckStatusWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) {
o.GroupBy = all.GroupBy
o.Grouping = all.Grouping
o.Tags = all.Tags
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_dashboard_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ func (o *DashboardList) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.Author != nil && all.Author.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Author = all.Author
o.Created = all.Created
o.DashboardCount = all.DashboardCount
Expand Down
21 changes: 21 additions & 0 deletions api/v1/datadog/model_distribution_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,33 @@ func (o *DistributionWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) {
o.Markers = all.Markers
o.Requests = all.Requests
o.ShowLegend = all.ShowLegend
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
o.TitleSize = all.TitleSize
o.Type = all.Type
if all.Xaxis != nil && all.Xaxis.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Xaxis = all.Xaxis
if all.Yaxis != nil && all.Yaxis.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Yaxis = all.Yaxis
return nil
}
70 changes: 70 additions & 0 deletions api/v1/datadog/model_distribution_widget_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,86 @@ func (o *DistributionWidgetRequest) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.ApmQuery != nil && all.ApmQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ApmQuery = all.ApmQuery
if all.ApmStatsQuery != nil && all.ApmStatsQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ApmStatsQuery = all.ApmStatsQuery
if all.EventQuery != nil && all.EventQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.EventQuery = all.EventQuery
if all.LogQuery != nil && all.LogQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.LogQuery = all.LogQuery
if all.NetworkQuery != nil && all.NetworkQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.NetworkQuery = all.NetworkQuery
if all.ProcessQuery != nil && all.ProcessQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ProcessQuery = all.ProcessQuery
if all.ProfileMetricsQuery != nil && all.ProfileMetricsQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.ProfileMetricsQuery = all.ProfileMetricsQuery
o.Q = all.Q
if all.RumQuery != nil && all.RumQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.RumQuery = all.RumQuery
if all.SecurityQuery != nil && all.SecurityQuery.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.SecurityQuery = all.SecurityQuery
if all.Style != nil && all.Style.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Style = all.Style
return nil
}
7 changes: 7 additions & 0 deletions api/v1/datadog/model_event_create_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ func (o *EventCreateResponse) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.Event != nil && all.Event.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Event = all.Event
o.Status = all.Status
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_event_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ func (o *EventResponse) UnmarshalJSON(bytes []byte) (err error) {
o.UnparsedObject = raw
return nil
}
if all.Event != nil && all.Event.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Event = all.Event
o.Status = all.Status
return nil
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_event_stream_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ func (o *EventStreamWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) {
o.EventSize = all.EventSize
o.Query = all.Query
o.TagsExecution = all.TagsExecution
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
Expand Down
7 changes: 7 additions & 0 deletions api/v1/datadog/model_event_timeline_widget_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ func (o *EventTimelineWidgetDefinition) UnmarshalJSON(bytes []byte) (err error)
}
o.Query = all.Query
o.TagsExecution = all.TagsExecution
if all.Time != nil && all.Time.UnparsedObject != nil && o.UnparsedObject == nil {
err = json.Unmarshal(bytes, &raw)
if err != nil {
return err
}
o.UnparsedObject = raw
}
o.Time = all.Time
o.Title = all.Title
o.TitleAlign = all.TitleAlign
Expand Down
Loading