Skip to content

Commit b1a91a7

Browse files
authored
🐛 fix reserve word validate
1 parent dc0cfcc commit b1a91a7

File tree

5 files changed

+36245
-400
lines changed

5 files changed

+36245
-400
lines changed

codegen/parser/schemas/model_schema.py

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
DateSchema,
1919
EnumSchema,
2020
FileSchema,
21+
ListSchema,
2122
NoneSchema,
2223
SchemaData,
2324
FloatSchema,
@@ -109,11 +110,13 @@ def _is_string_subset(
109110
def _is_model_merge(
110111
source: Source, name: str, prefix: str, first: SchemaData, second: SchemaData
111112
) -> Optional[ModelSchema]:
112-
if isinstance(first, ModelSchema) and isinstance(second, ModelSchema):
113-
properties = {prop.name: prop for prop in first.properties}
113+
if (first_model := _find_schema(first, ModelSchema)) and (
114+
second_model := _find_schema(second, ModelSchema)
115+
):
116+
properties = {prop.name: prop for prop in first_model.properties}
114117
class_name = build_class_name(prefix)
115118

116-
for prop in second.properties:
119+
for prop in second_model.properties:
117120
if prop.name in properties:
118121
# try merge
119122
try:
@@ -133,12 +136,42 @@ def _is_model_merge(
133136
schema = ModelSchema(
134137
class_name=class_name,
135138
properties=list(properties.values()),
136-
allow_extra=first.allow_extra and second.allow_extra,
139+
allow_extra=first_model.allow_extra and second_model.allow_extra,
137140
)
138141
add_schema((source / "allof" / "merged" / name).uri, schema)
139142
return schema
140143

141144

145+
def _is_list_merge(
146+
source: Source, name: str, prefix: str, first: SchemaData, second: SchemaData
147+
) -> Optional[ListSchema]:
148+
if isinstance(first, ListSchema) and isinstance(second, ListSchema):
149+
return ListSchema(
150+
title=first.title,
151+
description=first.description,
152+
default=first.default,
153+
examples=first.examples,
154+
item_schema=_merge_schema(
155+
source, name, prefix, first.item_schema, second.item_schema
156+
),
157+
)
158+
159+
160+
def _merge_schema(
161+
source: Source, name: str, prefix: str, first: SchemaData, second: SchemaData
162+
):
163+
if schema := (
164+
_is_union_subset(first, second)
165+
or _is_string_subset(first, second)
166+
or _is_string_subset(second, first)
167+
or _is_enum_subset(first, second)
168+
or _is_model_merge(source, name, prefix, first, second)
169+
or _is_list_merge(source, name, prefix, first, second)
170+
):
171+
return schema
172+
raise RuntimeError(f"Cannot merge schema {first!r} {second!r}")
173+
174+
142175
def _merge_property(
143176
source: Source, first: Property, second: Property, prefix: str
144177
) -> Property:
@@ -148,31 +181,23 @@ def _merge_property(
148181
required = first.required or second.required
149182
nullable = _is_nullable(first.schema_data) and _is_nullable(second.schema_data)
150183

151-
if schema := (
152-
_is_union_subset(first.schema_data, second.schema_data)
153-
or _is_string_subset(first.schema_data, second.schema_data)
154-
or _is_string_subset(second.schema_data, first.schema_data)
155-
or _is_enum_subset(first.schema_data, second.schema_data)
156-
or _is_model_merge(
157-
source, first.name, prefix, first.schema_data, second.schema_data
158-
)
159-
):
160-
if nullable:
161-
schema = UnionSchema(
162-
title=schema.title,
163-
description=schema.description,
164-
default=schema.default,
165-
examples=schema.examples,
166-
schemas=[schema, NoneSchema()],
167-
)
168-
return Property(
169-
name=second.name,
170-
prop_name=second.prop_name,
171-
required=required,
172-
schema_data=schema,
184+
schema = _merge_schema(
185+
source, first.name, prefix, first.schema_data, second.schema_data
186+
)
187+
if nullable:
188+
schema = UnionSchema(
189+
title=schema.title,
190+
description=schema.description,
191+
default=schema.default,
192+
examples=schema.examples,
193+
schemas=[schema, NoneSchema()],
173194
)
174-
175-
raise RuntimeError(f"Cannot merge property {first!r} {second!r}")
195+
return Property(
196+
name=second.name,
197+
prop_name=second.prop_name,
198+
required=required,
199+
schema_data=schema,
200+
)
176201

177202

178203
def _process_properties(
@@ -247,7 +272,6 @@ def _add_if_no_conflict(prop: Property):
247272
schema_data=prop_schema,
248273
)
249274
)
250-
251275
return list(properties.values())
252276

253277

codegen/parser/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def split_words(value: str) -> List[str]:
2626
return re.findall(rf"[^{DELIMITERS}]+", value)
2727

2828

29-
RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - {
29+
RESERVED_WORDS = (
30+
set(dir(builtins)) | {"self", "true", "false", "datetime", "validate"}
31+
) - {
3032
"type",
3133
"id",
3234
}

githubkit/rest/code_scanning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def upload_sarif(
746746
checkout_uri: Union[Unset, str] = UNSET,
747747
started_at: Union[Unset, datetime] = UNSET,
748748
tool_name: Union[Unset, str] = UNSET,
749-
validate: Union[Unset, bool] = UNSET,
749+
validate_: Union[Unset, bool] = UNSET,
750750
) -> "Response[CodeScanningSarifsReceipt]":
751751
...
752752

@@ -802,7 +802,7 @@ async def async_upload_sarif(
802802
checkout_uri: Union[Unset, str] = UNSET,
803803
started_at: Union[Unset, datetime] = UNSET,
804804
tool_name: Union[Unset, str] = UNSET,
805-
validate: Union[Unset, bool] = UNSET,
805+
validate_: Union[Unset, bool] = UNSET,
806806
) -> "Response[CodeScanningSarifsReceipt]":
807807
...
808808

0 commit comments

Comments
 (0)