[ERROR] package.json already exists at package.json
gustawdaniel opened this issue · comments
I started from command
npm init openapi-generator-plus
and had errors
npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs
[ERROR] package.json already exists at package.json
npm ERR! code 1
npm ERR! path /home/daniel/exp/chroma/clients/js
npm ERR! command failed
npm ERR! command sh -c create-openapi-generator-plus
npm ERR! A complete log of this run can be found in:
npm ERR! /home/daniel/.npm/_logs/2023-04-15T09_32_32_991Z-debug-0.log
but on this command
npx openapi-generator-plus generate -i openapi.json -g typescript-fetch -o src/generated --additional-properties 'typescriptThreePlus=true,withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models,useSingleRequestParameter=true,withNodeImports=true,npmName=chromadb';
I had
Unknown option: i
Unknown option: additional-properties
API specification not specified
usage: /home/daniel/.npm/_npx/d004b2cb4af24a43/node_modules/.bin/ogplus [generate] [-c <config file>] [-o <output dir>] [-g <generator template or path>] [--watch] [--clean] [<path or url to api spec>]
so I tried this one
npx openapi-generator-plus generate -g typescript-fetch -o src/generated openapi.json
and seen
Failed to load generator template: typescript-fetch Error: Cannot find module 'typescript-fetch'
I changed to
npx openapi-generator-plus generate -g typescript-fetch-client -o src/generated openapi.json
also without success
In next step I removed my package.json
and tried with init
again. Then I reverted my package.json
I suggest to rather append
"openapi-generator-plus": "^2.6.0",
"@openapi-generator-plus/typescript-fetch-node-client-generator": "^1.1.6"
to devDependencies and
"generate": "openapi-generator-plus -c config.yml"
to scripts than override existing package.json
then I changed config.yml to
# OpenAPI Generator Plus generator configuration
inputPath: openapi.json
outputPath: src/generated
generator: "@openapi-generator-plus/typescript-fetch-node-client-generator"
# See https://github.com/karlvr/openapi-generator-plus-generators/tree/master/packages/typescript-fetch-node-client#readme for more configuration options
and seen
Failed to process the API specification: Error: Missing schema type: {}
I have in my schema
is it correct openapi schema few places with
```json
"/api/v1/version": {
"get": {
"summary": "Version",
"operationId": "version",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
I i decided to omit them entirely. Did not helped.
Then I changed
throw new Error(`Missing schema type: ${(0, utils_1.debugStringify)(apiSchema)}`);
to less restrictive
return types_1.CodegenSchemaType.OBJECT;
code was generated but I had further problems
- I do not need
abab
dependency (it is not used btw) - I do not want
node-fetch
dependency because node from 18 support fetch natively
I changed generator to typescript-fetch-client-generator
and then I had next problem
I could not use
import { Configuration, DefaultApi } from "./generated";
because DefaultApi
is not exported.
I did not solved this problem and when I saw
export const defaultFetch = window.fetch;
I understood that I have to give up.
I wish you success with this library. I think your approach is much better that in original openapi-generator
. But there is a lot to do to simplify it and document. I hope that this report will be useful to understand what problems have your users. Probably many of them consider option of migrate from openapi-generator
to openapi-generator-plus
and simplifying this process substantially increase chance for mass adoption of this project.
@gustawdaniel thanks for your detailed report. It is indeed frustrating when you try something and it just doesn't work.
I do think the npm init
path is the quickest path to achieving something... it seems that it didn't work for you because you wanted it to add to your additional package.json
, is that correct? I would be possible to just add to the existing project... it's just a little more work in the create-api-project.ts
. I'll make some changes to improve that a bit.
Re:
schema: {}
Is it correct that an empty schema should be treated as an object? The generated code for an object with no properties won't be very useful. Are you sure about that?
The abab
dependency is sometimes used, depending upon the API spec. It is a little annoying to have unwanted dependencies, but you can easily remove it... the generated package.json
isn't replaced so your modifications are permanent. That is interesting news re node-fetch
... that suggests that I can simply remove it as a dependency. I'll probably need an option that retains it for people targeting older versions of node. The work never ends :-)
I suspect you wanted to use the node generator but switched to the web generator (typescript-fetch-client-generator
), which is why you saw window
etc. But regarding the imports, I think everything is exported, so you'll find DefaultApi
in the default export.
I hope your API journey has gone well!