def _register_responses(self): """Register default responses for all status codes""" # Register a response for each status code for status in http.HTTPStatus: response = { 'description': status.phrase, 'schema': self.ERROR_SCHEMA, } prepare_response(response, self.spec, DEFAULT_RESPONSE_CONTENT_TYPE) self.spec.components.response(status.name, response) # Also register a default error response response = { 'description': 'Default error response', 'schema': self.ERROR_SCHEMA, } prepare_response(response, self.spec, DEFAULT_RESPONSE_CONTENT_TYPE) self.spec.components.response('DEFAULT_ERROR', response)
def _register_responses(self): """Lazyly register default responses for all status codes""" # Lazy register a response for each status code for status in http.HTTPStatus: response = { "description": status.phrase, } if not (100 <= status < 200) and status not in (204, 304): response["schema"] = self.ERROR_SCHEMA prepare_response(response, self.spec, self.DEFAULT_RESPONSE_CONTENT_TYPE) self.spec.components.response(status.name, response, lazy=True) # Also lazy register a default error response response = { "description": "Default error response", "schema": self.ERROR_SCHEMA, } prepare_response(response, self.spec, self.DEFAULT_RESPONSE_CONTENT_TYPE) self.spec.components.response("DEFAULT_ERROR", response, lazy=True)
def operation_helper(self, operations=None, **kwargs): """Inspired by MarshmallowPlugin.operation_helper Looking for `str` responses, adding the corresponding spec responses. `APISpec.clean_operations` will add a $ref for any response that is not a `dict`, it's this plugin's role to ensure that $ref exists. """ for operation in (operations or {}).values(): if not isinstance(operation, dict): continue for response in operation.get("responses", {}).values(): if ( isinstance(response, str) and response not in self._registered and response in self._available ): resp = self._available[response] prepare_response(resp, self.spec, self.content_type) self.spec.components.response(response, resp) self._registered.add(response)