Skip to content

Commit d08b74d

Browse files
jason810496sanederchik
authored andcommitted
Fix OpenAPI schema for get_log API (apache#50547)
* Fix openapi schema for get_log API * Fix test_log
1 parent b408047 commit d08b74d

File tree

11 files changed

+52
-23
lines changed

11 files changed

+52
-23
lines changed

airflow-core/src/airflow/api_fastapi/common/headers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,30 @@ def header_accept_json_or_text_depends(
4747

4848

4949
HeaderAcceptJsonOrText = Annotated[Mimetype, Depends(header_accept_json_or_text_depends)]
50+
51+
52+
def header_accept_json_or_ndjson_depends(
53+
accept: Annotated[
54+
str,
55+
Header(
56+
json_schema_extra={
57+
"type": "string",
58+
"enum": [Mimetype.JSON, Mimetype.NDJSON, Mimetype.ANY],
59+
}
60+
),
61+
] = Mimetype.ANY,
62+
) -> Mimetype:
63+
if accept.startswith(Mimetype.ANY):
64+
return Mimetype.ANY
65+
if accept.startswith(Mimetype.JSON):
66+
return Mimetype.JSON
67+
if accept.startswith(Mimetype.NDJSON) or accept.startswith(Mimetype.ANY):
68+
return Mimetype.NDJSON
69+
70+
raise HTTPException(
71+
status_code=status.HTTP_406_NOT_ACCEPTABLE,
72+
detail="Only application/json or application/x-ndjson is supported",
73+
)
74+
75+
76+
HeaderAcceptJsonOrNdjson = Annotated[Mimetype, Depends(header_accept_json_or_ndjson_depends)]

airflow-core/src/airflow/api_fastapi/common/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Mimetype(str, Enum):
7272

7373
TEXT = "text/plain"
7474
JSON = "application/json"
75+
NDJSON = "application/x-ndjson"
7576
ANY = "*/*"
7677

7778

airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6495,7 +6495,7 @@ paths:
64956495
type: string
64966496
enum:
64976497
- application/json
6498-
- text/plain
6498+
- application/x-ndjson
64996499
- '*/*'
65006500
default: '*/*'
65016501
title: Accept
@@ -6506,10 +6506,12 @@ paths:
65066506
application/json:
65076507
schema:
65086508
$ref: '#/components/schemas/TaskInstancesLogResponse'
6509-
text/plain:
6509+
application/x-ndjson:
65106510
schema:
65116511
type: string
6512-
example: 'content
6512+
example: '{"content": "content"}
6513+
6514+
{"content": "content"}
65136515
65146516
'
65156517
'401':

airflow-core/src/airflow/api_fastapi/core_api/routes/public/log.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from airflow.api_fastapi.common.dagbag import DagBagDep
3030
from airflow.api_fastapi.common.db.common import SessionDep
31-
from airflow.api_fastapi.common.headers import HeaderAcceptJsonOrText
31+
from airflow.api_fastapi.common.headers import HeaderAcceptJsonOrNdjson
3232
from airflow.api_fastapi.common.router import AirflowRouter
3333
from airflow.api_fastapi.common.types import Mimetype
3434
from airflow.api_fastapi.core_api.datamodels.log import ExternalLogUrlResponse, TaskInstancesLogResponse
@@ -43,13 +43,14 @@
4343
tags=["Task Instance"], prefix="/dags/{dag_id}/dagRuns/{dag_run_id}/taskInstances"
4444
)
4545

46-
text_example_response_for_get_log = {
47-
Mimetype.TEXT: {
46+
ndjson_example_response_for_get_log = {
47+
Mimetype.NDJSON: {
4848
"schema": {
4949
"type": "string",
5050
"example": textwrap.dedent(
5151
"""\
52-
content
52+
{"content": "content"}
53+
{"content": "content"}
5354
"""
5455
),
5556
}
@@ -63,7 +64,7 @@
6364
**create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
6465
status.HTTP_200_OK: {
6566
"description": "Successful Response",
66-
"content": text_example_response_for_get_log,
67+
"content": ndjson_example_response_for_get_log,
6768
},
6869
},
6970
dependencies=[Depends(requires_access_dag("GET", DagAccessEntity.TASK_LOGS))],
@@ -75,7 +76,7 @@ def get_log(
7576
dag_run_id: str,
7677
task_id: str,
7778
try_number: PositiveInt,
78-
accept: HeaderAcceptJsonOrText,
79+
accept: HeaderAcceptJsonOrNdjson,
7980
request: Request,
8081
dag_bag: DagBagDep,
8182
session: SessionDep,

airflow-core/src/airflow/ui/openapi-gen/queries/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ export const UseTaskInstanceServiceGetLogKeyFn = (
12141214
token,
12151215
tryNumber,
12161216
}: {
1217-
accept?: "application/json" | "text/plain" | "*/*";
1217+
accept?: "application/json" | "*/*" | "application/x-ndjson";
12181218
dagId: string;
12191219
dagRunId: string;
12201220
fullContent?: boolean;

airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ export const ensureUseTaskInstanceServiceGetLogData = (
16651665
token,
16661666
tryNumber,
16671667
}: {
1668-
accept?: "application/json" | "text/plain" | "*/*";
1668+
accept?: "application/json" | "*/*" | "application/x-ndjson";
16691669
dagId: string;
16701670
dagRunId: string;
16711671
fullContent?: boolean;

airflow-core/src/airflow/ui/openapi-gen/queries/prefetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ export const prefetchUseTaskInstanceServiceGetLog = (
16651665
token,
16661666
tryNumber,
16671667
}: {
1668-
accept?: "application/json" | "text/plain" | "*/*";
1668+
accept?: "application/json" | "*/*" | "application/x-ndjson";
16691669
dagId: string;
16701670
dagRunId: string;
16711671
fullContent?: boolean;

airflow-core/src/airflow/ui/openapi-gen/queries/queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ export const useTaskInstanceServiceGetLog = <
19931993
token,
19941994
tryNumber,
19951995
}: {
1996-
accept?: "application/json" | "text/plain" | "*/*";
1996+
accept?: "application/json" | "*/*" | "application/x-ndjson";
19971997
dagId: string;
19981998
dagRunId: string;
19991999
fullContent?: boolean;

airflow-core/src/airflow/ui/openapi-gen/queries/suspense.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ export const useTaskInstanceServiceGetLogSuspense = <
19701970
token,
19711971
tryNumber,
19721972
}: {
1973-
accept?: "application/json" | "text/plain" | "*/*";
1973+
accept?: "application/json" | "*/*" | "application/x-ndjson";
19741974
dagId: string;
19751975
dagRunId: string;
19761976
fullContent?: boolean;

airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ export type PatchTaskInstanceDryRunData = {
24642464
export type PatchTaskInstanceDryRunResponse = TaskInstanceCollectionResponse;
24652465

24662466
export type GetLogData = {
2467-
accept?: "application/json" | "text/plain" | "*/*";
2467+
accept?: "application/json" | "application/x-ndjson" | "*/*";
24682468
dagId: string;
24692469
dagRunId: string;
24702470
fullContent?: boolean;

0 commit comments

Comments
 (0)