f-f / gogolica

Auto-generated Google APIs for Clojure
Eclipse Public License 1.0
2 stars 0 forks source link

Recognise the enum parameters #29

Open zudov opened 7 years ago

zudov commented 7 years ago

For parameter like:

:projection
  {:type "string",
   :description "Set of properties to return. Defaults to noAcl.",
   :enum ["full" "noAcl"],
   :enumDescriptions
   ["Include all properties."
    "Omit owner, acl and defaultObjectAcl properties."],
   :location "query"}

We could spew out the code like:

:projection
  (case (name projection)
    "no-acl" "noAcl"
    (name projection))

to allow kebab case.

10 (spec-checking) and #19 (docstring generation) would benefit from recognizing them too.

f-f commented 7 years ago

Good point.

More than kebab case, I would say that we should put asserts that check that values are contained in the possible enum values when provided.

zudov commented 7 years ago

When writing that example with the case I was on the fence regarding what should be the default case: argument as it is or throw (InvalidArgumentException. ...), like:

:projection
  (case (name projection)
    "no-acl" "noAcl"
    "noAcl" "noAcl"
    "full" "full"
    (throw (InvalidArgumentException. (str "Unexpected value for 'projection' argument: " projection))))

If we are sure that there won't be need to specify anything that's not in the API model, throwing (or checking it via :pre, would of course be better.

f-f commented 7 years ago

I would go with generating an assert or a :pre, they throw if the things don't look right.

About kebab casing: not sure if we need to do it, as long as we document what goes into the enum in the docstring. But if we want to provide the kebab casing, then we might as well go all the way to use keywords instead of strings.

zudov commented 7 years ago

to use keywords instead of strings

This is why I use name there. Would work on strings, symbols, keywords and anything nameable.

On Wed, Oct 4, 2017, at 12:00, Fabrizio Ferrai wrote:

I would go with generating an assert or a :pre, they throw if the things don't look right.> About kebab casing: not sure if we need to do it, as long as we document what goes into the enum in the docstring.> But if we want to provide the kebab casing, then we might as well go all the way to use keywords instead of strings.> — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub[1], or mute the thread[2].>

Links:

  1. https://github.com/f-f/gogolica/issues/29#issuecomment-334093325
  2. https://github.com/notifications/unsubscribe-auth/ACfiziOp_ANz9m0cPmTunEb8ZJkfEAmiks5so0k-gaJpZM4PrLbn
f-f commented 7 years ago

@zudov TIL you shouldn't answer GH emails in top-posting :D

But I didn't notice the name there, good point 👍