Bart ten Brinke 4ece8e992a
Elixir: Switch Poison to Jason (#16061)
* Switch Poison to Jason

* generate-samples.sh

* Finalize Poison -> Jason switch

* parse date-time values to Elixir DateTime
* improve formatting in various places, so there's less changes by `mix
  format` later
* fix Java version in flake.nix

* Use List.delete/2 instead of Enum.reject/2 for performance reasons

* mix format test/*

* Install dialyxir and fix reported issues

* Fix RequestBuilder.decode/2 hardcoded module name

* Update docs

* Revert changes to API spec (HTTP -> HTTPS)

* Revert uneeded change to Elixir code generator

* Use HTTP in Elixir tests

HTTPS doesn't work for folks who setup petstore.swagger.io as described
in docs/faq-contributing.md.

---------

Co-authored-by: Wojciech Piekutowski <wojciech@piekutowski.net>
2023-07-20 18:36:50 +02:00

50 lines
1.2 KiB
Elixir

defmodule DeserializerTest do
use ExUnit.Case, async: true
alias OpenapiPetstore.Deserializer
alias OpenapiPetstore.Model.{Category, Pet, Tag}
@valid_json """
{
"id": 14,
"category": {
"id": 75,
"name": "sea dragons"
},
"name": "Nagga",
"photoUrls": [
"https://example.com/nagga1.jpg",
"https://example.com/nagga2.jpg"
],
"tags": [
{
"id": 99,
"name": "dragon"
},
{
"id": 23,
"name": "sea"
}
],
"status": "foo"
}
"""
test "jason_decode/2 with valid JSON" do
assert Deserializer.jason_decode(@valid_json, Pet) ==
{:ok,
%Pet{
id: 14,
category: %Category{id: 75, name: "sea dragons"},
name: "Nagga",
photoUrls: ["https://example.com/nagga1.jpg", "https://example.com/nagga2.jpg"],
tags: [%Tag{id: 99, name: "dragon"}, %Tag{id: 23, name: "sea"}],
status: "foo"
}}
end
test "jason_decode/2 with invalid JSON" do
assert Deserializer.jason_decode(~s/{: 1}/, Pet) ==
{:error, %Jason.DecodeError{data: "{: 1}", position: 1, token: nil}}
end
end