Skip to content

Commit

Permalink
Fix issue found with pydantic dataclass arguments order
Browse files Browse the repository at this point in the history
  • Loading branch information
tito97sp committed Mar 27, 2024
1 parent 5176754 commit e46ba81
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class ClientCredentialsOauthFlow(security_schemes.ClientCredentialsOauthFlow):



@dataclasses.dataclass
class OAuthFlows(security_schemes.OAuthFlows):
client_credentials: ClientCredentialsOauthFlow = ClientCredentialsOauthFlow()
client_credentials: ClientCredentialsOauthFlow


@dataclasses.dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@dataclasses.dataclass
class PasswordOauthFlow(security_schemes.PasswordOauthFlow):
username: str
password: str
token_url: parse.ParseResult = parse.ParseResult(
scheme="https",
netloc="petstore.swagger.io",
Expand All @@ -26,8 +28,9 @@ class PasswordOauthFlow(security_schemes.PasswordOauthFlow):
})


@dataclasses.dataclass
class OAuthFlows(security_schemes.OAuthFlows):
password : PasswordOauthFlow = PasswordOauthFlow()
password : PasswordOauthFlow


@dataclasses.dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ def apply_auth(

@dataclasses.dataclass
class PasswordOauthFlow(OAuthFlowBase):
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
username: str
password: str
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
refresh_url: typing.Optional[str] = None
_scope_names_to_client: typing.Dict[typing.Tuple[str, ...], requests_client.OAuth2Session] = dataclasses.field(default_factory=dict)
_scope_names_to_token: typing.Dict[typing.Tuple[str, ...], OauthToken] = dataclasses.field(default_factory=dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class ImplicitOAuthFlow(security_schemes.ImplicitOAuthFlow):
})


@dataclasses.dataclass
class OAuthFlows(security_schemes.OAuthFlows):
implicit : ImplicitOAuthFlow = ImplicitOAuthFlow()
implicit : ImplicitOAuthFlow


@dataclasses.dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def apply_auth(

@dataclasses.dataclass
class PasswordOauthFlow(OAuthFlowBase):
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
username: str
password: str
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
refresh_url: typing.Optional[str] = None
_scope_names_to_client: typing.Dict[typing.Tuple[str, ...], requests_client.OAuth2Session] = dataclasses.field(default_factory=dict)
_scope_names_to_token: typing.Dict[typing.Tuple[str, ...], OauthToken] = dataclasses.field(default_factory=dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ImplicitOAuthFlow(security_schemes.ImplicitOAuthFlow):

@dataclasses.dataclass
class PasswordOauthFlow(security_schemes.PasswordOauthFlow):
username: str
password: str
token_url: parse.ParseResult = parse.ParseResult(
{{#with tokenUrl}}
scheme="{{getProtocol}}",
Expand Down Expand Up @@ -178,19 +180,20 @@ class AuthorizationCodeOauthFlow(security_schemes.AuthorizationCodeOauthFlow):
{{/with}}


@dataclasses.dataclass
class OAuthFlows(security_schemes.OAuthFlows):
{{#with flows}}
{{#if password}}
password : PasswordOauthFlow = PasswordOauthFlow()
password : PasswordOauthFlow
{{/if}}
{{#if implicit}}
implicit : ImplicitOAuthFlow = ImplicitOAuthFlow()
implicit : ImplicitOAuthFlow
{{/if}}
{{#if clientCredentials}}
client_credentials: ClientCredentialsOauthFlow = ClientCredentialsOauthFlow()
client_credentials: ClientCredentialsOauthFlow
{{/if}}
{{#if authorizationCode}}
authorization_code: AuthorizationCodeOauthFlow = AuthorizationCodeOauthFlow()
authorization_code: AuthorizationCodeOauthFlow
{{/if}}
{{/with}}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/python/security_schemes.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ class ImplicitOAuthFlow(OAuthFlowBase):

@dataclasses.dataclass
class PasswordOauthFlow(OAuthFlowBase):
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
username: str
password: str
token_url: parse.ParseResult
scopes: typing.Dict[str, str]
refresh_url: typing.Optional[str] = None
_scope_names_to_client: typing.Dict[typing.Tuple[str, ...], requests_client.OAuth2Session] = dataclasses.field(default_factory=dict)
_scope_names_to_token: typing.Dict[typing.Tuple[str, ...], OauthToken] = dataclasses.field(default_factory=dict)
Expand Down

0 comments on commit e46ba81

Please sign in to comment.