prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Change Configs detail API GET/PATCH for a more structured response
  The API endpoints for GET, PATCH /api/v1/configs/{config_key} return badly structured data. This should return better structured data. 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `CTFd/api/v1/config.py`
  Content:
  ```
  1 from typing import List
  2 
  3 from flask import request
  4 from flask_restx import Namespace, Resource
  5 
  6 from CTFd.api.v1.helpers.models import build_model_filters
  7 from CTFd.api.v1.helpers.request import validate_args
  8 from CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic
  9 from CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse
  10 from CTFd.cache import clear_config, clear_standings
  11 from CTFd.constants import RawEnum
  12 from CTFd.models import Configs, db
  13 from CTFd.schemas.config import ConfigSchema
  14 from CTFd.utils import get_config, set_config
  15 from CTFd.utils.decorators import admins_only
  16 
  17 configs_namespace = Namespace("configs", description="Endpoint to retrieve Configs")
  18 
  19 ConfigModel = sqlalchemy_to_pydantic(Configs)
  20 
  21 
  22 class ConfigDetailedSuccessResponse(APIDetailedSuccessResponse):
  23     data: ConfigModel
  24 
  25 
  26 class ConfigListSuccessResponse(APIListSuccessResponse):
  27     data: List[ConfigModel]
  28 
  29 
  30 configs_namespace.schema_model(
  31     "ConfigDetailedSuccessResponse", ConfigDetailedSuccessResponse.apidoc()
  32 )
  33 
  34 configs_namespace.schema_model(
  35     "ConfigListSuccessResponse", ConfigListSuccessResponse.apidoc()
  36 )
  37 
  38 
  39 @configs_namespace.route("")
  40 class ConfigList(Resource):
  41     @admins_only
  42     @configs_namespace.doc(
  43         description="Endpoint to get Config objects in bulk",
  44         responses={
  45             200: ("Success", "ConfigListSuccessResponse"),
  46             400: (
  47                 "An error occured processing the provided or stored data",
  48                 "APISimpleErrorResponse",
  49             ),
  50         },
  51     )
  52     @validate_args(
  53         {
  54             "key": (str, None),
  55             "value": (str, None),
  56             "q": (str, None),
  57             "field": (RawEnum("ConfigFields", {"key": "key", "value": "value"}), None),
  58         },
  59         location="query",
  60     )
  61     def get(self, query_args):
  62         q = query_args.pop("q", None)
  63         field = str(query_args.pop("field", None))
  64         filters = build_model_filters(model=Configs, query=q, field=field)
  65 
  66         configs = Configs.query.filter_by(**query_args).filter(*filters).all()
  67         schema = ConfigSchema(many=True)
  68         response = schema.dump(configs)
  69         if response.errors:
  70             return {"success": False, "errors": response.errors}, 400
  71 
  72         return {"success": True, "data": response.data}
  73 
  74     @admins_only
  75     @configs_namespace.doc(
  76         description="Endpoint to get create a Config object",
  77         responses={
  78             200: ("Success", "ConfigDetailedSuccessResponse"),
  79             400: (
  80                 "An error occured processing the provided or stored data",
  81                 "APISimpleErrorResponse",
  82             ),
  83         },
  84     )
  85     def post(self):
  86         req = request.get_json()
  87         schema = ConfigSchema()
  88         response = schema.load(req)
  89 
  90         if response.errors:
  91             return {"success": False, "errors": response.errors}, 400
  92 
  93         db.session.add(response.data)
  94         db.session.commit()
  95 
  96         response = schema.dump(response.data)
  97         db.session.close()
  98 
  99         clear_config()
  100         clear_standings()
  101 
  102         return {"success": True, "data": response.data}
  103 
  104     @admins_only
  105     @configs_namespace.doc(
  106         description="Endpoint to get patch Config objects in bulk",
  107         responses={200: ("Success", "APISimpleSuccessResponse")},
  108     )
  109     def patch(self):
  110         req = request.get_json()
  111 
  112         for key, value in req.items():
  113             set_config(key=key, value=value)
  114 
  115         clear_config()
  116         clear_standings()
  117 
  118         return {"success": True}
  119 
  120 
  121 @configs_namespace.route("/<config_key>")
  122 class Config(Resource):
  123     @admins_only
  124     # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
  125     def get(self, config_key):
  126 
  127         return {"success": True, "data": get_config(config_key)}
  128 
  129     @admins_only
  130     # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
  131     def patch(self, config_key):
  132         config = Configs.query.filter_by(key=config_key).first()
  133         data = request.get_json()
  134         if config:
  135             schema = ConfigSchema(instance=config, partial=True)
  136             response = schema.load(data)
  137         else:
  138             schema = ConfigSchema()
  139             data["key"] = config_key
  140             response = schema.load(data)
  141             db.session.add(response.data)
  142 
  143         if response.errors:
  144             return response.errors, 400
  145 
  146         db.session.commit()
  147 
  148         response = schema.dump(response.data)
  149         db.session.close()
  150 
  151         clear_config()
  152         clear_standings()
  153 
  154         return {"success": True, "data": response.data}
  155 
  156     @admins_only
  157     @configs_namespace.doc(
  158         description="Endpoint to delete a Config object",
  159         responses={200: ("Success", "APISimpleSuccessResponse")},
  160     )
  161     def delete(self, config_key):
  162         config = Configs.query.filter_by(key=config_key).first_or_404()
  163 
  164         db.session.delete(config)
  165         db.session.commit()
  166         db.session.close()
  167 
  168         clear_config()
  169         clear_standings()
  170 
  171         return {"success": True}
  172
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/CTFd/api/v1/config.py b/CTFd/api/v1/config.py
  --- a/CTFd/api/v1/config.py
  +++ b/CTFd/api/v1/config.py
  @@ -11,7 +11,7 @@
   from CTFd.constants import RawEnum
   from CTFd.models import Configs, db
   from CTFd.schemas.config import ConfigSchema
  -from CTFd.utils import get_config, set_config
  +from CTFd.utils import set_config
   from CTFd.utils.decorators import admins_only
   
   configs_namespace = Namespace("configs", description="Endpoint to retrieve Configs")
  @@ -121,13 +121,33 @@
   @configs_namespace.route("/<config_key>")
   class Config(Resource):
       @admins_only
  -    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
  +    @configs_namespace.doc(
  +        description="Endpoint to get a specific Config object",
  +        responses={
  +            200: ("Success", "ConfigDetailedSuccessResponse"),
  +            400: (
  +                "An error occured processing the provided or stored data",
  +                "APISimpleErrorResponse",
  +            ),
  +        },
  +    )
       def get(self, config_key):
  -
  -        return {"success": True, "data": get_config(config_key)}
  +        config = Configs.query.filter_by(key=config_key).first_or_404()
  +        schema = ConfigSchema()
  +        response = schema.dump(config)
  +        return {"success": True, "data": response.data}
   
       @admins_only
  -    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
  +    @configs_namespace.doc(
  +        description="Endpoint to edit a specific Config object",
  +        responses={
  +            200: ("Success", "ConfigDetailedSuccessResponse"),
  +            400: (
  +                "An error occured processing the provided or stored data",
  +                "APISimpleErrorResponse",
  +            ),
  +        },
  +    )
       def patch(self, config_key):
           config = Configs.query.filter_by(key=config_key).first()
           data = request.get_json()
  
verification_info: {"golden_diff": "diff --git a/CTFd/api/v1/config.py b/CTFd/api/v1/config.py\n--- a/CTFd/api/v1/config.py\n+++ b/CTFd/api/v1/config.py\n@@ -11,7 +11,7 @@\n from CTFd.constants import RawEnum\n from CTFd.models import Configs, db\n from CTFd.schemas.config import ConfigSchema\n-from CTFd.utils import get_config, set_config\n+from CTFd.utils import set_config\n from CTFd.utils.decorators import admins_only\n \n configs_namespace = Namespace(\"configs\", description=\"Endpoint to retrieve Configs\")\n@@ -121,13 +121,33 @@\n @configs_namespace.route(\"/<config_key>\")\n class Config(Resource):\n     @admins_only\n-    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506\n+    @configs_namespace.doc(\n+        description=\"Endpoint to get a specific Config object\",\n+        responses={\n+            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n+            400: (\n+                \"An error occured processing the provided or stored data\",\n+                \"APISimpleErrorResponse\",\n+            ),\n+        },\n+    )\n     def get(self, config_key):\n-\n-        return {\"success\": True, \"data\": get_config(config_key)}\n+        config = Configs.query.filter_by(key=config_key).first_or_404()\n+        schema = ConfigSchema()\n+        response = schema.dump(config)\n+        return {\"success\": True, \"data\": response.data}\n \n     @admins_only\n-    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506\n+    @configs_namespace.doc(\n+        description=\"Endpoint to edit a specific Config object\",\n+        responses={\n+            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n+            400: (\n+                \"An error occured processing the provided or stored data\",\n+                \"APISimpleErrorResponse\",\n+            ),\n+        },\n+    )\n     def patch(self, config_key):\n         config = Configs.query.filter_by(key=config_key).first()\n         data = request.get_json()\n", "issue": "Change Configs detail API GET/PATCH for a more structured response\nThe API endpoints for GET, PATCH /api/v1/configs/{config_key} return badly structured data. This should return better structured data. \n", "before_files": [{"content": "from typing import List\n\nfrom flask import request\nfrom flask_restx import Namespace, Resource\n\nfrom CTFd.api.v1.helpers.models import build_model_filters\nfrom CTFd.api.v1.helpers.request import validate_args\nfrom CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic\nfrom CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse\nfrom CTFd.cache import clear_config, clear_standings\nfrom CTFd.constants import RawEnum\nfrom CTFd.models import Configs, db\nfrom CTFd.schemas.config import ConfigSchema\nfrom CTFd.utils import get_config, set_config\nfrom CTFd.utils.decorators import admins_only\n\nconfigs_namespace = Namespace(\"configs\", description=\"Endpoint to retrieve Configs\")\n\nConfigModel = sqlalchemy_to_pydantic(Configs)\n\n\nclass ConfigDetailedSuccessResponse(APIDetailedSuccessResponse):\n    data: ConfigModel\n\n\nclass ConfigListSuccessResponse(APIListSuccessResponse):\n    data: List[ConfigModel]\n\n\nconfigs_namespace.schema_model(\n    \"ConfigDetailedSuccessResponse\", ConfigDetailedSuccessResponse.apidoc()\n)\n\nconfigs_namespace.schema_model(\n    \"ConfigListSuccessResponse\", ConfigListSuccessResponse.apidoc()\n)\n\n\n@configs_namespace.route(\"\")\nclass ConfigList(Resource):\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get Config objects in bulk\",\n        responses={\n            200: (\"Success\", \"ConfigListSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    @validate_args(\n        {\n            \"key\": (str, None),\n            \"value\": (str, None),\n            \"q\": (str, None),\n            \"field\": (RawEnum(\"ConfigFields\", {\"key\": \"key\", \"value\": \"value\"}), None),\n        },\n        location=\"query\",\n    )\n    def get(self, query_args):\n        q = query_args.pop(\"q\", None)\n        field = str(query_args.pop(\"field\", None))\n        filters = build_model_filters(model=Configs, query=q, field=field)\n\n        configs = Configs.query.filter_by(**query_args).filter(*filters).all()\n        schema = ConfigSchema(many=True)\n        response = schema.dump(configs)\n        if response.errors:\n            return {\"success\": False, \"errors\": response.errors}, 400\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get create a Config object\",\n        responses={\n            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    def post(self):\n        req = request.get_json()\n        schema = ConfigSchema()\n        response = schema.load(req)\n\n        if response.errors:\n            return {\"success\": False, \"errors\": response.errors}, 400\n\n        db.session.add(response.data)\n        db.session.commit()\n\n        response = schema.dump(response.data)\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get patch Config objects in bulk\",\n        responses={200: (\"Success\", \"APISimpleSuccessResponse\")},\n    )\n    def patch(self):\n        req = request.get_json()\n\n        for key, value in req.items():\n            set_config(key=key, value=value)\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True}\n\n\n@configs_namespace.route(\"/<config_key>\")\nclass Config(Resource):\n    @admins_only\n    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506\n    def get(self, config_key):\n\n        return {\"success\": True, \"data\": get_config(config_key)}\n\n    @admins_only\n    # TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506\n    def patch(self, config_key):\n        config = Configs.query.filter_by(key=config_key).first()\n        data = request.get_json()\n        if config:\n            schema = ConfigSchema(instance=config, partial=True)\n            response = schema.load(data)\n        else:\n            schema = ConfigSchema()\n            data[\"key\"] = config_key\n            response = schema.load(data)\n            db.session.add(response.data)\n\n        if response.errors:\n            return response.errors, 400\n\n        db.session.commit()\n\n        response = schema.dump(response.data)\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to delete a Config object\",\n        responses={200: (\"Success\", \"APISimpleSuccessResponse\")},\n    )\n    def delete(self, config_key):\n        config = Configs.query.filter_by(key=config_key).first_or_404()\n\n        db.session.delete(config)\n        db.session.commit()\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True}\n", "path": "CTFd/api/v1/config.py"}], "after_files": [{"content": "from typing import List\n\nfrom flask import request\nfrom flask_restx import Namespace, Resource\n\nfrom CTFd.api.v1.helpers.models import build_model_filters\nfrom CTFd.api.v1.helpers.request import validate_args\nfrom CTFd.api.v1.helpers.schemas import sqlalchemy_to_pydantic\nfrom CTFd.api.v1.schemas import APIDetailedSuccessResponse, APIListSuccessResponse\nfrom CTFd.cache import clear_config, clear_standings\nfrom CTFd.constants import RawEnum\nfrom CTFd.models import Configs, db\nfrom CTFd.schemas.config import ConfigSchema\nfrom CTFd.utils import set_config\nfrom CTFd.utils.decorators import admins_only\n\nconfigs_namespace = Namespace(\"configs\", description=\"Endpoint to retrieve Configs\")\n\nConfigModel = sqlalchemy_to_pydantic(Configs)\n\n\nclass ConfigDetailedSuccessResponse(APIDetailedSuccessResponse):\n    data: ConfigModel\n\n\nclass ConfigListSuccessResponse(APIListSuccessResponse):\n    data: List[ConfigModel]\n\n\nconfigs_namespace.schema_model(\n    \"ConfigDetailedSuccessResponse\", ConfigDetailedSuccessResponse.apidoc()\n)\n\nconfigs_namespace.schema_model(\n    \"ConfigListSuccessResponse\", ConfigListSuccessResponse.apidoc()\n)\n\n\n@configs_namespace.route(\"\")\nclass ConfigList(Resource):\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get Config objects in bulk\",\n        responses={\n            200: (\"Success\", \"ConfigListSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    @validate_args(\n        {\n            \"key\": (str, None),\n            \"value\": (str, None),\n            \"q\": (str, None),\n            \"field\": (RawEnum(\"ConfigFields\", {\"key\": \"key\", \"value\": \"value\"}), None),\n        },\n        location=\"query\",\n    )\n    def get(self, query_args):\n        q = query_args.pop(\"q\", None)\n        field = str(query_args.pop(\"field\", None))\n        filters = build_model_filters(model=Configs, query=q, field=field)\n\n        configs = Configs.query.filter_by(**query_args).filter(*filters).all()\n        schema = ConfigSchema(many=True)\n        response = schema.dump(configs)\n        if response.errors:\n            return {\"success\": False, \"errors\": response.errors}, 400\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get create a Config object\",\n        responses={\n            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    def post(self):\n        req = request.get_json()\n        schema = ConfigSchema()\n        response = schema.load(req)\n\n        if response.errors:\n            return {\"success\": False, \"errors\": response.errors}, 400\n\n        db.session.add(response.data)\n        db.session.commit()\n\n        response = schema.dump(response.data)\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get patch Config objects in bulk\",\n        responses={200: (\"Success\", \"APISimpleSuccessResponse\")},\n    )\n    def patch(self):\n        req = request.get_json()\n\n        for key, value in req.items():\n            set_config(key=key, value=value)\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True}\n\n\n@configs_namespace.route(\"/<config_key>\")\nclass Config(Resource):\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to get a specific Config object\",\n        responses={\n            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    def get(self, config_key):\n        config = Configs.query.filter_by(key=config_key).first_or_404()\n        schema = ConfigSchema()\n        response = schema.dump(config)\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to edit a specific Config object\",\n        responses={\n            200: (\"Success\", \"ConfigDetailedSuccessResponse\"),\n            400: (\n                \"An error occured processing the provided or stored data\",\n                \"APISimpleErrorResponse\",\n            ),\n        },\n    )\n    def patch(self, config_key):\n        config = Configs.query.filter_by(key=config_key).first()\n        data = request.get_json()\n        if config:\n            schema = ConfigSchema(instance=config, partial=True)\n            response = schema.load(data)\n        else:\n            schema = ConfigSchema()\n            data[\"key\"] = config_key\n            response = schema.load(data)\n            db.session.add(response.data)\n\n        if response.errors:\n            return response.errors, 400\n\n        db.session.commit()\n\n        response = schema.dump(response.data)\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True, \"data\": response.data}\n\n    @admins_only\n    @configs_namespace.doc(\n        description=\"Endpoint to delete a Config object\",\n        responses={200: (\"Success\", \"APISimpleSuccessResponse\")},\n    )\n    def delete(self, config_key):\n        config = Configs.query.filter_by(key=config_key).first_or_404()\n\n        db.session.delete(config)\n        db.session.commit()\n        db.session.close()\n\n        clear_config()\n        clear_standings()\n\n        return {\"success\": True}\n", "path": "CTFd/api/v1/config.py"}]}