Skip to content

Commit 8a51e04

Browse files
committed
feat(headless): match ACCOUNT_SIGNUP_FIELDS in spec
1 parent 6fe52d8 commit 8a51e04

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

allauth/headless/spec/doc/openapi.yaml

+14-19
Original file line numberDiff line numberDiff line change
@@ -2408,34 +2408,29 @@ components:
24082408
required:
24092409
- password
24102410
ProviderSignup:
2411-
type: object
2412-
properties:
2413-
email:
2414-
$ref: "#/components/schemas/Email"
2415-
required:
2416-
- email
2411+
allOf:
2412+
- $ref: '#/components/schemas/BaseSignup'
24172413
PasskeySignup:
2414+
allOf:
2415+
- $ref: '#/components/schemas/BaseSignup'
2416+
BaseSignup:
24182417
type: object
24192418
properties:
24202419
email:
24212420
$ref: "#/components/schemas/Email"
2422-
username:
2423-
$ref: "#/components/schemas/Username"
2424-
required:
2425-
- email
2426-
Signup:
2427-
type: object
2428-
properties:
2429-
email:
2430-
$ref: "#/components/schemas/Email"
2431-
password:
2432-
$ref: "#/components/schemas/Password"
24332421
phone:
24342422
$ref: "#/components/schemas/Phone"
24352423
username:
24362424
$ref: "#/components/schemas/Username"
2437-
required:
2438-
- password
2425+
Signup:
2426+
allOf:
2427+
- $ref: '#/components/schemas/BaseSignup'
2428+
- type: object
2429+
properties:
2430+
password:
2431+
$ref: "#/components/schemas/Password"
2432+
required:
2433+
- password
24392434
Username:
24402435
type: string
24412436
description: |

allauth/headless/spec/internal/schema.py

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.urls import resolve, reverse
44
from django.urls.exceptions import Resolver404
55

6+
from allauth.account import app_settings as account_settings
67
from allauth.headless import app_settings
78

89

@@ -24,6 +25,7 @@ def get_schema() -> dict:
2425
used_tags = drop_unused_paths(spec)
2526
drop_unused_tags(spec, used_tags)
2627
drop_unused_tag_groups(spec, used_tags)
28+
specify_signup_fields(spec)
2729
return spec
2830

2931

@@ -83,3 +85,22 @@ def drop_unused_tag_groups(spec: dict, used_tags: set) -> None:
8385
for tag_group in tag_groups:
8486
if any([t in used_tags for t in tag_group["tags"]]):
8587
spec["x-tagGroups"].append(tag_group)
88+
89+
90+
def specify_signup_fields(spec: dict) -> None:
91+
base_signup = spec["components"]["schemas"]["BaseSignup"]
92+
signup = spec["components"]["schemas"]["Signup"]
93+
properties = base_signup["properties"]
94+
required_fields = []
95+
for field_name in ("email", "phone", "username"):
96+
field = account_settings.SIGNUP_FIELDS.get(field_name)
97+
if not field:
98+
properties.pop(field_name)
99+
elif field["required"]:
100+
required_fields.append(field_name)
101+
base_signup["required"] = required_fields
102+
password_field = account_settings.SIGNUP_FIELDS.get("password1")
103+
if not password_field:
104+
signup["allOf"] = signup["allOf"][:1]
105+
elif not password_field["required"]:
106+
signup["allOf"][1]["required"].remove("password")

0 commit comments

Comments
 (0)