Skip to content

Commit b46c979

Browse files
committed
improvement: add installers & extenders
improvement: automatically infer the `prefix` instead of relying on configuration and use it always since its never wrong, preventing a common class of misconfigurations.
1 parent 057b0de commit b46c979

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+423
-113
lines changed

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
erlang 26.0.2
2-
elixir 1.15.4
1+
erlang 27.0.1
2+
elixir 1.17.2-otp-27

documentation/topics/open-api.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ mix openapi.spec.json --spec MyAppWeb.AshJsonApi
126126
mix openapi.spec.yaml --spec MyAppWeb.AshJsonApi
127127
```
128128

129+
> ### Setting a route prefix for generated files {: .warning}
130+
>
131+
> The route prefix in normal usage is automatically inferred, but when generating files
132+
> we will use the `prefix` option set in the `json_api` section of the relevant `Ash.Domain` module.
133+
129134
To generate the YAML file you need to add the ymlr dependency.
130135

131136
```elixir
@@ -136,6 +141,13 @@ def deps do
136141
end
137142
```
138143

144+
You can also use the `--check` option to confirm that your checked in spec file(s) match.
145+
146+
```sh
147+
mix openapi.spec.json --spec MyAppWeb.AshJsonApi --check
148+
mix openapi.spec.yaml --spec MyAppWeb.AshJsonApi --check
149+
```
150+
139151
## Known issues/limitations
140152

141153
### Swagger UI

documentation/tutorials/getting-started-with-ash-json-api.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ Add the following to your `config/config.exs`.
105105
config :mime, :types, %{
106106
"application/vnd.api+json" => ["json"]
107107
}
108-
109-
config :mime, :extensions, %{
110-
"json" => "application/vnd.api+json"
111-
}
112108
```
113109

114110
This configuration is required to support working with the JSON:API custom mime type.

lib/ash_json_api/controllers/delete.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule AshJsonApi.Controllers.Delete do
1616
all_domains = options[:all_domains]
1717

1818
conn
19-
|> Request.from(resource, action, domain, all_domains, route)
19+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2020
|> Helpers.destroy_record()
2121
|> Helpers.fetch_includes()
2222
|> Helpers.fetch_metadata()

lib/ash_json_api/controllers/delete_from_relationship.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule AshJsonApi.Controllers.DeleteFromRelationship do
4141
end
4242

4343
conn
44-
|> Request.from(options[:resource], action, domain, all_domains, route)
44+
|> Request.from(options[:resource], action, domain, all_domains, route, options[:prefix])
4545
|> Helpers.update_record(&Helpers.resource_identifiers(&1, argument))
4646
|> Helpers.fetch_metadata()
4747
|> Helpers.render_or_render_errors(conn, fn conn, request ->

lib/ash_json_api/controllers/generic_action_route.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule AshJsonApi.Controllers.GenericActionRoute do
1616
all_domains = options[:all_domains]
1717

1818
conn
19-
|> Request.from(resource, action, domain, all_domains, route)
19+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2020
|> Helpers.run_action()
2121
|> Helpers.render_or_render_errors(conn, fn conn, request ->
2222
status =

lib/ash_json_api/controllers/get.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule AshJsonApi.Controllers.Get do
1616
all_domains = options[:all_domains]
1717

1818
conn
19-
|> Request.from(resource, action, domain, all_domains, route)
19+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2020
|> Helpers.fetch_record_from_path()
2121
|> Helpers.fetch_includes()
2222
|> Helpers.fetch_metadata()

lib/ash_json_api/controllers/get_related.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule AshJsonApi.Controllers.GetRelated do
1717
all_domains = options[:all_domains]
1818

1919
conn
20-
|> Request.from(resource, action, domain, all_domains, route)
20+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2121
|> Helpers.fetch_related(options[:resource])
2222
|> Helpers.fetch_includes()
2323
|> Helpers.fetch_metadata()

lib/ash_json_api/controllers/get_relationship.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule AshJsonApi.Controllers.GetRelationship do
1717
resource = relationship.destination
1818

1919
conn
20-
|> Request.from(resource, action, domain, all_domains, route)
20+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2121
|> Helpers.fetch_related(options[:resource])
2222
|> Helpers.fetch_metadata()
2323
|> Helpers.render_or_render_errors(conn, fn conn, request ->

lib/ash_json_api/controllers/index.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule AshJsonApi.Controllers.Index do
1717

1818
if action.type == :read do
1919
conn
20-
|> Request.from(resource, action, domain, all_domains, route)
20+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
2121
|> Helpers.fetch_pagination_parameters()
2222
|> Helpers.fetch_records()
2323
|> Helpers.fetch_includes()
@@ -33,7 +33,7 @@ defmodule AshJsonApi.Controllers.Index do
3333
end)
3434
else
3535
conn
36-
|> Request.from(resource, action, domain, all_domains, route)
36+
|> Request.from(resource, action, domain, all_domains, route, options[:prefix])
3737
|> Helpers.fetch_records()
3838
|> Helpers.fetch_includes()
3939
|> Helpers.fetch_metadata()

0 commit comments

Comments
 (0)