Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imports for TS autogenerated imports #239

Merged
merged 5 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion stone/backends/tsd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
fmt_func,
fmt_tag,
fmt_type,
get_data_types_for_namespace,
)
from stone.ir import Void

Expand Down Expand Up @@ -154,7 +155,11 @@ def generate(self, api):
self.emit_raw(template[r_end + 1:t_end] + ('\n' if not t_ends_with_newline else ''))

def _generate_import(self, api, type_file):
namespaces = ", ".join(map(lambda namespace: namespace.name, api.namespaces.values()))
# identify which routes belong to
namespaces_with_types = filter(
lambda namespace: len(get_data_types_for_namespace(namespace)) != 0,
api.namespaces.values())
namespaces = ", ".join(map(lambda namespace: namespace.name, namespaces_with_types))
self.emit("import { %s } from '%s';" % (namespaces, type_file))

def _generate_routes(self, api, spaces_per_indent, indent_level):
Expand Down
3 changes: 3 additions & 0 deletions stone/backends/tsd_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ def generate_imports_for_referenced_namespaces(backend, namespace, module_name_p
)
)
backend.emit()

def get_data_types_for_namespace(namespace):
return namespace.data_types + namespace.aliases
8 changes: 3 additions & 5 deletions stone/backends/tsd_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
fmt_type_name,
fmt_union,
generate_imports_for_referenced_namespaces,
get_data_types_for_namespace,
)


Expand Down Expand Up @@ -186,15 +187,12 @@ def _read_template(self):
else:
raise AssertionError('TypeScript template file does not exist.')

def _get_data_types(self, namespace):
return namespace.data_types + namespace.aliases

def _generate_base_namespace_module(self, namespace_list, filename,
template, extra_args,
exclude_error_types=False):

# Skip namespaces that do not contain types.
if all([len(self._get_data_types(ns)) == 0 for ns in namespace_list]):
if all([len(get_data_types_for_namespace(ns)) == 0 for ns in namespace_list]):
return

spaces_per_indent = self.args.spaces_per_indent
Expand Down Expand Up @@ -238,7 +236,7 @@ def _generate_base_namespace_module(self, namespace_list, filename,
def _generate_types(self, namespace, spaces_per_indent, extra_args):
self.cur_namespace = namespace
# Count aliases as data types too!
data_types = self._get_data_types(namespace)
data_types = get_data_types_for_namespace(namespace)
# Skip namespaces that do not contain types.
if len(data_types) == 0:
return
Expand Down