create-client icon indicating copy to clipboard operation
create-client copied to clipboard

Next.js: SyntaxError: Unexpected token, expected ";" (8:7)

Open nicodemuz opened this issue 5 years ago • 0 comments

API Platform version(s) affected: 0.7.0

Description
Unable to generate code using Next.js generator.

How to reproduce

Notification.yaml for API platform:

App\Entity\Notification:
    collectionOperations:
        get:
            method: 'GET'
            path: '/auth/v1/notifications'
            normalization_context:
                groups: ['notification_list']
    itemOperations:
        get:
            method: 'GET'
            path: '/auth/v1/notification/{id}'
            normalization_context:
                groups: ['notification_detail']
        patch:
            method: 'PATCH'
            path: '/auth/v1/notification/{id}'
            security: 'object.getUser() == user'
            normalization_context:
                groups: ['notification_detail']
            denormalization_context:
                groups: ['notification_write']
    attributes:
        order:
            is_read: ASC
            created: DESC
        pagination_items_per_page: 1000 # Output all notifications
        pagination_maximum_items_per_page: 1000 # Output all notifications
        pagination_client_items_per_page: true # default query param is itemsPerPage

Sample execution:

npx @api-platform/client-generator http://127.0.0.1:8018/api src -g next 
SyntaxError: Unexpected token, expected ";" (8:7)
   6 | 
   7 | interface Props {
>  8 |   auth/v1/notifications: Notification[];
     |       ^
   9 | }
  10 | 
  11 | export const List: FunctionComponent<Props> = ({ auth/v1/notifications }) => (
    at t (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/parser-babel.js:1:317)
    at Object.parse (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/parser-babel.js:1:346164)
    at Object.parse (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/index.js:13625:19)
    at coreFormat (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/index.js:14899:14)
    at format (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/index.js:15131:14)
    at /home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/index.js:57542:12
    at Object.format (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/node_modules/prettier/index.js:57562:12)
    at NextGenerator.createFile (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/lib/generators/BaseGenerator.js:105:40)
    at NextGenerator.createFileFromPattern (/home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/lib/generators/BaseGenerator.js:84:12)
    at /home/nico/.npm/_npx/1660197/lib/node_modules/@api-platform/client-generator/lib/generators/NextGenerator.js:97:23 {
  loc: { start: { line: 8, column: 7 } },
  codeFrame: '\x1B[0m \x1B[90m  6 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m  7 | \x1B[39minterface \x1B[33mProps\x1B[39m {\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m  8 | \x1B[39m  auth\x1B[33m/\x1B[39mv1\x1B[33m/\x1B[39mnotifications\x1B[33m:\x1B[39m \x1B[33mNotification\x1B[39m[]\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m    | \x1B[39m      \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m  9 | \x1B[39m}\x1B[0m\n' +
    '\x1B[0m \x1B[90m 10 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 11 | \x1B[39m\x1B[36mexport\x1B[39m \x1B[36mconst\x1B[39m \x1B[33mList\x1B[39m\x1B[33m:\x1B[39m \x1B[33mFunctionComponent\x1B[39m\x1B[33m<\x1B[39m\x1B[33mProps\x1B[39m\x1B[33m>\x1B[39m \x1B[33m=\x1B[39m ({ auth\x1B[33m/\x1B[39mv1\x1B[33m/\x1B[39mnotifications }) \x1B[33m=>\x1B[39m (\x1B[0m'
}

Possible Solution
Possibly requires changes in here: https://github.com/api-platform/client-generator/blob/main/templates/next/components/foo/Form.tsx#L9

Additional Context
Similar issue posted here: https://stackoverflow.com/questions/66319050/api-platform-pwa-client-generation-next-js-seems-to-break-for-entitieswithmult

nicodemuz avatar Apr 02 '21 02:04 nicodemuz