rjcnd105
hello. I’m a beginner who has just studied elixir and ash.
I wanted to add the maxLength, minLength, and pattern properties in the Openapi Model type through Ash constructs
When I checked the code, I think I can add it through json_write_schema.
use Ash.Type.NewType,
subtype_of: :string
use AshJsonApi.Type
@base_scehma %{
"type" => "string"
}
@impl AshJsonApi.Type
def json_write_schema(constraints) do
@base_scehma
|> apply_min_length(Keyword.get(constraints, :min_length))
|> apply_max_length(Keyword.get(constraints, :max_length))
|> apply_pattern(Keyword.get(constraints, :match))
end
I implemented it in this way and adds to /json_schema is well reflected.
/open_api is not reflected, so I checked the code
/ash_json_api/json_schema/json_schema.ex
defp resource_write_attribute_type(%{type: type} = attr, action_type) do
if embedded?(type) do
embedded_type_input(attr, action_type)
else
if :erlang.function_exported(type, :json_write_schema, 1) do
type.json_write_schema(attr.constraints)
else
resource_attribute_type(attr)
end
end
end
/ash_json_api/json_schema/open_api.ex
def resource_write_attribute_type(%{type: type} = attr, resource, action_type, format) do
cond do
Ash.Type.NewType.new_type?(type) ->
new_constraints = Ash.Type.NewType.constraints(type, attr.constraints)
new_type = Ash.Type.NewType.subtype_of(type)
resource_write_attribute_type(
Map.merge(attr, %{type: Ash.Type.get_type(new_type), constraints: new_constraints}),
resource,
action_type,
format
)
AshJsonApi.JsonSchema.embedded?(type) ->
embedded_type_input(attr, action_type)
true ->
if :erlang.function_exported(type, :json_write_schema, 1) do
type.json_write_schema(attr.constraints)
else
resource_attribute_type(attr, resource, format)
end
end
|> with_attribute_description(attr)
end
If you are written in this way, it is not going to json_write_schema if it is newType.
def resource_write_attribute_type(%{type: type} = attr, resource, action_type, format) do
cond do
:erlang.function_exported(type, :json_write_schema, 1) ->
type.json_write_schema(attr.constraints)
Ash.Type.NewType.new_type?(type) ->
new_constraints = Ash.Type.NewType.constraints(type, attr.constraints)
new_type = Ash.Type.NewType.subtype_of(type)
resource_write_attribute_type(
Map.merge(attr, %{type: Ash.Type.get_type(new_type), constraints: new_constraints}),
resource,
action_type,
format
)
AshJsonApi.JsonSchema.embedded?(type) ->
embedded_type_input(attr, action_type)
true ->
resource_attribute_type(attr, resource, format)
end
|> with_attribute_description(attr)
end
Shouldn’t it be modified like the code above? Or are I approaching in the wrong way?
I didn’t speak English and translated it. The article may be awkward
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
Yes, you are correct. We should have a check for
function_exported(type, :json_write_schema, 1)at the beginning of thatcondstatement. Great find! Would you like to PR that change?rjcnd105
Sure, I’ll open a PR for that. thanks!
rjcnd105
I’m really sorry about this. Since I don’t have much experience contributing to open source yet, it looks like I made a mistake somewhere. This unfortunately caused the same item to be listed twice in the generated changelog. ㅠ_ㅠ
zachdaniel
It was my fault
Nothing to worry about
You did great!