Skip to content

Commit

Permalink
fix: required attributes being marked as nullable in OpenAPI output (#…
Browse files Browse the repository at this point in the history
…269)

This occured due to an unnecessary conversion from strings to atoms in the OpenApiSpex.Schema's required field.
  • Loading branch information
deerob4 authored Jan 2, 2025
1 parent 81665c9 commit 8cb60b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/ash_json_api/json_schema/open_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ if Code.ensure_loaded?(OpenApiSpex) do
resource
|> Ash.Resource.Info.public_attributes()
|> Enum.reject(&(&1.allow_nil? || AshJsonApi.Resource.only_primary_key?(resource, &1.name)))
|> Enum.map(&to_string(&1.name))
|> Enum.map(& &1.name)
end

@spec resource_attributes(
Expand Down
43 changes: 16 additions & 27 deletions test/acceptance/open_api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ defmodule Test.Acceptance.OpenApiTest do
type: :object,
properties: %{
attributes: %OpenApiSpex.Schema{
required: ["name", "author_id"],
required: [:name, :author_id],
type: :object,
properties: %{
hidden: %{
Expand All @@ -681,26 +681,21 @@ defmodule Test.Acceptance.OpenApiTest do
%{"type" => "null"}
]
},
name: %{
"anyOf" => [
%OpenApiSpex.Schema{
type: :string,
description:
"description of attribute :name. Field included by default."
},
%{"type" => "null"}
]
name: %OpenApiSpex.Schema{
type: :string,
description: "description of attribute :name. Field included by default."
},
author_id: %{
name_twice: %{
"anyOf" => [
%OpenApiSpex.Schema{
type: :string,
description: "Field included by default.",
format: "uuid"
},
%OpenApiSpex.Schema{type: :string, nullable: true},
%{"type" => "null"}
]
},
author_id: %OpenApiSpex.Schema{
type: :string,
description: "Field included by default.",
format: "uuid"
},
email: %{
"anyOf" => [
%OpenApiSpex.Schema{
Expand All @@ -711,12 +706,6 @@ defmodule Test.Acceptance.OpenApiTest do
%{"type" => "null"}
]
},
name_twice: %{
"anyOf" => [
%OpenApiSpex.Schema{type: :string, nullable: true},
%{"type" => "null"}
]
},
count_of_tags: %{
"anyOf" => [%OpenApiSpex.Schema{type: :integer}, %{"type" => "null"}]
}
Expand All @@ -732,19 +721,19 @@ defmodule Test.Acceptance.OpenApiTest do
author: %OpenApiSpex.Schema{
properties: %{
data: %OpenApiSpex.Schema{
type: :object,
description: "An identifier for author",
required: [:type, :id],
additionalProperties: false,
nullable: true,
type: :object,
properties: %{
id: %OpenApiSpex.Schema{type: :string},
meta: %OpenApiSpex.Schema{
type: :object,
additionalProperties: true
},
type: %OpenApiSpex.Schema{type: :string}
}
},
additionalProperties: false,
description: "An identifier for author",
nullable: true
}
}
}
Expand Down

0 comments on commit 8cb60b4

Please sign in to comment.