Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any reason underscores and not dashes? #5

Open
mmucklo opened this issue Dec 22, 2015 · 1 comment
Open

Any reason underscores and not dashes? #5

mmucklo opened this issue Dec 22, 2015 · 1 comment
Assignees

Comments

@mmucklo
Copy link

mmucklo commented Dec 22, 2015

I notice the attribute keys get passed through this function:

    /**
     * Transforms a given string from camelCase to under_score style.
     *
     * @param string $camel
     * @param string $splitter
     *
     * @return string
     */
    public static function camelCaseToUnderscore($camel, $splitter = '_')
    {
        $camel = \preg_replace(
            '/(?!^)[[:upper:]][[:lower:]]/',
            '$0',
            \preg_replace('/(?!^)[[:upper:]]+/', $splitter.'$0', $camel)
        );

        return \strtolower($camel);
    }

However the spec seems to recommend dashes:

http://jsonapi.org/recommendations/#naming

Any thoughts? Can you support both?

@nilportugues
Copy link
Owner

It's just a convention for most JSON format APIs, and JSONAPI doesn't enforce it but recommends.

Back to the bundle itself, thing is you may rename attributes and the class name using dashes and nothing will happen, as they will be preserved by the serializer, so you'll get the desired result. I understand your concern is it doesn't come in by default, right?

It agree ut would be nice to allow the bundle user decide. I'll just allow to pass down a variable. I'll mark this as an enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants