aj-foster / open-api-generator

Open API code generator for Elixir
MIT License
97 stars 13 forks source link

Support Default Entry in Responses #5

Closed aj-foster closed 1 year ago

aj-foster commented 1 year ago

Resolves #4.

aej commented 1 year ago

I've just tested this out with Hubspot's Companies API spec (https://api.hubspot.com/api-catalog-public/v1/apis/crm/v3/objects/companies) and it worked great. (Well - there is another bug where if the operationId contains { and } then it fails but Im going to report that separately)

I notice the response structure is something like:

[
  {200, {Hubspot.Companies.CollectionResponseWithTotalSimplePublicObjectForwardPaging, :t}},
  default: {Hubspot.Companies.Error, :t}
]

i.e: The default case is a Keyword list while the 200 case is a tuple - is this intentional?

aej commented 1 year ago

Ah I just remembered that [{:foo, "bar"}] is equivalent to [foo: "bar"] - so that answers my question.

aj-foster commented 1 year ago

I also paused when I saw the output. There could be a way to trick the formatter into behaving differently by adding some annotations to the AST (we do this some other places to ensure the use of """ instead of " in doc strings). However, it is equivalent like you said.

Thanks for mentioning the example spec, and the other issue you encountered 👍🏼