ahultgren / swagger-elm

Generate Elm types and decoders based on a Swagger file
74 stars 9 forks source link

Snakecase fields in records should be turned into camelCase #17

Open eeue56 opened 7 years ago

eeue56 commented 7 years ago

Example input:

  Banana:
    type: object
    required:
      - banana_id
    properties:
      banana_id:
        type: string

right now generates:

type alias BananaRecord = 
  {  banana_id: String
  }

decodeBanana = ...
  ... 
  |> required "banana_id"
  ...

It should instead generate:

type alias BananaRecord = 
  {  bananaId: String
  }

decodeBanana = ...
  ... 
  |> required "banana_id"
  ...
ahultgren commented 7 years ago

I think this is a nice-to-have, since _, while not idiomatic, works. Also there's the issue of avoiding name collisions. Consider:

  Banana:
    type: object
    properties:
      banana_id:
        type: string
      bananaId:
        type: string

which would be valid swagger.

eeue56 commented 7 years ago

I would argue that that example should actually be invalid swagger. If you have to things with the same name, the only difference being camelCase and camel_case, then you've duplicated the fields and made the API inconsistent

ahultgren commented 7 years ago

I agree it's a bad schema, but it's nonetheless a valid spec. Swagger is very unopinionated on how you name your fields. I suppose it's a separate issue though, since sanitization can already cause collisions.

eeue56 commented 7 years ago

I would think the ideal approach would be to make swagger-elm warn you when your API contains underscores, and provide a flag for auto-converting it to camelCase

ahultgren commented 7 years ago

That sounds like a good solution