Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions apps/knowledge/api/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ def get_parameters():
location='path',
required=True,
),

OpenApiParameter(
name="limit",
description="分段长度",
type=OpenApiTypes.INT,
location='query',
required=False,
),
OpenApiParameter(
name="patterns",
description="分段正则列表",
type=OpenApiTypes.STR,
location='query',
required=False,
),
OpenApiParameter(
name="with_filter",
description="是否清除特殊字符",
type=OpenApiTypes.BOOL,
location='query',
required=False,
),
]

@staticmethod
Expand All @@ -53,6 +31,18 @@ def get_request():
'file': {
'type': 'string',
'format': 'binary' # Tells Swagger it's a file
},
'limit': {
'type': 'integer',
'description': '分段长度'
},
'patterns': {
'type': 'string',
'description': '分段正则列表'
},
'with_filter': {
'type': 'boolean',
'description': '是否清除特殊字符'
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The given Python function appears to be setting up API parameters using Django Rest Framework (DRF). Here are some points of concern and recommendations:

  1. Django vs FastAPI:

    • The example uses djangorestframework for defining parameters, but you're likely working with FastAPI if you see similar code structures. If this is indeed DRF, please note that DRF has its own way of handling query parameters.
  2. Parameter Naming:

    • The parameter names (limit, patterns, with_filter) are consistent across both functions, which is good unless there are specific naming conventions in place.
  3. Type Definitions:

    • All types are correctly defined, such as INT for integers and BOOL for booleans. Ensure consistency in the usage of these types.
  4. Documentation and Descriptions:

    • Each parameter has a description provided in Swagger format within the operation.get_request() method. This is excellent practice for clarity and maintainability.
  5. Location Parameters:

    • The location (location='query') is correct according to the requirements. However, ensure that other parameters also follow this pattern consistently if you have other methods like POST requests where different locations might be appropriate.
  6. Binary File Handling:

    • The addition of 'file': {'type': 'string', 'format': 'binary'}
      in get_request() suggests handling files or binary data. Make sure this line fits into your design and does not conflict with existing logic.
  7. Optimization Suggestions:

    • There doesn’t appear to be significant opportunities for optimization in the current implementation. Ensure that all fields are necessary and perform efficiently within their contexts.
    • Consider adding more thorough validation on certain inputs, particularly if they interact with sensitive operations.

Overall, the code looks well-structured and should work effectively once integrated into an API setup. Make sure to adjust it accordingly based on whether you’re using Django REST Framework or FastAPI.

Expand Down
Loading