Skip to content

Commit e785e3a

Browse files
committed
chore: apply code formatting
Apply mix format to maintain consistent code style
1 parent dfb7131 commit e785e3a

File tree

1 file changed

+60
-44
lines changed

1 file changed

+60
-44
lines changed

lib/ash_json_api/json_schema/open_api.ex

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ if Code.ensure_loaded?(OpenApiSpex) do
949949
# We're in a recursive loop, return $ref and warn
950950
# Recursive type detected, using $ref instead of inline definition
951951
require Logger
952+
952953
Logger.warning(
953954
"Detected recursive embedded type with JSON API type: #{inspect(instance_of)}"
954955
)
@@ -1079,12 +1080,12 @@ if Code.ensure_loaded?(OpenApiSpex) do
10791080
# Generate the schema name based on parent context when needed
10801081
parent_type = AshJsonApi.Resource.Info.type(parent_resource)
10811082
attribute_name = Map.get(attribute, :name)
1082-
1083+
10831084
# Check if this embedded resource has a JSON API type for input schema naming
10841085
json_api_type = AshJsonApi.Resource.Info.type(embedded_resource)
10851086

10861087
# Generate schema name - use parent context for embedded resources without their own type
1087-
input_schema_name =
1088+
input_schema_name =
10881089
if json_api_type do
10891090
"#{json_api_type}-input-#{action_type}"
10901091
else
@@ -1111,7 +1112,7 @@ if Code.ensure_loaded?(OpenApiSpex) do
11111112

11121113
# Create a minimal schema for the recursive type if it doesn't exist
11131114
# This ensures the $ref has something to point to
1114-
acc_with_schema =
1115+
acc_with_schema =
11151116
if Map.has_key?(acc.schemas, input_schema_name) do
11161117
acc
11171118
else
@@ -1122,6 +1123,7 @@ if Code.ensure_loaded?(OpenApiSpex) do
11221123
properties: %{},
11231124
description: "Recursive embedded type - see parent schema for structure"
11241125
}
1126+
11251127
%{acc | schemas: Map.put(acc.schemas, input_schema_name, minimal_schema)}
11261128
end
11271129

@@ -1155,10 +1157,19 @@ if Code.ensure_loaded?(OpenApiSpex) do
11551157
properties: %{},
11561158
description: "Recursive embedded type"
11571159
}
1160+
11581161
{minimal_schema, acc}
11591162
else
11601163
new_acc = %{acc | seen_input_types: [type_key | acc.seen_input_types]}
1161-
embedded_type_input_impl(attribute, embedded_resource, action_type, new_acc, format, nil)
1164+
1165+
embedded_type_input_impl(
1166+
attribute,
1167+
embedded_resource,
1168+
action_type,
1169+
new_acc,
1170+
format,
1171+
nil
1172+
)
11621173
end
11631174
end
11641175
end
@@ -1581,10 +1592,10 @@ if Code.ensure_loaded?(OpenApiSpex) do
15811592

15821593
# Get request body and any generated schemas
15831594
{request_body_result, request_schemas} = request_body(route, resource)
1584-
1595+
15851596
# Merge request schemas into accumulator
15861597
acc_with_request_schemas = %{acc | schemas: Map.merge(acc.schemas, request_schemas)}
1587-
1598+
15881599
operation = %Operation{
15891600
description: action_description(action, route, resource),
15901601
operationId: route.name,
@@ -2046,53 +2057,58 @@ if Code.ensure_loaded?(OpenApiSpex) do
20462057

20472058
{multipart_body_schema, multipart_acc} =
20482059
request_body_schema(route, resource, :multipart, empty_acc())
2049-
2060+
20502061
# Collect all generated schemas
20512062
all_schemas = Map.merge(json_acc.schemas, multipart_acc.schemas)
20522063

2053-
body = if route.type == :route &&
2054-
(route.method == :delete || Enum.empty?(json_body_schema.properties.data.properties)) do
2055-
nil
2056-
else
2057-
body_required =
2058-
cond do
2059-
route.type in [:post_to_relationship, :delete_from_relationship, :patch_relationship] ->
2060-
true
2064+
body =
2065+
if route.type == :route &&
2066+
(route.method == :delete || Enum.empty?(json_body_schema.properties.data.properties)) do
2067+
nil
2068+
else
2069+
body_required =
2070+
cond do
2071+
route.type in [
2072+
:post_to_relationship,
2073+
:delete_from_relationship,
2074+
:patch_relationship
2075+
] ->
2076+
true
20612077

2062-
route.type == :route ->
2063-
json_body_schema.properties.data.required != []
2078+
route.type == :route ->
2079+
json_body_schema.properties.data.required != []
20642080

2065-
true ->
2066-
json_body_schema.properties.data.properties.attributes.required != [] ||
2067-
json_body_schema.properties.data.properties.relationships.required != []
2068-
end
2081+
true ->
2082+
json_body_schema.properties.data.properties.attributes.required != [] ||
2083+
json_body_schema.properties.data.properties.relationships.required != []
2084+
end
20692085

2070-
content =
2071-
if json_body_schema == multipart_body_schema do
2072-
# No file inputs declared, multipart is not necessary
2073-
%{
2074-
"application/vnd.api+json" => %MediaType{schema: json_body_schema}
2075-
}
2076-
else
2077-
%{
2078-
"application/vnd.api+json" => %MediaType{schema: json_body_schema},
2079-
"multipart/x.ash+form-data" => %MediaType{
2080-
schema: %Schema{
2081-
multipart_body_schema
2082-
| additionalProperties: %{type: :string, format: :binary}
2086+
content =
2087+
if json_body_schema == multipart_body_schema do
2088+
# No file inputs declared, multipart is not necessary
2089+
%{
2090+
"application/vnd.api+json" => %MediaType{schema: json_body_schema}
2091+
}
2092+
else
2093+
%{
2094+
"application/vnd.api+json" => %MediaType{schema: json_body_schema},
2095+
"multipart/x.ash+form-data" => %MediaType{
2096+
schema: %Schema{
2097+
multipart_body_schema
2098+
| additionalProperties: %{type: :string, format: :binary}
2099+
}
20832100
}
20842101
}
2085-
}
2086-
end
2102+
end
2103+
2104+
%RequestBody{
2105+
description:
2106+
"Request body for the #{route.name || route.route} operation on #{AshJsonApi.Resource.Info.type(resource)} resource",
2107+
required: body_required,
2108+
content: content
2109+
}
2110+
end
20872111

2088-
%RequestBody{
2089-
description:
2090-
"Request body for the #{route.name || route.route} operation on #{AshJsonApi.Resource.Info.type(resource)} resource",
2091-
required: body_required,
2092-
content: content
2093-
}
2094-
end
2095-
20962112
# Return both the body and any generated schemas
20972113
{body, all_schemas}
20982114
end

0 commit comments

Comments
 (0)