changeset 160:2db15ae9f222

generate: Enable youtube API to be generated
author Lewin Bormann <lbo@spheniscida.de>
date Thu, 29 Oct 2020 21:51:38 +0100
parents 38bf78b7cf8a
children 2933cf1633fc
files generate/generate.py
diffstat 1 files changed, 8 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/generate/generate.py	Wed Oct 28 12:31:32 2020 +0100
+++ b/generate/generate.py	Thu Oct 29 21:51:38 2020 +0100
@@ -23,8 +23,8 @@
 
 def replace_keywords(name):
     return {
-        'type': ('typ', 'type'),
-        'enum': ('enums', 'enum'),
+        'type': 'typ',
+        'enum': 'enums',
     }.get(name, name)
 
 
@@ -99,6 +99,7 @@
 
             # Structs are represented as dicts that can be used to render the SchemaStructTmpl.
             if 'properties' in schema:
+                name = replace_keywords(name)
                 typ = name
                 struct = {'name': name, 'description': schema.get('description', ''), 'fields': []}
                 for pn, pp in schema['properties'].items():
@@ -111,12 +112,8 @@
                     else:
                         comment = None
                     cleaned_pn = replace_keywords(pn)
-                    if type(cleaned_pn) is tuple:
-                        jsonname = cleaned_pn[1]
-                        cleaned_pn = rust_identifier(cleaned_pn[0])
-                    else:
-                        jsonname = pn
-                        cleaned_pn = rust_identifier(cleaned_pn)
+                    jsonname = pn
+                    cleaned_pn = rust_identifier(cleaned_pn)
                     struct['fields'].append({
                         'name':
                         cleaned_pn,
@@ -225,7 +222,7 @@
             opt_query_parameters = []
             if global_params:
                 struct['fields'].append({
-                    'name': rust_identifier(global_params),
+                    'name': replace_keywords(rust_identifier(global_params)),
                     'typ': optionalize(global_params, True),
                     'attr': '#[serde(flatten)]',
                     'comment': 'General attributes applying to any API call'
@@ -235,7 +232,7 @@
                 for paramname, param in method['parameters'].items():
                     (typ, desc), substructs = parse_schema_types('', param, optional=False, parents=[])
                     field = {
-                        'name': rust_identifier(paramname),
+                        'name': replace_keywords(rust_identifier(paramname)),
                         'original_name': paramname,
                         'typ': optionalize(typ, not param.get('required', False)),
                         'comment': desc,
@@ -501,7 +498,7 @@
     # Generate global parameters struct and its Display impl.
     if 'parameters' in discdoc:
         schema = {'type': 'object', 'properties': discdoc['parameters']}
-        name = snake_to_camel(params_struct_name)
+        name = replace_keywords(snake_to_camel(params_struct_name))
         typ, substructs = parse_schema_types(name, schema)
         for s in substructs:
             s['optional_fields'] = s['fields']