-
Notifications
You must be signed in to change notification settings - Fork 194
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
Fix oneOf/allOf/anyOf and schema module in Discriminator mapping #455
Merged
+717
−165
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
024e7d2
fix: cast discriminator when value has atom keys
igormq bfba2b9
chore: addressing pr comments
53490dd
fix: add new logic for one of and any of cast
igormq 876bf78
chore: fix format
igormq 5c33b97
chore: fix format
igormq 44de9df
fix: all of with required
igormq 1d83763
fix: small fix on the allOf function
robpmarques 44867b7
fix: fixing required fields outside all_of, one_of and any_of
robpmarques f4ea70b
chore: adding put_properties to inherit properties on all of, any of …
robpmarques 13a97b2
fix: adding put_properties
robpmarques b87cf1c
fix: removing put_properties
robpmarques 53f56ea
chore: make a better approach to test for errors in required fields
igormq 36467a5
chore: one of should return errors
igormq f853eb7
chore: expose all errors
igormq 58388d0
fix: anyOf and allOf casting with additionalProperties
albertored 20bdf66
fix format
albertored 10d5d29
fix: correctly handle write/readOnly on checking required properties
albertored 4d33362
fix: it should be possible to cast a null value when nullabe true in …
albertored 85cfd24
fix: no special treatment for allOf of arrays
albertored cc1a6c3
fix: nil value when schema has xxxOf
albertored 3a10680
Merge branch 'master' into fix-xxxOf
lucacorti ad7547b
Don't prepend discriminator propertyName to path
lucacorti ed48cc9
Fix tests
lucacorti 5cf10bd
Merge branch 'master' into fix-xxxOf
lucacorti 071d7c5
Fix merge
lucacorti 9599e57
Format and fix tests
lucacorti 55e56f2
Merge branch 'master' into fix-xxxOf
lucacorti 489e93a
Merge branch 'master' into fix-xxxOf
lucacorti 895e2f5
Merge branch 'open-api-spex:master' into fix-xxxOf
lucacorti 75db236
Merge branch 'open-api-spex:master' into fix-xxxOf
lucacorti 7eb02e4
Merge branch 'open-api-spex:master' into fix-xxxOf
lucacorti 33ec112
Address review remarks
lucacorti d2402d3
Remove casting from atom-keyed maps
mbuhot cd94ab5
chore: formatting
mbuhot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,10 @@ defmodule OpenApiSpex.Cast.Utils do | |
# Merge 2 maps considering as equal keys that are atom or string representation | ||
# of that atom. Atom keys takes precedence over string ones. | ||
def merge_maps(map1, map2) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've not implemented this and am not sure what the functions achieves. @albertored can you take a look? |
||
l1 = Enum.map(map1, fn {key, val} -> {to_string(key), key, val} end) | ||
l2 = Enum.map(map2, fn {key, val} -> {to_string(key), key, val} end) | ||
|
||
l1 | ||
|> Kernel.++(l2) | ||
|> Enum.group_by(fn {ks, _, _} -> ks end, fn {_, k, v} -> {k, v} end) | ||
|> Map.new(fn | ||
{_ks, [{k, v}]} -> | ||
{k, v} | ||
|
||
{_ks, [{k1, v1}, {k2, v2}]} -> | ||
cond do | ||
is_atom(k2) -> {k2, v2} | ||
is_atom(k1) -> {k1, v1} | ||
true -> {k2, v2} | ||
end | ||
result = Map.merge(map1, map2) | ||
Enum.reduce(result, result, fn | ||
{k, _v}, result when is_atom(k) -> Map.delete(result, to_string(k)) | ||
_, result -> result | ||
end) | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@mbuhot I don't remember if I was the one that originally added this line but I think this was needed to support discriminators where the property is an atom, it is indirectly tested in the test you removed in this same commit.
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.
Is there a scenario where the discriminator property is an atom?
The test was casting a map where all keys were already atoms, I'm not sure when that would be required.
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 think there are use cases but I don't have a particular one in mind.
My reasoning was that since it is possible to cast an object with atom keys it should be possible also when the discriminator property is an atom
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.
@igormq Is there a scenario you have where you need to cast data that already has atom keys?
I'm open to including the functionality, I just want to make sure it's not a hack to fix some other bug we might have :)
024e7d2