Skip to content

cannot add nullable property in schema's example #294

@DenysGonchar

Description

@DenysGonchar

if property is set to :null or nil in schema's example, it's filtered out by if PhoenixSwagger.to_json/1
here is an example:

Interactive Elixir (1.13.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> use PhoenixSwagger
PhoenixSwagger.JsonApi
iex(2)> swagger_schema do
...(2)>   property(:someProperty, [:null, :string], "some nullable property")
...(2)>   example(%{someProperty: :null})
...(2)> end
%{
  "example" => %{},
  "properties" => %{
    "someProperty" => %{
      "description" => "some nullable property",
      "type" => [:null, "string"]
    }
  },
  "type" => "object"
}
iex(3)> swagger_schema do
...(3)>   property(:someProperty, [:null, :string], "some nullable property")
...(3)>   example(%{someProperty: nil})
...(3)> end
%{
  "example" => %{},
  "properties" => %{
    "someProperty" => %{
      "description" => "some nullable property",
      "type" => [:null, "string"]
    }
  },
  "type" => "object"
}
iex(4)> swagger_schema do
...(4)>   property(:someProperty, [:null, :string], "some nullable property")
...(4)>   example(%{someProperty: "some_value"})
...(4)> end
%{
  "example" => %{"someProperty" => "some_value"},
  "properties" => %{
    "someProperty" => %{
      "description" => "some nullable property",
      "type" => [:null, "string"]
    }
  },
  "type" => "object"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions