Skip to content
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

Merged
merged 2 commits into from
May 8, 2021
Merged

Issue/359 #360

merged 2 commits into from
May 8, 2021

Conversation

zoten
Copy link
Contributor

@zoten zoten commented May 5, 2021

Issue #359

@mbuhot
Copy link
Collaborator

mbuhot commented May 6, 2021

Looks like CI is complaining about formatting:

** (Mix) mix format failed due to --check-formatted.
The following files were not formatted:

* test/open_api/decode_yaml_test.exs
* test/cast_test.exs
* lib/open_api_spex/open_api/decode.ex

@zoten
Copy link
Contributor Author

zoten commented May 6, 2021

Thanks!
Please note that the 2 failing tests are there to highlight the second question in the referenced issue, I'll fix or remove them as you prefer if everything is ok. I think it is (otherwise messages with additionalProperties would risk to bomb the beam with atom consumption) but better to ask!

@@ -0,0 +1,66 @@
defmodule OpenApiSpex.OpenApi.DecodYamlTest do
Copy link
Contributor

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

Copy link
Contributor

@moxley moxley May 6, 2021

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.

Copy link
Contributor Author

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

@@ -130,6 +130,45 @@ defmodule OpenApiSpec.CastTest do
assert error.path == [:age]
end

test "additional properties" do
Copy link
Contributor

@moxley moxley May 6, 2021

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.

Copy link
Contributor Author

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})
Copy link
Contributor

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.

Copy link
Contributor Author

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!

@moxley moxley merged commit 5d15f33 into open-api-spex:master May 8, 2021
@moxley
Copy link
Contributor

moxley commented May 8, 2021

Thanks @zoten !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants