Skip to content

Commit

Permalink
use 412 Precondition Failed instead of 409 conflict when If-Match fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Nally committed May 25, 2017
1 parent e46be67 commit 806ca4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions util/gen_openapispec.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,11 @@ def build_put_patch_responses(self):
'403': self.global_response_ref('403'),
'404': self.global_response_ref('404'),
'406': self.global_response_ref('406'),
'409': self.global_response_ref('409'),
'default': self.global_response_ref('default')
}
if self.use_etag:
rslt['409'] = self.global_response_ref('409')
rslt['412'] = self.global_response_ref('412')
return rslt

def build_delete_responses(self):
Expand All @@ -517,6 +518,7 @@ def build_post_responses(self):
'403': self.global_response_ref('403'),
'404': self.global_response_ref('404'),
'406': self.global_response_ref('406'),
'409': self.global_response_ref('409'),
'default': self.global_response_ref('default')
}

Expand Down Expand Up @@ -666,14 +668,18 @@ def build_standard_responses(self):
'description': 'Not Acceptable. Requested media type not available',
'schema': self.error_response if self.yaml_merge else self.error_response.copy()
},
'409': {
'description': 'Conflict. May be a duplicate',
'schema': self.error_response if self.yaml_merge else self.error_response.copy()
},
'default': {
'description': '5xx errors and other stuff',
'schema': self.error_response if self.yaml_merge else self.error_response.copy()
}
}
if self.use_etag:
rslt['409'] = \
{'description': 'Conflict. Value provided in If-Match header does not match current ETag value of resource',
rslt['412'] = \
{'description': 'Precondition Failed. Value provided in If-Match header does not match current ETag value of resource',
'schema': self.error_response if self.yaml_merge else self.error_response.copy()
}
return rslt
Expand Down
4 changes: 3 additions & 1 deletion util/validate_rapier.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ def validate_property_relationship(self, node, key, relationship):
if node.get('format') != 'uri':
self.error('relationship properties must have "format: uri"', key)
if hasattr(relationship, 'keys'):
if relationship.get('entities') is None:
self.error('relationship must have property "entities"', key)
self.check_and_validate_keywords(self.__class__.relationship_keywords, relationship, key)
elif isinstance(relationship, basestring):
self.validate_relationship_entities(node, key, relationship)
Expand All @@ -299,7 +301,7 @@ def validate_relationship_entities(self, node, key, entities):

def validate_relationship_multiplicity(self, node, key, multiplicity):
if not isinstance(multiplicity, basestring):
self.error('relationship multiplicity mut be a string %s' %s, key)
self.error('relationship multiplicity mut be a string %s' % multiplicity, key)
else:
parts = multiplicity.split(':')
if len(parts) == 1:
Expand Down

0 comments on commit 806ca4e

Please sign in to comment.