Skip to content

Commit

Permalink
Make documentation generation optional and improve objc path specific…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
julianlocke committed Feb 8, 2024
1 parent f4cf70d commit 9871cdf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
8 changes: 1 addition & 7 deletions stone/backends/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,8 @@ def _docf(self, tag, val):
else:
return val

def _write_output_in_target_folder(self, output, file_name, objc=False, rop=None):
def _write_output_in_target_folder(self, output, file_name):

Check warning on line 272 in stone/backends/swift.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift.py#L272

Added line #L272 was not covered by tests
full_path = self.target_folder_path
if objc:
if rop is None:
full_path = full_path.replace('Source/SwiftyDropbox', 'Source/SwiftyDropboxObjC')
else:
full_path = '{}{}'.format(full_path, rop)

if not os.path.exists(full_path):
os.mkdir(full_path)
full_path = os.path.join(full_path, file_name)
Expand Down
25 changes: 7 additions & 18 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,9 @@
help='The dict that maps a style type to a Swift request object name.',
)
_cmdline_parser.add_argument(
'-objc',
'--objc',
action='store_true',
help='Generate the Objective-C compatibile files as well as the standard Swift files.',
)
_cmdline_parser.add_argument(
'-rop',
'--relative-objc-path',
type=str,
help='Custom output path for Objective-C compatible files relative to the standard Swift files',
help='Generate the Objective-C compatibile files.',
)


Expand Down Expand Up @@ -146,7 +140,8 @@ def generate(self, api):

self._generate_client(api)
self._generate_request_boxes(api)
self._generate_reconnection_helpers(api)
if not self.args.objc:
self._generate_reconnection_helpers(api)

Check warning on line 144 in stone/backends/swift_client.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_client.py#L144

Added line #L144 was not covered by tests

def _generate_client(self, api):
template_globals = {}
Expand All @@ -160,9 +155,7 @@ def _generate_client(self, api):
template.globals = template_globals

self._write_output_in_target_folder(template.render(),
'DBX{}.swift'.format(self.args.module_name),
True,
self.args.relative_objc_path)
'DBX{}.swift'.format(self.args.module_name))
else:
template = self._jinja_template("SwiftClient.jinja")
template.globals = template_globals
Expand Down Expand Up @@ -224,9 +217,7 @@ def _generate_routes(self, namespace):
output_from_parsed_template = template.render(namespace=namespace)

self._write_output_in_target_folder(output_from_parsed_template,
'DBX{}Routes.swift'.format(ns_class),
True,
self.args.relative_objc_path)
'DBX{}Routes.swift'.format(ns_class))
else:
template = self._jinja_template("SwiftRoutes.jinja")
template.globals = template_globals
Expand Down Expand Up @@ -267,9 +258,7 @@ def _generate_request_boxes(self, api):

file_name = 'DBX{}RequestBox.swift'.format(self.args.class_name)
self._write_output_in_target_folder(output,
file_name,
True,
self.args.relative_objc_path)
file_name)
else:
template = self._jinja_template("SwiftRequestBox.jinja")
template.globals = template_globals
Expand Down
2 changes: 1 addition & 1 deletion stone/backends/swift_rsrc/SwiftReconnectionHelpers.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

enum {{ class_name }} {
enum {{ class_name }}: ReconnectionHelpersShared {

static func rebuildRequest(apiRequest: ApiRequest, client: DropboxTransportClientInternal) throws -> {{ return_type }} {
let info = try persistedRequestInfo(from: apiRequest)
Expand Down
49 changes: 26 additions & 23 deletions stone/backends/swift_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,17 @@
'{route} for the route name.'),
)
_cmdline_parser.add_argument(
'-objc',
'--objc',
action='store_true',
help='Generate the Objective-C compatibile files as well as the standard Swift files.',
help='Generate the Objective-C compatibile files',
)
_cmdline_parser.add_argument(
'-rop',
'--relative-objc-path',
type=str,
help='A custom output path for Objective-C compatible files relative to standard Swift files',
'-d',
'--documentation',
action='store_true',
help=('Sets whether documentation is generated.'),
)


class SwiftTypesBackend(SwiftBaseBackend):
"""
Generates Swift modules to represent the input Stone spec.
Expand Down Expand Up @@ -132,19 +131,16 @@ class SwiftTypesBackend(SwiftBaseBackend):
cmdline_parser = _cmdline_parser
def generate(self, api):
rsrc_folder = os.path.join(os.path.dirname(__file__), 'swift_rsrc')
self.logger.info('Copying StoneValidators.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneValidators.swift'),
self.target_folder_path)
self.logger.info('Copying StoneSerializers.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneSerializers.swift'),
self.target_folder_path)
self.logger.info('Copying StoneBase.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneBase.swift'),
self.target_folder_path)

jazzy_cfg_path = os.path.join('../Format', 'jazzy.json')
with open(jazzy_cfg_path, encoding='utf-8') as jazzy_file:
jazzy_cfg = json.load(jazzy_file)
if not self.args.objc:
self.logger.info('Copying StoneValidators.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneValidators.swift'),

Check warning on line 136 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L135-L136

Added lines #L135 - L136 were not covered by tests
self.target_folder_path)
self.logger.info('Copying StoneSerializers.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneSerializers.swift'),

Check warning on line 139 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L138-L139

Added lines #L138 - L139 were not covered by tests
self.target_folder_path)
self.logger.info('Copying StoneBase.swift to output folder')
shutil.copy(os.path.join(rsrc_folder, 'StoneBase.swift'),

Check warning on line 142 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L141-L142

Added lines #L141 - L142 were not covered by tests
self.target_folder_path)

template_loader = jinja2.FileSystemLoader(searchpath=rsrc_folder)
template_env = jinja2.Environment(loader=template_loader,
Expand Down Expand Up @@ -207,15 +203,22 @@ def generate(self, api):
objc_output = objc_template.render(namespace=namespace,
route_schema=api.route_schema)
self._write_output_in_target_folder(objc_output,
'DBX{}.swift'.format(ns_class),
True,
self.args.relative_objc_path)
'DBX{}.swift'.format(ns_class))
else:
swift_output = swift_template.render(namespace=namespace,
route_schema=api.route_schema)
self._write_output_in_target_folder(swift_output,
'{}.swift'.format(ns_class))
if self.args.documentation:
self._generate_jazzy_docs(api)

Check warning on line 213 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L213

Added line #L213 was not covered by tests

def _generate_jazzy_docs(self, api):
jazzy_cfg_path = os.path.join('../Format', 'jazzy.json')
with open(jazzy_cfg_path, encoding='utf-8') as jazzy_file:
jazzy_cfg = json.load(jazzy_file)

Check warning on line 218 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L215-L218

Added lines #L215 - L218 were not covered by tests

for namespace in api.namespaces.values():
ns_class = fmt_class(namespace.name)

Check warning on line 221 in stone/backends/swift_types.py

View check run for this annotation

Codecov / codecov/patch

stone/backends/swift_types.py#L221

Added line #L221 was not covered by tests
jazzy_cfg['custom_categories'][1]['children'].append(ns_class)

if namespace.routes:
Expand Down

0 comments on commit 9871cdf

Please sign in to comment.