Skip to content

Commit

Permalink
camelCase
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Dec 6, 2024
1 parent 0758689 commit 90295ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Annotated, Any

from models_library.basic_types import IDStr
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, SecretStr
from pydantic import AliasGenerator, BaseModel, ConfigDict, Field, HttpUrl, SecretStr
from pydantic.alias_generators import to_camel

from ..emails import LowerCaseEmailStr
Expand Down Expand Up @@ -61,7 +61,9 @@ class ApiKeyCreateRequest(BaseModel):
)

model_config = ConfigDict(
alias_generator=to_camel,
alias_generator=AliasGenerator(
validation_alias=to_camel,
),
from_attributes=True,
json_schema_extra={
"examples": [
Expand All @@ -88,7 +90,9 @@ class ApiKeyCreateResponse(ApiKeyCreateRequest):
api_secret: str

model_config = ConfigDict(
alias_generator=to_camel,
alias_generator=AliasGenerator(
serialization_alias=to_camel,
),
from_attributes=True,
json_schema_extra={
"examples": [
Expand Down Expand Up @@ -125,7 +129,9 @@ class ApiKeyGet(BaseModel):
display_name: Annotated[str, Field(..., min_length=3)]

model_config = ConfigDict(
alias_generator=to_camel,
alias_generator=AliasGenerator(
serialization_alias=to_camel,
),
from_attributes=True,
json_schema_extra={
"examples": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6731,10 +6731,10 @@ components:
title: Announcement
ApiKeyCreateRequest:
properties:
display_name:
displayName:
type: string
minLength: 3
title: Display Name
title: Displayname
expiration:
anyOf:
- type: string
Expand All @@ -6745,14 +6745,14 @@ components:
it does not expire.
type: object
required:
- display_name
- displayName
title: ApiKeyCreateRequest
ApiKeyCreateResponse:
properties:
display_name:
displayName:
type: string
minLength: 3
title: Display Name
title: Displayname
expiration:
anyOf:
- type: string
Expand All @@ -6766,25 +6766,22 @@ components:
maxLength: 100
minLength: 1
title: Id
api_base_url:
apiBaseUrl:
type: string
maxLength: 2083
minLength: 1
format: uri
title: Api Base Url
api_key:
title: Apibaseurl
apiKey:
type: string
title: Api Key
api_secret:
title: Apikey
apiSecret:
type: string
title: Api Secret
title: Apisecret
type: object
required:
- display_name
- displayName
- id
- api_base_url
- api_key
- api_secret
- apiBaseUrl
- apiKey
- apiSecret
title: ApiKeyCreateResponse
ApiKeyGet:
properties:
Expand All @@ -6793,14 +6790,14 @@ components:
maxLength: 100
minLength: 1
title: Id
display_name:
displayName:
type: string
minLength: 3
title: Display Name
title: Displayname
type: object
required:
- id
- display_name
- displayName
title: ApiKeyGet
AppStatusCheck:
properties:
Expand Down Expand Up @@ -7613,40 +7610,46 @@ components:
additionalProperties: false
type: object
title: EmptyModel
Envelope_ApiKeyCreateResponse_:
Envelope_AnyUrl_:
properties:
data:
anyOf:
- $ref: '#/components/schemas/ApiKeyCreateResponse'
- type: string
- type: 'null'
title: Envelope[ApiKeyCreateResponse]
Envelope_ApiKeyGet_:
title: Data
error:
anyOf:
- {}
- type: 'null'
title: Error
type: object
title: Envelope[AnyUrl]
Envelope_ApiKeyCreateResponse_:
properties:
data:
anyOf:
- $ref: '#/components/schemas/ApiKeyGet'
- $ref: '#/components/schemas/ApiKeyCreateResponse'
- type: 'null'
error:
anyOf:
- {}
- type: 'null'
title: Error
type: object
title: Envelope[ApiKeyGet]
Envelope_AnyUrl_:
title: Envelope[ApiKeyCreateResponse]
Envelope_ApiKeyGet_:
properties:
data:
anyOf:
- type: string
- $ref: '#/components/schemas/ApiKeyGet'
- type: 'null'
title: Data
error:
anyOf:
- {}
- type: 'null'
title: Error
type: object
title: Envelope[AnyUrl]
title: Envelope[ApiKeyGet]
Envelope_AppStatusCheck_:
properties:
data:
Expand Down
20 changes: 10 additions & 10 deletions services/web/server/tests/unit/with_dbs/01/test_api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ async def test_create_api_key(
disable_gc_manual_guest_users: None,
):
display_name = "foo"
resp = await client.post("/v0/auth/api-keys", json={"display_name": display_name})
resp = await client.post("/v0/auth/api-keys", json={"displayName": display_name})

data, errors = await assert_status(resp, expected)

if not errors:
assert data["display_name"] == display_name
assert "api_key" in data
assert "api_secret" in data
assert data["displayName"] == display_name
assert "apiKey" in data
assert "apiSecret" in data

resp = await client.get("/v0/auth/api-keys")
data, _ = await assert_status(resp, expected)
assert [d["display_name"] for d in data] == [display_name]
assert [d["displayName"] for d in data] == [display_name]


@pytest.mark.parametrize(
Expand Down Expand Up @@ -150,19 +150,19 @@ async def test_create_api_key_with_expiration(
expiration_interval = timedelta(seconds=1)
resp = await client.post(
"/v0/auth/api-keys",
json={"display_name": "foo", "expiration": expiration_interval.seconds},
json={"displayName": "foo", "expiration": expiration_interval.seconds},
)

data, errors = await assert_status(resp, expected)
if not errors:
assert data["display_name"] == "foo"
assert "api_key" in data
assert "api_secret" in data
assert data["displayName"] == "foo"
assert "apiKey" in data
assert "apiSecret" in data

# list created api-key
resp = await client.get("/v0/auth/api-keys")
data, _ = await assert_status(resp, expected)
assert [d["display_name"] for d in data] == ["foo"]
assert [d["displayName"] for d in data] == ["foo"]

# wait for api-key for it to expire and force-run scheduled task
await asyncio.sleep(expiration_interval.seconds)
Expand Down

0 comments on commit 90295ec

Please sign in to comment.