diff --git a/packages/models-library/src/models_library/api_schemas_webserver/auth.py b/packages/models-library/src/models_library/api_schemas_webserver/auth.py index 2dbc3678437..9db5f24edbc 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/auth.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/auth.py @@ -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 @@ -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": [ @@ -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": [ @@ -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": [ diff --git a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml index ea51e00e843..570cb5583e0 100644 --- a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml +++ b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml @@ -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 @@ -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 @@ -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: @@ -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: @@ -7613,18 +7610,25 @@ 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: @@ -7632,21 +7636,20 @@ components: - 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: diff --git a/services/web/server/tests/unit/with_dbs/01/test_api_keys.py b/services/web/server/tests/unit/with_dbs/01/test_api_keys.py index 6e60c834b13..85f63c42b96 100644 --- a/services/web/server/tests/unit/with_dbs/01/test_api_keys.py +++ b/services/web/server/tests/unit/with_dbs/01/test_api_keys.py @@ -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( @@ -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)