Skip to content

Commit

Permalink
Remove unused status code, rename post_body to body
Browse files Browse the repository at this point in the history
  • Loading branch information
jason810496 committed Nov 18, 2024
1 parent f020ba5 commit 42e8a51
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
3 changes: 0 additions & 3 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2700,9 +2700,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'400':
description: Validation error
example: {}
'409':
description: Conflict
content:
Expand Down
33 changes: 13 additions & 20 deletions airflow/api_fastapi/core_api/routes/public/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,17 @@ def patch_pool(
@pools_router.post(
"/",
status_code=status.HTTP_201_CREATED,
responses=create_openapi_http_exception_doc(
[status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN, status.HTTP_409_CONFLICT]
),
responses=create_openapi_http_exception_doc([status.HTTP_409_CONFLICT]),
)
def post_pool(
post_body: PoolPostBody,
body: PoolPostBody,
session: Annotated[Session, Depends(get_session)],
) -> PoolResponse:
"""Create a Pool."""
pool = session.scalar(select(Pool).where(Pool.pool == post_body.pool))
pool = session.scalar(select(Pool).where(Pool.pool == body.pool))
if pool is not None:
raise HTTPException(status.HTTP_409_CONFLICT, f"Pool with name: `{post_body.pool}` already exists")
pool = Pool(**post_body.model_dump())
raise HTTPException(status.HTTP_409_CONFLICT, f"Pool with name: `{body.pool}` already exists")
pool = Pool(**body.model_dump())

session.add(pool)

Expand All @@ -188,32 +186,27 @@ def post_pool(
@pools_router.post(
"/bulk",
status_code=status.HTTP_201_CREATED,
responses={
status.HTTP_400_BAD_REQUEST: {"description": "Validation error", "example": {}},
**create_openapi_http_exception_doc(
[
status.HTTP_401_UNAUTHORIZED,
status.HTTP_403_FORBIDDEN,
status.HTTP_409_CONFLICT,
]
),
},
responses=create_openapi_http_exception_doc(
[
status.HTTP_409_CONFLICT,
]
),
)
def post_pools(
post_bulk_body: PoolPostBulkBody,
body: PoolPostBulkBody,
session: Annotated[Session, Depends(get_session)],
) -> PoolCollectionResponse:
"""Create multiple pools."""
# Check if any of the pools already exists
pools_names = [pool.pool for pool in post_bulk_body.pools]
pools_names = [pool.pool for pool in body.pools]
existing_pools = session.scalars(select(Pool.pool).where(Pool.pool.in_(pools_names))).all()
if existing_pools:
raise HTTPException(
status.HTTP_409_CONFLICT,
detail=f"Pools with names: `{existing_pools}` already exist",
)

pools = [Pool(**post_body.model_dump()) for post_body in post_bulk_body.pools]
pools = [Pool(**body.model_dump()) for body in body.pools]
session.add_all(pools)

return PoolCollectionResponse(
Expand Down
1 change: 0 additions & 1 deletion airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ export class PoolService {
body: data.requestBody,
mediaType: "application/json",
errors: {
400: "Validation error",
401: "Unauthorized",
403: "Forbidden",
409: "Conflict",
Expand Down
4 changes: 0 additions & 4 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2758,10 +2758,6 @@ export type $OpenApiTs = {
* Successful Response
*/
201: PoolCollectionResponse;
/**
* Validation error
*/
400: unknown;
/**
* Unauthorized
*/
Expand Down

0 comments on commit 42e8a51

Please sign in to comment.