rtk-incubator / rtk-query-codegen

93 stars 13 forks source link

Autogen. file with syntax error on header field #59

Closed JonJohann closed 3 years ago

JonJohann commented 3 years ago

When I try the following command:

npx @rtk-incubator/rtk-query-codegen-openapi --hooks openapi.json > test.ts

I get the following syntax error, it expects a comma on line 8 around "X-Client-Product-Version":

SyntaxError: ',' expected. (8:65) 6 | endpoints: build => ({ 7 | getDatasets: build.query<GetDatasetsApiResponse, GetDatasetsApiArg>({ >8 | query: queryArg => ({ url: /datasets, headers: { X-Client-Product-Version: queryArg.xClientProductVersion } }) 9 | }), 10 | getDatasetMetadata: build.query<GetDatasetMetadataApiResponse, GetDatasetMetadataApiArg>({ 11 | query: queryArg => ({ url: /datasets/${queryArg.datasetId}, headers: { X-Client-Product-Version: queryArg.xClientProductVersion }, params: { crs_EPSG: queryArg.crsEpsg, normalized_for_visualization: queryArg.normalizedForVisualization } })

at e (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\parser-typescript.js:1:322) at C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\parser-typescript.js:22:3244464 at Object.parse (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\parser-typescript.js:22:3244497) at Object.parse$a [as parse] (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\index.js:13652:19) at coreFormat (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\index.js:15183:16) at formatWithCursor$1 (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\index.js:15423:14) at C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\index.js:60171:12 at Object.format (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\node_modules\prettier\index.js:60191:12) at Object.prettify (C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\lib\utils\prettier.js:53:21) at C:\Users\jonjoh\AppData\Roaming\npm-cache_npx\3844\node_modules\@rtk-incubator\rtk-query-codegen-openapi\lib\bin\cli.js:90:39 {

I downloaded the file from https://raw.githubusercontent.com/kartverket/SFKB-API/master/spec/openapi.yaml as both a .yaml file and a converted json file. They both gave the same error. When comparing with the pet API used in the docs, it lacks header fields, so I suspect the problem lies with either the generation of the header fields inside the endpoints or in the openAPI spec? The spec works perfectly fine in e.g Postman.

tevariou commented 3 years ago

The issue lies with the - characters in X-Client-Product-Version and it should be fixed by https://github.com/rtk-incubator/rtk-query-codegen/pull/52. Maybe you can try this one out?

phryneas commented 3 years ago

This should be resolved with 0.4.0