Browse Source

🎨 Re-order parameters

pull/11/head
Sebastián Ramírez 6 years ago
parent
commit
948a39af95
  1. 40
      fastapi/applications.py
  2. 24
      fastapi/params.py
  3. 44
      fastapi/routing.py

40
fastapi/applications.py

@ -106,11 +106,11 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
methods: List[str] = None, methods: List[str] = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> None: ) -> None:
self.router.add_api_route( self.router.add_api_route(
path, path,
@ -122,11 +122,11 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=methods, methods=methods,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def api_route( def api_route(
@ -140,11 +140,11 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
methods: List[str] = None, methods: List[str] = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
def decorator(func: Callable) -> Callable: def decorator(func: Callable) -> Callable:
self.router.add_api_route( self.router.add_api_route(
@ -157,11 +157,11 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=methods, methods=methods,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
return func return func
@ -181,10 +181,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.get( return self.router.get(
path, path,
@ -195,10 +195,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def put( def put(
@ -212,10 +212,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.put( return self.router.put(
path, path,
@ -226,10 +226,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def post( def post(
@ -243,10 +243,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.post( return self.router.post(
path, path,
@ -257,10 +257,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def delete( def delete(
@ -274,10 +274,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.delete( return self.router.delete(
path, path,
@ -288,10 +288,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def options( def options(
@ -305,10 +305,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.options( return self.router.options(
path, path,
@ -319,10 +319,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def head( def head(
@ -336,10 +336,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.head( return self.router.head(
path, path,
@ -350,10 +350,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def patch( def patch(
@ -367,10 +367,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.patch( return self.router.patch(
path, path,
@ -381,10 +381,10 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def trace( def trace(
@ -398,10 +398,10 @@ class FastAPI(Starlette):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.router.trace( return self.router.trace(
path, path,
@ -412,8 +412,8 @@ class FastAPI(Starlette):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )

24
fastapi/params.py

@ -18,7 +18,6 @@ class Param(Schema):
self, self,
default: Any, default: Any,
*, *,
deprecated: bool = None,
alias: str = None, alias: str = None,
title: str = None, title: str = None,
description: str = None, description: str = None,
@ -29,6 +28,7 @@ class Param(Schema):
min_length: int = None, min_length: int = None,
max_length: int = None, max_length: int = None,
regex: str = None, regex: str = None,
deprecated: bool = None,
**extra: Any, **extra: Any,
): ):
self.deprecated = deprecated self.deprecated = deprecated
@ -55,7 +55,6 @@ class Path(Param):
self, self,
default: Any, default: Any,
*, *,
deprecated: bool = None,
alias: str = None, alias: str = None,
title: str = None, title: str = None,
description: str = None, description: str = None,
@ -66,13 +65,12 @@ class Path(Param):
min_length: int = None, min_length: int = None,
max_length: int = None, max_length: int = None,
regex: str = None, regex: str = None,
deprecated: bool = None,
**extra: Any, **extra: Any,
): ):
self.description = description
self.deprecated = deprecated
self.in_ = self.in_ self.in_ = self.in_
super().__init__( super().__init__(
default, ...,
alias=alias, alias=alias,
title=title, title=title,
description=description, description=description,
@ -83,6 +81,7 @@ class Path(Param):
min_length=min_length, min_length=min_length,
max_length=max_length, max_length=max_length,
regex=regex, regex=regex,
deprecated=deprecated,
**extra, **extra,
) )
@ -94,7 +93,6 @@ class Query(Param):
self, self,
default: Any, default: Any,
*, *,
deprecated: bool = None,
alias: str = None, alias: str = None,
title: str = None, title: str = None,
description: str = None, description: str = None,
@ -105,10 +103,9 @@ class Query(Param):
min_length: int = None, min_length: int = None,
max_length: int = None, max_length: int = None,
regex: str = None, regex: str = None,
deprecated: bool = None,
**extra: Any, **extra: Any,
): ):
self.description = description
self.deprecated = deprecated
super().__init__( super().__init__(
default, default,
alias=alias, alias=alias,
@ -121,6 +118,7 @@ class Query(Param):
min_length=min_length, min_length=min_length,
max_length=max_length, max_length=max_length,
regex=regex, regex=regex,
deprecated=deprecated,
**extra, **extra,
) )
@ -132,7 +130,6 @@ class Header(Param):
self, self,
default: Any, default: Any,
*, *,
deprecated: bool = None,
alias: str = None, alias: str = None,
convert_underscores: bool = True, convert_underscores: bool = True,
title: str = None, title: str = None,
@ -144,10 +141,9 @@ class Header(Param):
min_length: int = None, min_length: int = None,
max_length: int = None, max_length: int = None,
regex: str = None, regex: str = None,
deprecated: bool = None,
**extra: Any, **extra: Any,
): ):
self.description = description
self.deprecated = deprecated
self.convert_underscores = convert_underscores self.convert_underscores = convert_underscores
super().__init__( super().__init__(
default, default,
@ -161,6 +157,7 @@ class Header(Param):
min_length=min_length, min_length=min_length,
max_length=max_length, max_length=max_length,
regex=regex, regex=regex,
deprecated=deprecated,
**extra, **extra,
) )
@ -172,7 +169,6 @@ class Cookie(Param):
self, self,
default: Any, default: Any,
*, *,
deprecated: bool = None,
alias: str = None, alias: str = None,
title: str = None, title: str = None,
description: str = None, description: str = None,
@ -183,10 +179,9 @@ class Cookie(Param):
min_length: int = None, min_length: int = None,
max_length: int = None, max_length: int = None,
regex: str = None, regex: str = None,
deprecated: bool = None,
**extra: Any, **extra: Any,
): ):
self.description = description
self.deprecated = deprecated
super().__init__( super().__init__(
default, default,
alias=alias, alias=alias,
@ -199,6 +194,7 @@ class Cookie(Param):
min_length=min_length, min_length=min_length,
max_length=max_length, max_length=max_length,
regex=regex, regex=regex,
deprecated=deprecated,
**extra, **extra,
) )

44
fastapi/routing.py

@ -205,11 +205,11 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
methods: List[str] = None, methods: List[str] = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> None: ) -> None:
route = APIRoute( route = APIRoute(
path, path,
@ -221,11 +221,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=methods, methods=methods,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
self.routes.append(route) self.routes.append(route)
@ -240,11 +240,11 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
methods: List[str] = None, methods: List[str] = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
def decorator(func: Callable) -> Callable: def decorator(func: Callable) -> Callable:
self.add_api_route( self.add_api_route(
@ -257,11 +257,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=methods, methods=methods,
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
return func return func
@ -285,19 +285,19 @@ class APIRouter(routing.Router):
description=route.description, description=route.description,
response_description=route.response_description, response_description=route.response_description,
deprecated=route.deprecated, deprecated=route.deprecated,
name=route.name,
methods=route.methods, methods=route.methods,
operation_id=route.operation_id, operation_id=route.operation_id,
include_in_schema=route.include_in_schema, include_in_schema=route.include_in_schema,
content_type=route.content_type, content_type=route.content_type,
name=route.name,
) )
elif isinstance(route, routing.Route): elif isinstance(route, routing.Route):
self.add_route( self.add_route(
prefix + route.path, prefix + route.path,
route.endpoint, route.endpoint,
methods=route.methods, methods=route.methods,
name=route.name,
include_in_schema=route.include_in_schema, include_in_schema=route.include_in_schema,
name=route.name,
) )
def get( def get(
@ -311,10 +311,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -325,11 +325,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["GET"], methods=["GET"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def put( def put(
@ -343,10 +343,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -357,11 +357,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["PUT"], methods=["PUT"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def post( def post(
@ -375,10 +375,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -389,11 +389,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["POST"], methods=["POST"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def delete( def delete(
@ -407,10 +407,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -421,11 +421,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["DELETE"], methods=["DELETE"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def options( def options(
@ -439,10 +439,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -453,11 +453,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["OPTIONS"], methods=["OPTIONS"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def head( def head(
@ -471,10 +471,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -485,11 +485,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["HEAD"], methods=["HEAD"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def patch( def patch(
@ -503,10 +503,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -517,11 +517,11 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["PATCH"], methods=["PATCH"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )
def trace( def trace(
@ -535,10 +535,10 @@ class APIRouter(routing.Router):
description: str = None, description: str = None,
response_description: str = "Successful Response", response_description: str = "Successful Response",
deprecated: bool = None, deprecated: bool = None,
name: str = None,
operation_id: str = None, operation_id: str = None,
include_in_schema: bool = True, include_in_schema: bool = True,
content_type: Type[Response] = JSONResponse, content_type: Type[Response] = JSONResponse,
name: str = None,
) -> Callable: ) -> Callable:
return self.api_route( return self.api_route(
path=path, path=path,
@ -549,9 +549,9 @@ class APIRouter(routing.Router):
description=description, description=description,
response_description=response_description, response_description=response_description,
deprecated=deprecated, deprecated=deprecated,
name=name,
methods=["TRACE"], methods=["TRACE"],
operation_id=operation_id, operation_id=operation_id,
include_in_schema=include_in_schema, include_in_schema=include_in_schema,
content_type=content_type, content_type=content_type,
name=name,
) )

Loading…
Cancel
Save