Skip to content

Commit

Permalink
[Fix] Fix docs generation when two services have the same name (#872)
Browse files Browse the repository at this point in the history
## What changes are proposed in this pull request?

Fix docs generation when two services have the same name. Currently,
only one service docs will be generated.

## How is this tested?

Regenerated current Docs
  • Loading branch information
hectorcast-db authored Jan 24, 2025
1 parent 5576d32 commit 4bcfb0a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions docs/gen-client-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,22 @@ def _load_mapping(self) -> dict[str, Tag]:
pkgs = {p.name: p for p in self.packages}
spec = json.loads(self._openapi_spec())
for tag in spec['tags']:
is_account=tag.get('x-databricks-is-accounts')
# Unique identifier for the tag. Note that the service name may not be unique
key = 'a' if is_account else 'w'
parent_service = tag.get('x-databricks-parent-service')
if parent_service:
# SDK generation removes the "account" prefix from account services
clean_parent_service = parent_service.lower().removeprefix("account")
key = f"{key}.{clean_parent_service}"

key = f"{key}.{tag['x-databricks-service']}".lower()

t = Tag(name=tag['name'],
service=tag['x-databricks-service'],
is_account=tag.get('x-databricks-is-accounts', False),
package=pkgs[tag['x-databricks-package']])
mapping[tag['name']] = t
mapping[key] = t
return mapping

@staticmethod
Expand Down Expand Up @@ -360,7 +371,7 @@ def service_docs(self, client_inst, client_prefix: str) -> list[ServiceDoc]:
service_name=service_name,
class_name=class_name,
doc=class_doc,
tag=self._get_tag_name(service_inst.__class__.__name__, service_name),
tag=self._get_tag_name(service_inst.__class__.__name__, client_prefix, service_name),
methods=self.class_methods(service_inst),
property=self.class_properties(service_inst)))
return all
Expand Down Expand Up @@ -399,13 +410,13 @@ def write_dataclass_docs(self):
{all}''')

def _get_tag_name(self, class_name, service_name) -> Tag:
def _get_tag_name(self, class_name, client_prefix, service_name) -> Tag:
if class_name[-3:] == 'Ext':
# ClustersExt, DbfsExt, WorkspaceExt, but not ExternalLocations
class_name = class_name.replace('Ext', 'API')
class_name = class_name[:-3]
for tag_name, t in self.mapping.items():
if t.service.lower() == str(class_name).lower():
for key, t in self.mapping.items():
if key == f'{client_prefix}.{str(class_name).lower()}':
return t
raise KeyError(f'Cannot find {class_name} / {service_name} tag')

Expand Down

0 comments on commit 4bcfb0a

Please sign in to comment.