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

Handle more parsing cases (int and str formats, additional props: fix #10, #11 and #13) #12

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

smondet
Copy link

@smondet smondet commented Nov 24, 2024

No description provided.

@smondet smondet marked this pull request as draft November 24, 2024 22:01
@smondet smondet changed the title Add enum and field-mask formats (#10 and #11) Handle more parsing cases (int and str formats, additional props: fix #10, #11 and #13) Nov 25, 2024
@smondet smondet marked this pull request as ready for review November 25, 2024 14:43
@smondet smondet force-pushed the smondet-I10-enum-int-format branch from 112cc1a to 8b34166 Compare November 25, 2024 18:08
@smondet smondet force-pushed the smondet-I10-enum-int-format branch from 8b34166 to ce6759d Compare November 25, 2024 19:37
)
$ Arg.(
value (opt_all string [] (info [ "only-matching" ] ~docv:"REGEXP" ~doc:"Only output types matching REGEXP."))
)
Copy link
Collaborator

@ixzzd ixzzd Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinking this is a nice addition, thank you @smondet
Could you please add also tests for this one and mention it in the doc?

lib/generator.ml Outdated Show resolved Hide resolved
value
(opt (t3 ~sep:':' keyword string string) Generator.default_state.json_ocaml_type
(info [ "json-ocaml-type" ] ~docv:"KEYWORD:MODULE.PATH:TYPE-NAME"
~doc:"Use an alternate Mod.type for `json`, e.g. from:My_mod.Submod:json_type."
Copy link
Collaborator

@ixzzd ixzzd Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useful 👍

lib/generator.ml Outdated
| None ->
(* fallback to untyped if schema type is not defined *)
maybe_nullable "json"
Printf.ksprintf maybe_nullable "json (* %s *)" (String.concat "/" (List.rev ancestors))
Copy link
Collaborator

@ixzzd ixzzd Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about ancestors lists here, for example:

   type dynamicConfigValue = {
     ~id  <ocaml default="\"\"">: string;
-    ?value : json option;
+    ?value : json (* DynamicConfigValue/value *) option;
   } 

https://github.com/ahrefs/jsonschema2atd/actions/runs/12166801073/job/33933871312#step:6:77

Looks like the comment is a bit redundant here. Do you have an example in mind which would illustrate the reason of having this comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've improved the comments but in that case, there is nothing in the JSON to display for "value" :)

"DynamicConfigValue": {
  "type": "object",
  "required": [
    "id"
  ],
  "properties": {
    "id": {
      "type": "string",
      "default": ""
    },
    "value": {}
  },
  "$schema": "http://json-schema.org/draft-04/schema#"
},

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

Successfully merging this pull request may close these issues.

2 participants