idea: normalizing to snake_case across the board #320
Replies: 6 comments 9 replies
-
If we have paths with underscores, they are no longer DNS safe, which is currently a should from AEP-122. This really touches on the difficulty of casing, which I'm sure we all have suffered from. Currently, my understanding is:
But this does require a conversion when you want to cross reference a resource from another resource. Are there other scenarios causing pain here? It might be worth thinking through all the scenarios and seeing if we can address them. We could do something with a standard field for
This is kind of verbose, but demonstrates a way around the kebabs being properties and forces them into values. (kebab author-name resource type used for demonstration purposes). |
Beta Was this translation helpful? Give feedback.
-
Using snake_case rather than kebab-case in path elements would have generated extremely passionate negative feedback at Roblox. We also made multi-word API names (i.e. subdomains) kebab-case as well because it looked weird to have snake_case in a URL (the Google AIPs didn't specify this at all IIRC). Does anyone use snake_case in URLs? I don't think we should make URLs jarringly ugly for the sake of consistency with unrelated things like field names. |
Beta Was this translation helpful? Give feedback.
-
I think @thegagne's DNS point should make the decision. We cannot have must AEPs conflict with should AEPs. That being said, JSON body properties should continue to be snake_case. It's enough of a convention that libraries like Pydantic rely on snake_case. |
Beta Was this translation helpful? Give feedback.
-
Thanks for all the engagement!
I don't know if we completely understand the motivation for AEP-122's requirement for dns-compatible resource ids. I'm not saying that's a reason to ignore the guidance, but I think it's worth scrutinizing the original motivation. I'd like to point out that URIs do not ban the use of an underscore: https://datatracker.ietf.org/doc/html/rfc3986#section-2.3. |
Beta Was this translation helpful? Give feedback.
-
https://spec.openapis.org/oas/latest.html#operation-object
The spec itself does not enforce a casing convention, only speaks to it being case sensitive. The examples on the site are camelCase, for example: https://learn.openapis.org/examples/v3.0/api-with-examples.html The examples on the swagger site also use camelCase. https://swagger.io/docs/specification/v2_0/paths-and-operations/?sbsearch=operationIds Here's some others I went and looked at:
FWIW in TypeSpec, it's a little goofy. You can let TypeSpec derive it from the namespace + operation, but this results in some ugly operationIds with a mix of Pascal and camel, separated by underscore. https://typespec.io/docs/getting-started/getting-started-rest/02-operations-responses/#example-operation-id-in-openapi-spec. They do allow you to specify the operationId and use whatever you want, which is what I prefer to do for a cleaner operationId. This one seems to be a bit all over the place. My current opinion is that we should either be prescriptive with camelCase to closely follow the examples from OAS, or alternatively use PascalCase, or leave it open ended but suggest that each org adopt their own convention for it based on their needs. From the little research I did, a couple of them had some sense of organization with the concept of namespace + operationId. Because these operationIds will likely get used in downstream automation, the naming convention probably does matter to some degree, but I don't have the foresight to pick a winner here. |
Beta Was this translation helpful? Give feedback.
-
We had a discussion in one of the weekly meetings, and have landed on the following deltas from existing guidance:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Today, we have a few different cases, still in use in the aeps today:
This bifurcation causes a few minor usability issues. They are not blocking, but nontheless introduce some usability friction, primarily in translation - client and uses must a few more string replacements, rather than copy-paste things like the resource singular directly.
This causes issues in:
book_store
, you have to convert it to it's resource singular (book-store
) if you want to look up it's type.So - why do we have this split? is it valuable?
Previously, the snake case was decided upon due to the fact that:
There are also other advantages over kebab-case. For example, all languages generally support snake_case variables (even if they are not recommended).
Making the change
The actual approach to perform this normalization is actually fairly straightforward:
snake_case
.x-aep-resource
annotation examples and syntax to also usesnake_case
.If desired, we could make this a should, with the caveat that existing APIs may not be able to break this precedent. But for new API I don't know if there's a good reason to not standardize.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions