Skip to content

Commit 3208bbb

Browse files
Fix bulk action annotation (#50852)
* Fix bulk api annotation * Small improvement --------- Co-authored-by: pierrejeambrun <[email protected]>
1 parent 3b78c6a commit 3208bbb

File tree

6 files changed

+99
-73
lines changed

6 files changed

+99
-73
lines changed

airflow-core/src/airflow/api_fastapi/core_api/datamodels/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from __future__ import annotations
2424

2525
import enum
26-
from typing import Annotated, Any, Generic, TypeVar, Union
26+
from typing import Annotated, Any, Generic, Literal, TypeVar, Union
2727

2828
from pydantic import Discriminator, Field, Tag
2929

@@ -34,7 +34,7 @@
3434
K = TypeVar("K")
3535

3636

37-
class BulkAction(enum.Enum):
37+
class BulkAction(str, enum.Enum):
3838
"""Bulk Action to be performed on the used model."""
3939

4040
CREATE = "create"
@@ -66,20 +66,23 @@ class BulkBaseAction(StrictBaseModel, Generic[T]):
6666
class BulkCreateAction(BulkBaseAction[T]):
6767
"""Bulk Create entity serializer for request bodies."""
6868

69+
action: Literal[BulkAction.CREATE] = Field(description="The action to be performed on the entities.")
6970
entities: list[T] = Field(..., description="A list of entities to be created.")
7071
action_on_existence: BulkActionOnExistence = BulkActionOnExistence.FAIL
7172

7273

7374
class BulkUpdateAction(BulkBaseAction[T]):
7475
"""Bulk Update entity serializer for request bodies."""
7576

77+
action: Literal[BulkAction.UPDATE] = Field(description="The action to be performed on the entities.")
7678
entities: list[T] = Field(..., description="A list of entities to be updated.")
7779
action_on_non_existence: BulkActionNotOnExistence = BulkActionNotOnExistence.FAIL
7880

7981

8082
class BulkDeleteAction(BulkBaseAction[T]):
8183
"""Bulk Delete entity serializer for request bodies."""
8284

85+
action: Literal[BulkAction.DELETE] = Field(description="The action to be performed on the entities.")
8386
entities: list[str] = Field(..., description="A list of entity id/key to be deleted.")
8487
action_on_non_existence: BulkActionNotOnExistence = BulkActionNotOnExistence.FAIL
8588

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7344,14 +7344,6 @@ components:
73447344
- status
73457345
title: BaseInfoResponse
73467346
description: Base info serializer for responses.
7347-
BulkAction:
7348-
type: string
7349-
enum:
7350-
- create
7351-
- delete
7352-
- update
7353-
title: BulkAction
7354-
description: Bulk Action to be performed on the used model.
73557347
BulkActionNotOnExistence:
73567348
type: string
73577349
enum:
@@ -7445,7 +7437,9 @@ components:
74457437
BulkCreateAction_ConnectionBody_:
74467438
properties:
74477439
action:
7448-
$ref: '#/components/schemas/BulkAction'
7440+
type: string
7441+
const: create
7442+
title: Action
74497443
description: The action to be performed on the entities.
74507444
entities:
74517445
items:
@@ -7465,7 +7459,9 @@ components:
74657459
BulkCreateAction_PoolBody_:
74667460
properties:
74677461
action:
7468-
$ref: '#/components/schemas/BulkAction'
7462+
type: string
7463+
const: create
7464+
title: Action
74697465
description: The action to be performed on the entities.
74707466
entities:
74717467
items:
@@ -7485,7 +7481,9 @@ components:
74857481
BulkCreateAction_VariableBody_:
74867482
properties:
74877483
action:
7488-
$ref: '#/components/schemas/BulkAction'
7484+
type: string
7485+
const: create
7486+
title: Action
74897487
description: The action to be performed on the entities.
74907488
entities:
74917489
items:
@@ -7505,7 +7503,9 @@ components:
75057503
BulkDeleteAction_ConnectionBody_:
75067504
properties:
75077505
action:
7508-
$ref: '#/components/schemas/BulkAction'
7506+
type: string
7507+
const: delete
7508+
title: Action
75097509
description: The action to be performed on the entities.
75107510
entities:
75117511
items:
@@ -7525,7 +7525,9 @@ components:
75257525
BulkDeleteAction_PoolBody_:
75267526
properties:
75277527
action:
7528-
$ref: '#/components/schemas/BulkAction'
7528+
type: string
7529+
const: delete
7530+
title: Action
75297531
description: The action to be performed on the entities.
75307532
entities:
75317533
items:
@@ -7545,7 +7547,9 @@ components:
75457547
BulkDeleteAction_VariableBody_:
75467548
properties:
75477549
action:
7548-
$ref: '#/components/schemas/BulkAction'
7550+
type: string
7551+
const: delete
7552+
title: Action
75497553
description: The action to be performed on the entities.
75507554
entities:
75517555
items:
@@ -7598,7 +7602,9 @@ components:
75987602
BulkUpdateAction_ConnectionBody_:
75997603
properties:
76007604
action:
7601-
$ref: '#/components/schemas/BulkAction'
7605+
type: string
7606+
const: update
7607+
title: Action
76027608
description: The action to be performed on the entities.
76037609
entities:
76047610
items:
@@ -7618,7 +7624,9 @@ components:
76187624
BulkUpdateAction_PoolBody_:
76197625
properties:
76207626
action:
7621-
$ref: '#/components/schemas/BulkAction'
7627+
type: string
7628+
const: update
7629+
title: Action
76227630
description: The action to be performed on the entities.
76237631
entities:
76247632
items:
@@ -7638,7 +7646,9 @@ components:
76387646
BulkUpdateAction_VariableBody_:
76397647
properties:
76407648
action:
7641-
$ref: '#/components/schemas/BulkAction'
7649+
type: string
7650+
const: update
7651+
title: Action
76427652
description: The action to be performed on the entities.
76437653
entities:
76447654
items:

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,6 @@ export const $BaseInfoResponse = {
536536
description: "Base info serializer for responses.",
537537
} as const;
538538

539-
export const $BulkAction = {
540-
type: "string",
541-
enum: ["create", "delete", "update"],
542-
title: "BulkAction",
543-
description: "Bulk Action to be performed on the used model.",
544-
} as const;
545-
546539
export const $BulkActionNotOnExistence = {
547540
type: "string",
548541
enum: ["fail", "skip"],
@@ -670,7 +663,9 @@ export const $BulkBody_VariableBody_ = {
670663
export const $BulkCreateAction_ConnectionBody_ = {
671664
properties: {
672665
action: {
673-
$ref: "#/components/schemas/BulkAction",
666+
type: "string",
667+
const: "create",
668+
title: "Action",
674669
description: "The action to be performed on the entities.",
675670
},
676671
entities: {
@@ -695,7 +690,9 @@ export const $BulkCreateAction_ConnectionBody_ = {
695690
export const $BulkCreateAction_PoolBody_ = {
696691
properties: {
697692
action: {
698-
$ref: "#/components/schemas/BulkAction",
693+
type: "string",
694+
const: "create",
695+
title: "Action",
699696
description: "The action to be performed on the entities.",
700697
},
701698
entities: {
@@ -720,7 +717,9 @@ export const $BulkCreateAction_PoolBody_ = {
720717
export const $BulkCreateAction_VariableBody_ = {
721718
properties: {
722719
action: {
723-
$ref: "#/components/schemas/BulkAction",
720+
type: "string",
721+
const: "create",
722+
title: "Action",
724723
description: "The action to be performed on the entities.",
725724
},
726725
entities: {
@@ -745,7 +744,9 @@ export const $BulkCreateAction_VariableBody_ = {
745744
export const $BulkDeleteAction_ConnectionBody_ = {
746745
properties: {
747746
action: {
748-
$ref: "#/components/schemas/BulkAction",
747+
type: "string",
748+
const: "delete",
749+
title: "Action",
749750
description: "The action to be performed on the entities.",
750751
},
751752
entities: {
@@ -770,7 +771,9 @@ export const $BulkDeleteAction_ConnectionBody_ = {
770771
export const $BulkDeleteAction_PoolBody_ = {
771772
properties: {
772773
action: {
773-
$ref: "#/components/schemas/BulkAction",
774+
type: "string",
775+
const: "delete",
776+
title: "Action",
774777
description: "The action to be performed on the entities.",
775778
},
776779
entities: {
@@ -795,7 +798,9 @@ export const $BulkDeleteAction_PoolBody_ = {
795798
export const $BulkDeleteAction_VariableBody_ = {
796799
properties: {
797800
action: {
798-
$ref: "#/components/schemas/BulkAction",
801+
type: "string",
802+
const: "delete",
803+
title: "Action",
799804
description: "The action to be performed on the entities.",
800805
},
801806
entities: {
@@ -865,7 +870,9 @@ Fields are populated in the response only if the respective action was part of t
865870
export const $BulkUpdateAction_ConnectionBody_ = {
866871
properties: {
867872
action: {
868-
$ref: "#/components/schemas/BulkAction",
873+
type: "string",
874+
const: "update",
875+
title: "Action",
869876
description: "The action to be performed on the entities.",
870877
},
871878
entities: {
@@ -890,7 +897,9 @@ export const $BulkUpdateAction_ConnectionBody_ = {
890897
export const $BulkUpdateAction_PoolBody_ = {
891898
properties: {
892899
action: {
893-
$ref: "#/components/schemas/BulkAction",
900+
type: "string",
901+
const: "update",
902+
title: "Action",
894903
description: "The action to be performed on the entities.",
895904
},
896905
entities: {
@@ -915,7 +924,9 @@ export const $BulkUpdateAction_PoolBody_ = {
915924
export const $BulkUpdateAction_VariableBody_ = {
916925
properties: {
917926
action: {
918-
$ref: "#/components/schemas/BulkAction",
927+
type: "string",
928+
const: "update",
929+
title: "Action",
919930
description: "The action to be performed on the entities.",
920931
},
921932
entities: {

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ export type BaseInfoResponse = {
143143
status: string | null;
144144
};
145145

146-
/**
147-
* Bulk Action to be performed on the used model.
148-
*/
149-
export type BulkAction = "create" | "delete" | "update";
150-
151146
/**
152147
* Bulk Action to be taken if the entity does not exist.
153148
*/
@@ -198,7 +193,7 @@ export type BulkCreateAction_ConnectionBody_ = {
198193
/**
199194
* The action to be performed on the entities.
200195
*/
201-
action: BulkAction;
196+
action: "create";
202197
/**
203198
* A list of entities to be created.
204199
*/
@@ -210,7 +205,7 @@ export type BulkCreateAction_PoolBody_ = {
210205
/**
211206
* The action to be performed on the entities.
212207
*/
213-
action: BulkAction;
208+
action: "create";
214209
/**
215210
* A list of entities to be created.
216211
*/
@@ -222,7 +217,7 @@ export type BulkCreateAction_VariableBody_ = {
222217
/**
223218
* The action to be performed on the entities.
224219
*/
225-
action: BulkAction;
220+
action: "create";
226221
/**
227222
* A list of entities to be created.
228223
*/
@@ -234,7 +229,7 @@ export type BulkDeleteAction_ConnectionBody_ = {
234229
/**
235230
* The action to be performed on the entities.
236231
*/
237-
action: BulkAction;
232+
action: "delete";
238233
/**
239234
* A list of entity id/key to be deleted.
240235
*/
@@ -246,7 +241,7 @@ export type BulkDeleteAction_PoolBody_ = {
246241
/**
247242
* The action to be performed on the entities.
248243
*/
249-
action: BulkAction;
244+
action: "delete";
250245
/**
251246
* A list of entity id/key to be deleted.
252247
*/
@@ -258,7 +253,7 @@ export type BulkDeleteAction_VariableBody_ = {
258253
/**
259254
* The action to be performed on the entities.
260255
*/
261-
action: BulkAction;
256+
action: "delete";
262257
/**
263258
* A list of entity id/key to be deleted.
264259
*/
@@ -292,7 +287,7 @@ export type BulkUpdateAction_ConnectionBody_ = {
292287
/**
293288
* The action to be performed on the entities.
294289
*/
295-
action: BulkAction;
290+
action: "update";
296291
/**
297292
* A list of entities to be updated.
298293
*/
@@ -304,7 +299,7 @@ export type BulkUpdateAction_PoolBody_ = {
304299
/**
305300
* The action to be performed on the entities.
306301
*/
307-
action: BulkAction;
302+
action: "update";
308303
/**
309304
* A list of entities to be updated.
310305
*/
@@ -316,7 +311,7 @@ export type BulkUpdateAction_VariableBody_ = {
316311
/**
317312
* The action to be performed on the entities.
318313
*/
319-
action: BulkAction;
314+
action: "update";
320315
/**
321316
* A list of entities to be updated.
322317
*/

0 commit comments

Comments
 (0)