andrenth / ocaml-swagger

Swagger 2.0 code generator for OCaml
37 stars 10 forks source link

Getting error: Schema.kind_to_string: object without additional_properties #11

Closed carlosdagos closed 5 years ago

carlosdagos commented 5 years ago

Hello!

I'm trying to use this lib with this schema and I'm getting the error:

Swagger.codegen
  ~input:"/path/to/spec-v1-swagger.json"
  ~output:stdout
  ~path_base:"/"
  ~definition_base:"/"
  ~reference_base:""
  ~reference_root:"definitions"
;;

And I'm getting the following

Exception:
Failure "Schema.kind_to_string: object without additional_properties".

(It's very likely I'm getting the invocation wrong.)

Thanks!

rdavison commented 5 years ago

I'm not completely sure about the invocation that you're using (nothing stands out as obviously wrong about it). However, it looks like the schema doesn't define any additionalProperties fields. As far as I know, the field is optional within the swagger spec, but ocaml-swagger doesn't handle the case when it is not present. You can see that here: https://github.com/andrenth/ocaml-swagger/blob/master/src/schema.ml#L39

I'm not really sure what would be the correct way of handling it, seeing as OCaml requires the type to be known ahead of time.

rdavison commented 5 years ago

So, I looked a little further into it, it looks like the types are being specified, but a level above. I'd say someone would have to tinker with the code generator in order to correctly output the necessary types.

carlosdagos commented 5 years ago

it looks like the types are being specified, but a level above

I noticed this when comparing to, say, the Kubernetes one. Looks like ocaml-swagger is making an assumption about the structure.

Thanks for replying to my issue @rdavison 👍

carlosdagos commented 5 years ago

Took a closer look and figured out that ocaml-swagger was just misinterpreting the semantics of additionalProperties (however, the level at which the types are being specified is correct and ocaml-swagger treats this correctly). I think I've got a fix for it. Will submit a PR and see what you and the library author think :)

carlosdagos commented 5 years ago

Quick update:

It's also happening with this schema. I haven't had time to look at the issue in detail, but I'll use it as an additional test case 😃