From 0481e8448f9dcc41b626328678a954f3afbe0fa4 Mon Sep 17 00:00:00 2001 From: Rajas <89877409+floydtree@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:04:18 -0400 Subject: [PATCH] Bug fixes (#112) * fixing sample data generation for timestamp fields Signed-off-by: Rajas Panat * setting additional properties to false in the json schemas Signed-off-by: Rajas Panat * updating the version Signed-off-by: Rajas Panat --------- Signed-off-by: Rajas Panat --- lib/schema/generator.ex | 2 +- lib/schema/json_schema.ex | 8 +++++--- mix.exs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/schema/generator.ex b/lib/schema/generator.ex index d642398..4157bcd 100644 --- a/lib/schema/generator.ex +++ b/lib/schema/generator.ex @@ -473,7 +473,7 @@ defmodule Schema.Generator do end defp generate_data(_name, "timestamp_t", _field), - do: DateTime.utc_now() |> DateTime.to_unix(:microsecond) + do: DateTime.utc_now() |> DateTime.to_unix(:millisecond) defp generate_data(_name, "datetime_t", _field), do: DateTime.utc_now() |> DateTime.to_iso8601() diff --git a/lib/schema/json_schema.ex b/lib/schema/json_schema.ex index 9b89305..b065015 100644 --- a/lib/schema/json_schema.ex +++ b/lib/schema/json_schema.ex @@ -44,12 +44,13 @@ defmodule Schema.JsonSchema do else class_schema(make_class_ref(name, ext)) end - |> empty_object(properties) |> Map.put("title", type[:caption]) |> Map.put("type", "object") |> Map.put("properties", properties) + |> Map.put("additionalProperties", false) |> put_required(required) |> encode_objects(type[:objects]) + |> empty_object(properties) end defp add_java_class(obj, name) do @@ -78,7 +79,8 @@ defmodule Schema.JsonSchema do defp class_schema(id) do %{ "$schema" => @schema_version, - "$id" => id + "$id" => id, + "additionalProperties" => false } end @@ -185,7 +187,7 @@ defmodule Schema.JsonSchema do true -> type end end - + defp encode_object(schema, _name, attr) do type = attr[:object_type] Map.put(schema, "$ref", make_object_ref(type)) diff --git a/mix.exs b/mix.exs index 35f72d8..cc5a550 100644 --- a/mix.exs +++ b/mix.exs @@ -10,7 +10,7 @@ defmodule Schema.MixProject do use Mix.Project - @version "2.73.1" + @version "2.74.0" def project do build = System.get_env("GITHUB_RUN_NUMBER") || "SNAPSHOT"