Skip to content

Commit

Permalink
fix: scaped apostrophe when original_schema is render in model. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosschroh authored Aug 23, 2024
1 parent 5b8d980 commit c1e7daa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
FIELD_TYPE_TEMPLATE = "$name: $type"
METACLASS_FIELD_TEMPLATE = '$name = "$value"'
METACLASS_ALIAS_FIELD = "$name = $value"
METACLASS_SCHEMA_FIELD = "$name = '$schema'"
METACLASS_SCHEMA_FIELD = '$name = """$schema"""'
METACLASS_DECORATOR = "@enum.nonmember" if PYTHON_VERSION_GE_311 else ""
FIELD_DEFAULT_TEMPLATE = " = $default"
OPTIONAL_TEMPLATE = "typing.Optional[$type]"
Expand Down
2 changes: 1 addition & 1 deletion tests/model_generator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def schema_one_to_many_array_relationship() -> JsonDict:
{"name": "street", "type": "string"},
{"name": "street_number", "type": "long"},
],
"doc": "An Address",
"doc": "Peter's Address",
},
"name": "address",
},
Expand Down
8 changes: 4 additions & 4 deletions tests/model_generator/test_model_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def test_schema_one_to_many_array_relationship(
@dataclasses.dataclass
class Address(AvroModel):
\"""
An Address
Peter's Address
\"""
street: str
street_number: int
Expand Down Expand Up @@ -742,14 +742,14 @@ def test_schema_with_schema_meta_field(
@dataclasses.dataclass
class Address(AvroModel):
\"""
An Address
Peter's Address
\"""
street: str
street_number: int
class Meta:
original_schema = '{"type": "record", "name": "Address", "fields": [{"name": "street", "type": "string"}, {"name": "street_number", "type": "long"}], "doc": "An Address"}'
original_schema = \"""{"type": "record", "name": "Address", "fields": [{"name": "street", "type": "string"}, {"name": "street_number", "type": "long"}], "doc": "Peter's Address"}\"""
@dataclasses.dataclass
class User(AvroModel):
Expand All @@ -761,7 +761,7 @@ class User(AvroModel):
class Meta:
original_schema = '{"type": "record", "name": "User", "fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "long"}, {"name": "addresses", "type": {"type": "array", "items": {"type": "record", "name": "Address", "fields": [{"name": "street", "type": "string"}, {"name": "street_number", "type": "long"}], "doc": "An Address"}, "name": "address"}}, {"name": "crazy_union", "type": ["string", {"type": "array", "items": "Address", "name": "optional_address"}]}, {"name": "optional_addresses", "type": ["null", {"type": "array", "items": "Address", "name": "optional_address"}], "default": null}]}'
original_schema = \"""{"type": "record", "name": "User", "fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "long"}, {"name": "addresses", "type": {"type": "array", "items": {"type": "record", "name": "Address", "fields": [{"name": "street", "type": "string"}, {"name": "street_number", "type": "long"}], "doc": "Peter's Address"}, "name": "address"}}, {"name": "crazy_union", "type": ["string", {"type": "array", "items": "Address", "name": "optional_address"}]}, {"name": "optional_addresses", "type": ["null", {"type": "array", "items": "Address", "name": "optional_address"}], "default": null}]}\"""
"""
model_generator = ModelGenerator()
result = model_generator.render(schema=schema_one_to_many_array_relationship, include_original_schema=True)
Expand Down

0 comments on commit c1e7daa

Please sign in to comment.