Skip to content

Commit

Permalink
Make OpenAPI spec location configurable (#237)
Browse files Browse the repository at this point in the history
Introducing `DATABRICKS_OPENAPI_SPEC` environment variable to hold a
filesystem location of `all-internal.json` spec.
  • Loading branch information
nfx authored Jul 17, 2023
1 parent c2ebc4f commit 7350f21
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions docs/gen-client-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,26 @@ class Generator:
def __init__(self):
self.mapping = self._load_mapping()

def _load_mapping(self) -> dict[str, Tag]:
mapping = {}
pkgs = {p.name: p for p in self.packages}
def _spec_file(self) -> str:
if 'DATABRICKS_OPENAPI_SPEC' in os.environ:
return os.environ['DATABRICKS_OPENAPI_SPEC']
with open(os.path.expanduser('~/.openapi-codegen.json'), 'r') as f:
config = json.load(f)
if 'spec' not in config:
raise ValueError('Cannot find OpenAPI spec')
with open(config['spec'], 'r') as fspec:
spec = json.load(fspec)
for tag in spec['tags']:
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
return config['spec']

def _load_mapping(self) -> dict[str, Tag]:
mapping = {}
pkgs = {p.name: p for p in self.packages}
with open(self._spec_file(), 'r') as fspec:
spec = json.load(fspec)
for tag in spec['tags']:
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
return mapping

def class_methods(self, inst) -> list[MethodDoc]:
Expand Down Expand Up @@ -216,12 +221,12 @@ def _write_client_packages(self, folder: str, label: str, description: str, pack
f.write(f'''
{label}
{'=' * len(label)}
{description}
.. toctree::
:maxdepth: 1
{all}''')

def _write_client_package_doc(self, folder: str, pkg: Package, services: list[str]):
Expand All @@ -230,12 +235,12 @@ def _write_client_package_doc(self, folder: str, pkg: Package, services: list[st
f.write(f'''
{pkg.label}
{'=' * len(pkg.label)}
{pkg.description}
.. toctree::
:maxdepth: 1
{all}''')


Expand Down

0 comments on commit 7350f21

Please sign in to comment.