Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
chore: move group schemas to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
gtema committed Feb 27, 2024
1 parent 56cffe4 commit 8be8096
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
38 changes: 3 additions & 35 deletions codegenerator/openapi/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from ruamel.yaml.scalarstring import LiteralScalarString

from keystone.identity import schema as identity_schema

from codegenerator.common.schema import ParameterSchema
from codegenerator.common.schema import PathSchema
from codegenerator.common.schema import SpecSchema
Expand Down Expand Up @@ -477,39 +475,9 @@ def _get_schema_ref(
if matched:
return (ref, mime_type)

mime_type = "application/json"

# Groups
if name == "GroupPatchRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_update)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsPostRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_create)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupPatchResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**group.GROUP_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**group.GROUPS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**group.GROUP_SCHEMA)
)
ref = f"#/components/schemas/{name}"

# Default
else:
(ref, mime_type) = super()._get_schema_ref(
openapi_spec, name, description, action_name=action_name
)
(ref, mime_type) = super()._get_schema_ref(
openapi_spec, name, description, action_name=action_name
)

return (ref, mime_type)
45 changes: 45 additions & 0 deletions codegenerator/openapi/keystone_schemas/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from keystone.identity import schema as identity_schema

from codegenerator.common.schema import TypeSchema


GROUP_SCHEMA: dict[str, Any] = {
"type": "object",
"properties": {
Expand All @@ -26,3 +29,45 @@
"type": "object",
"properties": {"groups": {"type": "array", "items": GROUP_SCHEMA}},
}


def _get_schema_ref(
openapi_spec,
name,
description=None,
schema_def=None,
action_name=None,
) -> tuple[str | None, str | None, bool]:
mime_type: str = "application/json"
ref: str
# Groups
if name == "GroupPatchRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_update)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsPostRequest":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**identity_schema.user_create)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupPatchResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUP_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupsGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUPS_SCHEMA)
)
ref = f"#/components/schemas/{name}"
elif name == "GroupGetResponse":
openapi_spec.components.schemas.setdefault(
name, TypeSchema(**GROUP_SCHEMA)
)
ref = f"#/components/schemas/{name}"

else:
return (None, None, False)

return (ref, mime_type, True)

0 comments on commit 8be8096

Please sign in to comment.