improvement: support booleans in resource generator #1 (/issues/1) (#2)

This commit is contained in:
Peter Hartman 2023-10-18 02:28:54 +01:00 committed by GitHub
parent 418de7a1bd
commit 135c5edf1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1205 additions and 2 deletions

2
.tool-versions Normal file
View file

@ -0,0 +1,2 @@
erlang 26.0.2
elixir 1.15.4-otp-26

View file

@ -88,6 +88,9 @@ defmodule AshJsonApiWrapper.OpenApi.ResourceGenerator do
%{"type" => "integer"} ->
":integer"
%{"type" => "boolean"} ->
":boolean"
other ->
raise "Unsupported property: #{inspect(other)}"
end

View file

@ -41,7 +41,7 @@
"sobelow": {:hex, :sobelow, "0.11.1", "23438964486f8112b41e743bbfd402da3e5b296fdc9eacab29914b79c48916dd", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9897363a7eff96f4809304a90aad819e2ad5e5d24db547af502885146746a53c"},
"sourceror": {:hex, :sourceror, "0.14.0", "b6b8552d0240400d66b6f107c1bab7ac1726e998efc797f178b7b517e928e314", [:mix], [], "hexpm", "809c71270ad48092d40bbe251a133e49ae229433ce103f762a2373b7a10a8d8b"},
"spark": {:hex, :spark, "1.1.39", "f143b84a5b796bf2d83ec8fb4793ee9e66e67510c40d785f9a67050bb88e7677", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:sourceror, "~> 0.1", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "d71bc26014c7e7abcdcf553f4cf7c5a5ff96f8365b1e20be3768ce503aafb203"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"stream_data": {:hex, :stream_data, "0.5.0", "b27641e58941685c75b353577dc602c9d2c12292dd84babf506c2033cd97893e", [:mix], [], "hexpm", "012bd2eec069ada4db3411f9115ccafa38540a3c78c4c0349f151fc761b9e271"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"},

View file

@ -1,4 +1,4 @@
defmodule AshJsonApiWrapper.OpenApiTest do
defmodule AshJsonApiWrapper.OpenApi.CybridTest do
use ExUnit.Case
require Ash.Query

View file

@ -0,0 +1,50 @@
defmodule AshJsonApiWrapper.OpenApi.PetstoreTest do
use ExUnit.Case
require Ash.Query
@json "test/support/pet_store.json" |> File.read!() |> Jason.decode!()
defmodule TestingTesla do
use Tesla
# plug(Tesla.Middleware.Headers, [
# {"authorization", "Bearer xxx"}
# ])
end
@config [
tesla: TestingTesla,
endpoint: "https://petstore3.swagger.io/api/v3",
resources: [
"Petstore.Order": [
path: "/store/order/{orderId}",
object_type: "components.schemas.Order",
primary_key: "id",
# entity_path: "",
fields: [
orderId: [
filter_handler: {:place_in_csv_list, ["id"]}
]
]
]
]
]
defmodule Api do
use Ash.Api
resources do
allow_unregistered? true
end
end
test "it does stuff" do
@json
|> AshJsonApiWrapper.OpenApi.ResourceGenerator.generate(@config)
|> Enum.map(fn {resource, code} ->
Code.eval_string(code)
resource
end)
end
end

1148
test/support/pet_store.json Normal file

File diff suppressed because it is too large Load diff