feat: Add OTP 28+ compatibility with version-aware regex pattern handling#670
feat: Add OTP 28+ compatibility with version-aware regex pattern handling#670matthewsinclair wants to merge 2 commits intoopen-api-spex:masterfrom
Conversation
…ling - Implement OTP version detection in schema macro - Add runtime schema compilation for OTP 28+ when regex patterns are present - Maintain module attribute optimization for non-regex schemas on all OTP versions - Add deprecation warning for regex patterns on OTP 28+ with migration guidance - Fix cast_parameters.ex to avoid regex in module attributes - Update string test to check pattern source instead of regex struct equality This ensures backward compatibility while providing a clear migration path for OTP 28+ users to move from regex patterns to string patterns.
lib/open_api_spex/schema.ex
Outdated
| |> has_regex_pattern?() | ||
| end | ||
|
|
||
| def has_regex_pattern?(enumerable) |
There was a problem hiding this comment.
This guard is giving a warning CI:
==> open_api_spex
Compiling 80 files (.ex)
warning: incompatible types:
map() !~ [dynamic()]
in expression:
# lib/open_api_spex/schema.ex:544
is_list(enumerable)
where "enumerable" was given the type map() in:
# lib/open_api_spex/schema.ex:544
is_map_key(enumerable, :__struct__)
where "enumerable" was given the type [dynamic()] in:
# lib/open_api_spex/schema.ex:544
is_list(enumerable)
Conflict found at
│
544 │ when not is_struct(enumerable) and (is_list(enumerable) or is_map(enumerable)) do
│ ~
│
└─ lib/open_api_spex/schema.ex:544:43: OpenApiSpex.Schema.has_regex_pattern?/1
Compilation failed due to warnings while using the --warnings-as-errors option
Error: Process completed with exit code 1.
| prevent "... protocol has already been consolidated ..." | ||
| compiler warnings. | ||
| """ | ||
| def should_use_runtime_compilation?(body) do |
There was a problem hiding this comment.
I don't think this should be a public function. It's also hijacking the @doc for defmacro schema/2.
There was a problem hiding this comment.
I'll submit a change to fix this, but that method is called from elsewhere, so I think it needs to be public, no? Unless I'm missing something. The @doc issue is easier to fix (I think). :)
- Fix type incompatibility warning in has_regex_pattern?/1 by splitting function clauses - Make should_use_runtime_compilation?/1 undocumented (@doc false) Addresses feedback in open-api-spex#670 (review)
|
This change isn't actually necessary anymore. OTP 28.1 will restore this functionality, and Elixir 1.19 will be delayed until that happens. |
|
@zachdaniel would you happen to have a link to a relevant discussion about e.g. 28.1 and elixir 1.19? |
|
🤔 I don't. I just have it on good authority, but I could perhaps be wrong actually. |
|
Looking to see if there is a public thread about it somewhere. |
|
@zachdaniel @gmile This comment erlang/otp#9976 (comment) mentions that. |
Including:
This ensures backward compatibility while providing a clear migration path for OTP 28+ users to move from regex patterns to string patterns.