Skip to content

Commit

Permalink
source-hubspot-native: schematize propertiesWithHistory, but make it …
Browse files Browse the repository at this point in the history
…nullable

Since the top-level document has `additionalProperties: false`, the optional
`propertiesWithHistory` property needs to be in the schema, otherwise when the
option is turned on the capture this property there will be a schema violation.

This adds the property back to the schema, but makes it nullable, since it won't
always be there.
  • Loading branch information
williamhbaker committed Jan 10, 2025
1 parent f0c21cc commit c94068f
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 97 deletions.
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/companies.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/contacts.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/deals.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/engagements.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/line_items.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/products.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
21 changes: 8 additions & 13 deletions source-hubspot-native/acmeCo/tickets.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ $defs:
History:
additionalProperties: false
properties:
_meta:
allOf:
- $ref: "#/$defs/Meta"
default:
op: u
row_id: -1
description: Document metadata
timestamp:
format: date-time
title: Timestamp
Expand Down Expand Up @@ -93,13 +86,15 @@ properties:
- type: "null"
title: Properties
propertiesWithHistory:
additionalProperties:
items:
$ref: "#/$defs/History"
type: array
default: {}
anyOf:
- additionalProperties:
items:
$ref: "#/$defs/History"
type: array
type: object
- type: "null"
default: ~
title: Propertieswithhistory
type: object
associations:
additionalProperties: false
default: {}
Expand Down
12 changes: 6 additions & 6 deletions source-hubspot-native/source_hubspot_native/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class History(BaseModel, extra="forbid"):
archived: bool

properties: dict[str, str | None]
propertiesWithHistory: SkipJsonSchema[dict[str, list[History]]] = {}
propertiesWithHistory: dict[str, list[History]] | None = None

class InlineAssociations(BaseModel):
class Entry(BaseModel):
Expand All @@ -180,11 +180,11 @@ class Entry(BaseModel):
def _post_init(self) -> Self:
# Clear properties and history which don't have current values.
self.properties = {k: v for k, v in self.properties.items() if v}
self.propertiesWithHistory = {
k: v for k, v in self.propertiesWithHistory.items() if len(v)
}
if len(self.propertiesWithHistory) == 0:
delattr(self, "propertiesWithHistory")
if self.propertiesWithHistory:
self.propertiesWithHistory = {
k: v for k, v in self.propertiesWithHistory.items() if len(v)
}


# If the model has attached inline associations,
# hoist them to corresponding arrays. Then clear associations.
Expand Down
Loading

0 comments on commit c94068f

Please sign in to comment.