Incorrect handling of Union types
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu với các entry point APISpec và MarshmallowPlugin trong bản tái hiện, tập trung vào cách MainSchema.Schema() được chuyển đổi cho trường items có kiểu Union. Chạy ví dụ Python được cung cấp và bổ sung coverage cho cả list[Food | Drink] và Food | Drink; được xem là hoàn tất khi schema OpenAPI được tạo biểu diễn các lựa chọn thay thế thay vì để items trống.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
It seems that the API spec is not properly generated when using Union typehints.
The below snippet is on python 3.10 and 3.11
from typing import Literal
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from marshmallow_dataclass import dataclass
class BaseItemMixin:
name: str
@dataclass
class BaseItem(BaseItemMixin):
pass
@dataclass
class Food(BaseItem):
label: str
name: Literal["food"] = "food"
@dataclass
class Drink(BaseItem):
size: int
name: Literal["drink"] = "drink"
@dataclass
class MainSchema:
id: int
name: str
items: list[Food | Drink]
spec = APISpec(
title="API",
version="1.0.0",
openapi_version="3.0.2",
plugins=[(MarshmallowPlugin())],
)
spec.path(
"/endpoint",
operations={
"post": {
"parameters": [
{
"name": "Args",
"schema": MainSchema.Schema(),
"in": "body",
}
],
"responses": {
"200": {
"content": {"application/json": {}},
"description": "OK",
},
},
}
},
)
if __name__ == "__main__":
print(spec.to_yaml())
The outputted yaml contains the schema for Main as:
components:
schemas:
Main:
type: object
properties:
name:
type: string
id:
type: integer
items:
type: array
items: {}
required:
- id
- items
- name
Items is correctly marked as an array, but the items is not correct. I'd expect oneOf being used here (although i'm not 100%).
The same happens using item: Food | Drink.
I believe the issue is within this library, and not marshmallow_dataclass, as i'm able to deserialise serialise with the schemas without issue
data = MainSchema(
id=1,
name="test",
items=[
Food(name="food", label="test"),
Drink(name="drink", size=1),
],
)
data_as_dict = MainSchema.Schema().dumps(data)
loaded_data = MainSchema.Schema().loads(data_as_dict)
print("original", data)
print("deserialised", loaded_data)
print("serialised", data_as_dict)
# original MainSchema(id=1, name='test', items=[Food(label='test', name='food'), Drink(size=1, name='drink')])
# deserialised MainSchema(id=1, name='test', items=[Food(label='test', name='food'), Drink(size=1, name='drink')])
# serialised {"id": 1, "items": [{"label": "test", "name": "food"}, {"size": 1, "name": "drink"}], "name": "test"}
Note: I've also tried without the inheritance involved, and the result is the same.
- Ngôn ngữ chính
- Python
- Star
- 1.2k
- Fork
- 211
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của marshmallow-code/apispec
-
DateTime(format="timestamp") generates invalid OpenAPI schema using min instead of minimumCó thể đã có người làm @Sanjays2402 đã nhận 107 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
marshmallow-code/apispec#1064 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
marshmallow-code/apispec#750 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Dependency DashboardĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 30/100
marshmallow-code/apispec#1033 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`apispec` ignores `oneOf` from `marshmallow-oneofschema`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
marshmallow-code/apispec#1012 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support Overlays standardĐang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
marshmallow-code/apispec#981 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của marshmallow-code/apispec
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Netcracker/qubership-ai-packages#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
PROCESSED_DATA_FOLDER: strip whitespace and treat empty as unsetCó thể đã có người làm @TorecLuik đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
NL-BioImaging/BIOMERO.importer#63 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
MLX training-complete chat/merge suggestions omit --backend mlxCó thể đã có người làm @vaputa đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
MakazhanAlpamys/Soup#2913 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:security effort:S priority:P3 status:needs-triage type:chore
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
randomparity/kdive#3657 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aws/mcp-proxy-for-aws#476 ·
Maintainer thường phản hồi trong vòng 1 ngày