Skip to content

Commit 2ea209b

Browse files
fabiopellegriniFabio Pellegrini
andauthored
feat: allow to hide fields from documentation (#7)
Co-authored-by: Fabio Pellegrini <fabio.pellegrini@fluida.io>
1 parent fd022cf commit 2ea209b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

lib/open_api/open_api.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defmodule EctoCommand.OpenApi do
2222
Enum.reduce(@command_fields, {%{}, []}, fn field, {fields, required} ->
2323
{name, type, opts} = field
2424

25-
if opts[:internal] != true do
25+
if opts[:internal] != true and opts[:doc] != false do
2626
required = if Enum.member?([true, []], opts[:required]), do: [name | required], else: required
2727
fields = Map.put(fields, name, EctoCommand.OpenApi.schema_for(type, opts))
2828
{fields, required}

test/unit/command/open_api/open_api_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule Unit.EctoCommand.OpenApi.OpenApiTest do
1212

1313
command do
1414
param :id, :string, doc: Type.uuid()
15+
param :hidden_field, :string, required: true, inclusion: ["a", "b"], doc: false
1516
param :numeric_id, :id
1617
param :name, :string, required: true, length: [min: 2, max: 255], doc: [example: "Mario"]
1718
param :email, :string, required: true, format: ~r/@/, length: [min: 6], doc: Type.email()
@@ -158,6 +159,8 @@ defmodule Unit.EctoCommand.OpenApi.OpenApiTest do
158159
example: %{a: 1}
159160
}
160161
} == Sample.schema().properties
162+
163+
refute Map.has_key?(Sample.schema().properties, :hidden_field)
161164
end
162165

163166
test "example is generated accordingly to properties" do
@@ -188,6 +191,8 @@ defmodule Unit.EctoCommand.OpenApi.OpenApiTest do
188191
type_id: "string",
189192
uploaded_at: "2023-04-03T10:21:00Z"
190193
} == Sample.schema().example
194+
195+
refute Map.has_key?(Sample.schema().example, :hidden_field)
191196
end
192197

193198
test "required fields list is generated correctly" do

0 commit comments

Comments
 (0)