Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema's with id or $id fail to generate valid code #83

Open
ahacking opened this issue Jul 28, 2024 · 0 comments
Open

Schema's with id or $id fail to generate valid code #83

ahacking opened this issue Jul 28, 2024 · 0 comments

Comments

@ahacking
Copy link

Versions

I am attempting to use Exonerate 1.1.3, with Elixir 1.17.2 OTP-27

$ elixir -v
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:32:24] [ds:32:24:10] [async-threads:1] [jit:ns]

Elixir 1.17.2 (compiled with Erlang/OTP 27)

mix.exs:

{:exonerate, "~> 1.1.3", runtime: false},

The problem

Consider the schema at https://www.first.org/cvss/cvss-v3.0.json

When attempting to create a validation function:

defmodule Core.JSONSchema.CVSS do
    require Exonerate

  Exonerate.function_from_string(:def, :validate_cvss_3_0, """
  ... contents here ...
  """ 
  )
end
$ mix compile
Compiling 1 file (.ex)
     error: undefined function https://www.first.org/cvss/cvss-v3.0.json#/definitions/scoreType/minimum/2 (expected Core.JSONSchema.CVSS to define such a function or for it to be imported, but none are available)
     │
 613 │   Exonerate.function_from_string(:def, :validate_cvss_3_0, """
     │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     └─ lib/etc/json_schema/cvss.ex:613: Core.JSONSchema.CVSS."https://www.first.org/cvss/cvss-v3.0.json#/definitions/scoreType"/2

     error: undefined function https://www.first.org/cvss/cvss-v3.0.json#/definitions/scoreType/maximum/2 (expected Core.JSONSchema.CVSS to define such a function or for it to be imported, but none are available)

 613 │   Exonerate.function_from_string(:def, :validate_cvss_3_0, """
     │   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     │
     └─ lib/etc/json_schema/cvss.ex:613: Core.JSONSchema.CVSS."https://www.first.org/cvss/cvss-v3.0.json#/definitions/scoreType"/2

The generated code when using the dump: true option shows the following (both float and integer variants):

defp https___www.first.org_cvss_cvss_v3.0.jsonat_definitions_scoreType(float, path)
     when is_float(float) do
  with :ok <-
         https___www.first.org_cvss_cvss_v3.0.jsonat_definitions_scoreType_maximum(float, path),
       :ok <-
         https___www.first.org_cvss_cvss_v3.0.jsonat_definitions_scoreType_minimum(float, path) do
    :ok
  end
end

There are no functions generated named: https___www.first.org_cvss_cvss_v3.0.jsonat_definitions_scoreType_minimum or https___www.first.org_cvss_cvss_v3.0.jsonat_definitions_scoreType_maximum however there are functions entrypoint_at_definitions_scoreType_minimum and entrypoint_at_definitions_scoreType_maximum which indicates a problem prefixing the id on the function names.

If I remove the following "id: " line from the schema document string then it compiles successfully.

"id": "https://www.first.org/cvss/cvss-v3.0.json",

Some questions

  • Why does a schema with an id generate some function names without the required id prefix?
  • How would cross schema references resolve in the cache without the ids?
  • What would be a strategy to handling this correctly? (Would it be better to hash the id to keep them uniform length?)

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant