|
6 | 6 |
|
7 | 7 | from __future__ import annotations |
8 | 8 |
|
9 | | -from pathlib import Path |
10 | 9 | from typing import ( |
11 | 10 | TYPE_CHECKING, |
12 | 11 | Any, |
13 | 12 | ) |
14 | | -from urllib.parse import ParseResult |
15 | 13 |
|
16 | 14 | from typing_extensions import Unpack |
17 | 15 |
|
|
26 | 24 | from datamodel_code_generator.parser.base import ( |
27 | 25 | DataType, |
28 | 26 | Parser, |
29 | | - Source, |
30 | 27 | escape_characters, |
31 | 28 | ) |
32 | 29 | from datamodel_code_generator.reference import ModelType, Reference |
|
40 | 37 |
|
41 | 38 |
|
42 | 39 | if TYPE_CHECKING: |
43 | | - from collections.abc import Iterator |
| 40 | + from pathlib import Path |
| 41 | + from urllib.parse import ParseResult |
44 | 42 |
|
45 | 43 | from datamodel_code_generator._types import GraphQLParserConfigDict |
46 | 44 | from datamodel_code_generator.config import GraphQLParserConfig |
@@ -137,31 +135,6 @@ def __init__( |
137 | 135 | self.use_standard_collections = use_standard_collections |
138 | 136 | self.use_union_operator = use_union_operator |
139 | 137 |
|
140 | | - def _get_context_source_path_parts(self) -> Iterator[tuple[Source, list[str]]]: |
141 | | - # TODO (denisart): Temporarily this method duplicates |
142 | | - # the method `datamodel_code_generator.parser.jsonschema.JsonSchemaParser._get_context_source_path_parts`. |
143 | | - |
144 | | - if isinstance(self.source, list) or ( # pragma: no cover |
145 | | - isinstance(self.source, Path) and self.source.is_dir() |
146 | | - ): # pragma: no cover |
147 | | - self.current_source_path = Path() |
148 | | - self.model_resolver.after_load_files = { |
149 | | - self.base_path.joinpath(s.path).resolve().as_posix() for s in self.iter_source |
150 | | - } |
151 | | - |
152 | | - for source in self.iter_source: |
153 | | - if isinstance(self.source, ParseResult): # pragma: no cover |
154 | | - path_parts = self.get_url_path_parts(self.source) |
155 | | - else: |
156 | | - path_parts = list(source.path.parts) |
157 | | - if self.current_source_path is not None: # pragma: no cover |
158 | | - self.current_source_path = source.path |
159 | | - with ( |
160 | | - self.model_resolver.current_base_path_context(source.path.parent), |
161 | | - self.model_resolver.current_root_context(path_parts), |
162 | | - ): |
163 | | - yield source, path_parts |
164 | | - |
165 | 138 | def _resolve_types(self, paths: list[str], schema: graphql.GraphQLSchema) -> None: |
166 | 139 | for type_name, type_ in schema.type_map.items(): |
167 | 140 | if type_name.startswith("__"): |
@@ -523,13 +496,13 @@ def parse_raw(self) -> None: |
523 | 496 | graphql.type.introspection.TypeKind.UNION: self.parse_union, |
524 | 497 | } |
525 | 498 |
|
526 | | - for source, path_parts in self._get_context_source_path_parts(): |
527 | | - schema: graphql.GraphQLSchema = build_graphql_schema(source.text) |
528 | | - self.raw_obj = schema |
| 499 | + combined_schema = "\n".join(source.text for source in self.iter_source) |
| 500 | + schema: graphql.GraphQLSchema = build_graphql_schema(combined_schema) |
| 501 | + self.raw_obj = schema |
529 | 502 |
|
530 | | - self._resolve_types(path_parts, schema) |
| 503 | + self._resolve_types([], schema) |
531 | 504 |
|
532 | | - for next_type in self.parse_order: |
533 | | - for obj in self.support_graphql_types[next_type]: |
534 | | - parser_ = mapper_from_graphql_type_to_parser_method[next_type] |
535 | | - parser_(obj) |
| 505 | + for next_type in self.parse_order: |
| 506 | + for obj in self.support_graphql_types[next_type]: |
| 507 | + parser_ = mapper_from_graphql_type_to_parser_method[next_type] |
| 508 | + parser_(obj) |
0 commit comments