Mercurial > lbo > hg > async-google-apis
changeset 189:a7168ed85cc4
Run yapf
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 29 Jan 2021 11:48:09 +0100 |
parents | d6d4afc03622 |
children | 7b7ab508a20f |
files | generate/generate.py |
diffstat | 1 files changed, 23 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/generate/generate.py Fri Jan 29 11:44:58 2021 +0100 +++ b/generate/generate.py Fri Jan 29 11:48:09 2021 +0100 @@ -106,9 +106,9 @@ struct = {'name': name, 'description': schema.get('description', ''), 'fields': []} for pn, pp in schema['properties'].items(): subtyp, substructs, subenums = parse_schema_types(name + capitalize_first(pn), - pp, - optional=True, - parents=parents + [name]) + pp, + optional=True, + parents=parents + [name]) if type(subtyp) is tuple: subtyp, comment = subtyp else: @@ -137,21 +137,26 @@ if 'additionalProperties' in schema: field, substructs, subenums = parse_schema_types(name, - schema['additionalProperties'], - optional=False, - parents=parents + [name]) + schema['additionalProperties'], + optional=False, + parents=parents + [name]) structs.extend(substructs) if type(field) is tuple: typ = field[0] else: typ = field - return (optionalize('HashMap<String,' + typ + '>', optional), schema.get('description', '')), structs, subenums + return (optionalize('HashMap<String,' + typ + '>', optional), schema.get('description', + '')), structs, subenums if schema['type'] == 'array': - typ, substructs, subenums = parse_schema_types(name, schema['items'], optional=False, parents=parents + [name]) + typ, substructs, subenums = parse_schema_types(name, + schema['items'], + optional=False, + parents=parents + [name]) if type(typ) is tuple: typ = typ[0] - return (optionalize('Vec<' + typ + '>', optional), schema.get('description', '')), structs + substructs, subenums + return (optionalize('Vec<' + typ + '>', optional), schema.get('description', + '')), structs + substructs, subenums if schema['type'] == 'string': @@ -177,16 +182,17 @@ if 'enum' in schema and name: name_ = (sanitize_id(name)) + def sanitize_enum_value(v): if v[0].isnumeric(): - return '_'+v + return '_' + v return v[0].upper() + v[1:] values = [{ 'line': sanitize_enum_value(ev), 'jsonvalue': ev, - 'desc': schema.get('enumDescriptions', ['']*(i))[i]} - for (i, ev) in enumerate(schema.get('enum', []))] + 'desc': schema.get('enumDescriptions', [''] * (i))[i] + } for (i, ev) in enumerate(schema.get('enum', []))] templ_params = {'name': name_, 'values': values} print('Emitted enum', name_, 'with', len(values), 'fields') return (optionalize(name_, optional), schema.get('description', '')), structs, [templ_params] @@ -272,7 +278,8 @@ frags.append(chevron.render(SchemaDisplayTmpl, struct)) # Generate parameter types for subresources. frags.extend( - generate_params_structs(resource.get('resources', {}), super_name=super_name+'_'+resourcename, + generate_params_structs(resource.get('resources', {}), + super_name=super_name + '_' + resourcename, global_params=global_params)) return frags @@ -480,13 +487,15 @@ } for t in method_fragments] }) + '\n'.join(subresource_fragments) + def scopes_url_to_enum_val(apiname, url): split = url.split('/') rawname = split[-1] if len(rawname) == 0 and len(split) > 1: rawname = split[-2] fancy_name = snake_to_camel(rawname.replace('-', '_').replace('.', '_')) - return (snake_to_camel(apiname)+'Scopes', fancy_name) + return (snake_to_camel(apiname) + 'Scopes', fancy_name) + def generate_scopes_type(name, scopes): """Generate types for the `scopes` dictionary (path: auth.oauth2.scopes in a discovery document),