def lint_plural_resource_names(spec, resolver):
"""
Must: Pluralize Resource Names
https://zalando.github.io/restful-api-guidelines/naming/Naming.html#must-pluralize-resource-names
"""
inflect_engine = inflect.engine()
for path_name, methods_available in spec.get('paths', {}).items():
path_name_without_variables = re.sub('{[^}]*}', '', path_name)
for segment in path_name_without_variables.split('/'):
if segment != '.well-known':
resource = ' '.join(segment.split('-'))
if resource:
singular = inflect_engine.singular_noun(resource)
plural = inflect_engine.plural_noun(resource)
if singular == resource or (not singular and plural and plural != resource):
yield 'paths/"{}"'.format(path_name), '"{}" is not in plural form'.format(resource)
评论列表
文章目录