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

route_prefix crashes the next and nuxt generators

Open CedCannes opened this issue 4 years ago • 0 comments

API Platform version(s) affected: 2.6.6

Description
the next and nuxt generators return an error if routePrefix is set

How to reproduce
Add the routePrefix parameter to the apiResource attribute of an entity.

#[ApiResource(
    routePrefix: "prefix"
)]
class Board

or in the api/config/packages/api_platform.yaml file

# Good cache defaults for REST APIs
    defaults:
        stateless: true
        cache_headers:
            vary: ['Content-Type', 'Authorization', 'Origin']
        route_prefix: prefix

Possible Solution

Additional Context
The error appeared for next and nuxt but not the other generators.

the error :

SyntaxError: Unexpected token, expected ";" (7:9)
   5 |
   6 | interface Props {
>  7 |   prefix/boards: Board[];
     |         ^
   8 | }
   9 |
  10 | export const List: FunctionComponent<Props> = ({ prefix/boards }) => (
    at li (/usr/local/share/.config/yarn/global/node_modules/prettier/parser-babel.js:22:11986)
    at di (/usr/local/share/.config/yarn/global/node_modules/prettier/parser-babel.js:22:12115)
    at Object.parse (/usr/local/share/.config/yarn/global/node_modules/prettier/parser-babel.js:22:336232)
    at Object.parse$a [as parse] (/usr/local/share/.config/yarn/global/node_modules/prettier/index.js:12513:19)
    at coreFormat (/usr/local/share/.config/yarn/global/node_modules/prettier/index.js:14044:16)
    at formatWithCursor$1 (/usr/local/share/.config/yarn/global/node_modules/prettier/index.js:14284:14)
    at /usr/local/share/.config/yarn/global/node_modules/prettier/index.js:59304:12
    at Object.format (/usr/local/share/.config/yarn/global/node_modules/prettier/index.js:59324:12)
    at NextGenerator.createFile (/usr/local/share/.config/yarn/global/node_modules/@api-platform/client-generator/lib/generators/BaseGenerator.js:105:40)
    at NextGenerator.createFileFromPattern (/usr/local/share/.config/yarn/global/node_modules/@api-platform/client-generator/lib/generators/BaseGenerator.js:84:12) {
  loc: { start: { line: 7, column: 9 } },

I see the same error if I change new Resource("abc"... by new Resource("prefix/abc"... in the unit test here

CedCannes avatar Nov 15 '21 23:11 CedCannes