Skip to content

Commit

Permalink
Merge pull request #94 from nicolas-chaulet/fix/types-api
Browse files Browse the repository at this point in the history
fix(types): add types for programmatic API
  • Loading branch information
mrlubos authored Mar 20, 2024
2 parents 94a13cf + 84b1697 commit 872cae2
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 2,382 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dist
node_modules
samples
temp
test/e2e/generated
test/generated
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ yarn-error.log*
*.iml
dist
coverage
samples/generated
samples/swagger-codegen-cli-v2.jar
samples/swagger-codegen-cli-v3.jar
.env

# test files
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,25 @@ or
yarn add @nicolas-chaulet/openapi-typescript-codegen -D
```

and add a script to your `package.json` file
If you want to use `openapi-ts` with CLI, add a script to your `package.json` file

```json
"scripts": {
"openapi-ts": "openapi-ts"
}
```

You can also generate your client programmatically by importing `openapi-ts` in a `.ts` file.

```ts
import { createClient } from '@nicolas-chaulet/openapi-typescript-codegen'

createClient({
input: 'path/to/openapi.json',
output: 'src/client',
})
```

> ⚠️ You need to be running Node.js v18 or newer
## Configuration
Expand Down
7 changes: 2 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ const params = program

async function start() {
try {
const OpenAPI = await import(new URL('../dist/index.js', import.meta.url));
await OpenAPI.generate({
...params,
clientName: params.name,
});
const { createClient } = await import(new URL('../dist/index.js', import.meta.url));
await createClient(params);
process.exit(0);
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"build-types-check": "tsc --project tsconfig.check.json",
"build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp",
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node",
"clean": "rimraf dist test/generated test/e2e/generated samples/generated coverage node_modules/.cache",
"clean": "rimraf dist test/generated test/e2e/generated coverage node_modules/.cache",
"eslint:fix": "eslint . --fix",
"eslint": "eslint .",
"prepublishOnly": "npm run build",
Expand Down
21 changes: 0 additions & 21 deletions samples/codegen.sh

This file was deleted.

Loading

0 comments on commit 872cae2

Please sign in to comment.