-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue/359 #360
Issue/359 #360
Conversation
Looks like CI is complaining about formatting:
|
Thanks! |
test/open_api/decode_yaml_test.exs
Outdated
@@ -0,0 +1,66 @@ | |||
defmodule OpenApiSpex.OpenApi.DecodYamlTest do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix the typo in the module name? Should be DecodeYamlTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file looks like it's testing the OpenApiSpex.OpenApi.Decode
module, and there is already a test file (DecodeTest
) for it. Could you move them to the DecodeTest
file?
The Decode
module is agnostic to the original file format the api spec was stored in. I don't see a need to bring in the yamerl
dependency. YAML and JSON parse to identical Elixir data structures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! I've been misleaded by reading the comment on DecodeTest about decomposing and testing also yaml, so I thought to put a skeleton for it, but you're totally right
test/cast_test.exs
Outdated
@@ -130,6 +130,45 @@ defmodule OpenApiSpec.CastTest do | |||
assert error.path == [:age] | |||
end | |||
|
|||
test "additional properties" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to move these tests to test/cast/object_test.exs
. There is already a test there that does what this test is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, didn't see it!
I'll move those two tests there, since it's not exactly what the other tests are doing: this is about resolving references (that is the main point of the issue), while the already present tests use schemas defined in-place, so I think at least the first is useful (the nested one may be overkill since normal schema resolution is already well tested?)
@@ -403,4 +404,13 @@ defmodule OpenApiSpex.OpenApi.Decode do | |||
to_struct(v, mod) | |||
end) | |||
end | |||
|
|||
defp manage_additional_properties(%_{additionalProperties: %{"$ref" => reference}} = map) do | |||
Map.put(map, :additionalProperties, %Reference{"$ref": reference}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but it's good practice to use map literal syntax to put key values on a struct, like this:
%{schema | additionalProperties: %Reference{"$ref": reference}}
That way, if there is a typo in additionalProperties:
, the runtime will raise an exception.
Plus, the syntax is shorter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I code in elixir since some months now and never realized this! Super thanks!
Thanks @zoten !!! |
Issue #359