Skip to content

Commit

Permalink
Add jsonschema export handling for empty subfields (datacontract#219)
Browse files Browse the repository at this point in the history
* Add handling for empty subfields

* add test for empty object fix + update changelog
  • Loading branch information
hcrosse authored May 24, 2024
1 parent 9340f74 commit 479c72e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `datacontract export --format dbml`: Export to [Database Markup Language (DBML)](https://dbml.dbdiagram.io/home/) (#135)

### Fixed

- Fixed jsonschema export for models with empty object-typed fields (#218)

## [0.10.4] - 2024-05-17

### Added
Expand Down
2 changes: 1 addition & 1 deletion datacontract/export/jsonschema_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def to_property(field: Field) -> dict:
property["unique"] = True
if json_type == "object":
# TODO: any better idea to distinguish between properties and patternProperties?
if next(iter(field.fields.keys())).startswith("^"):
if field.fields.keys() and next(iter(field.fields.keys())).startswith("^"):
property["patternProperties"] = to_properties(field.fields)
else:
property["properties"] = to_properties(field.fields)
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/local-json-complex/datacontract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ models:
type: string
pattern: "^[0-9]{8}$"
required: true
empty_object:
type: object
examples:
- type: json # csv, json, yaml, custom
model: sts_data
Expand Down
8 changes: 8 additions & 0 deletions tests/test_export_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ def test_to_jsonschemas_complex_2():
"connection_test",
"key_list"
]
},
"empty_object": {
"type": [
"object",
"null"
],
"properties": {},
"required": []
}
},
"required": [
Expand Down

0 comments on commit 479c72e

Please sign in to comment.