Skip to content

Commit

Permalink
chore: update the codebase (#1)
Browse files Browse the repository at this point in the history
* chore: init

* chore: init

* chore: init

* chore: init

* chore: init

* chore: init

* chore: init

* chore: init

* chore: init

* chore: init
  • Loading branch information
vkbansal authored Aug 23, 2022
1 parent f94ba0a commit 46589ed
Show file tree
Hide file tree
Showing 151 changed files with 5,111 additions and 9,378 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = 2

[*.{yml,yaml,md,toml}]
indent_style = space
indent_size = 2
12 changes: 10 additions & 2 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ parserOptions:
ecmaFeatures:
jsx: true
impliedStrict: true
project: ./tsconfig-eslint.json
project: ./tsconfig.json
plugins:
- '@typescript-eslint/eslint-plugin'
- import
settings:
import/resolver:
typescript: true
node: true
env:
browser: true
node: true
Expand All @@ -19,10 +24,11 @@ extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
- prettier
- plugin:import/recommended
- plugin:import/typescript
rules:
# built-in
semi: [2, 'always']
no-await-in-loop: 2
no-shadow: 2

#typescript
Expand All @@ -38,6 +44,8 @@ rules:
ignoreRestSiblings: true
argsIgnorePattern: ^_
'@typescript-eslint/member-delimiter-style': 0

'import/no-cycle': 2
overrides:
- files:
- bin/**/*.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage
dist/
.idea/
temp/
*.log
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
strict-peer-dependencies=false
enable-pre-post-scripts=true
19 changes: 19 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
printWidth: 100,
tabWidth: 2,
useTabs: true,
semi: true,
singleQuote: true,
trailingComma: 'all',
bracketSpacing: true,
arrowParens: 'always',
overrides: [
{
files: ['*.yml', '*.yaml', '*.md', '*.toml', '*.json'],
options: {
tabWidth: 2,
useTabs: false,
},
},
],
};
10 changes: 0 additions & 10 deletions .prettierrc.yml

This file was deleted.

43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# Swagger to TS
# OpenAPI to TypeScript

Command-line utilities for converting OpenAPI (formerly Swagger) definitions to TypeScript.
Command-line utility for converting OpenAPI (formerly Swagger) definitions to TypeScript.

## Installation

WIP

## Usage

```
Usage: oa2ts <cmd> [args]
Commands:
oa2ts import Import OpenAPI specification and output TypeScript code
Options:
--version Show version number [boolean]
--help Show help [boolean]
```

### Available commands

### import

```
oa2ts import
Import OpenAPI specification and output TypeScript code
Options:
--version Show version number [boolean]
--help Show help [boolean]
--file Path to OpenAPI spec file. Can be either a JSON or YAML file.
[string]
--url URL to remote OpenAPI spec file. [string]
-o, --output Location for the output. [string]
-c, --config Location for the config file. [string]
--verbose Shows verbose output [boolean]
```
25 changes: 0 additions & 25 deletions jest.config.js

This file was deleted.

31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,31 @@
"private": true,
"version": "0.1.0",
"license": "MIT",
"type": "module",
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"workspaces": [
"packages/*"
],
"dependencies": {
"typescript": "^4.2.4"
"scripts": {
"build": "exit 0",
"fmt": "prettier --write packages/*/src/**/*.ts"
},
"devDependencies": {
"@jest/globals": "^26.6.2",
"@types/js-yaml": "^4.0.1",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.22.1",
"@typescript-eslint/parser": "^4.22.1",
"eslint": "^7.26.0",
"@types/node": "^18.7.8",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"lint-staged": "^11.0.0",
"eslint-import-resolver-typescript": "^3.4.2",
"eslint-plugin-import": "^2.26.0",
"globby": "^13.1.2",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.6",
"ts-node": "^9.1.1"
"typescript": "^4.2.4",
"vitest": "^0.22.1"
}
}
21 changes: 21 additions & 0 deletions packages/cli/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Vivek Kumar Bansal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# oa2ts CLI

Package for the `oa2ts` CLI
2 changes: 2 additions & 0 deletions packages/cli/bin/oa2ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#! /usr/bin/env node
import '../dist/cli.js';
49 changes: 49 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@oa2ts/cli",
"version": "0.1.0",
"license": "MIT",
"type": "module",
"author": {
"name": "Vivek Kumar Bansal",
"email": "[email protected]"
},
"bin": {
"oa2ts": "./bin/oa2ts.js"
},
"exports": {
"./config": "./dist/config.js",
"./plugin": "./dist/plugin.js",
"./nameHelpers": "./dist/nameHelpers.js",
"./pathHelpers": "./dist/pathHelpers.js",
"./codegen": "./dist/codegen.js"
},
"imports": {
"#@oa2ts/cli/config": "./dist/config.js",
"#@oa2ts/cli/plugin": "./dist/plugin.js"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc --outDir dist"
},
"engines": {
"node": ">=16.0.0"
},
"dependencies": {
"chalk": "^5.0.1",
"esbuild": "^0.15.5",
"js-yaml": "^4.1.0",
"node-fetch": "^3.2.10",
"openapi3-ts": "^3.0.1",
"pascal-case": "^3.1.2",
"prettier": "^2.2.1",
"swagger2openapi": "^7.0.5",
"yargs": "^17.0.1",
"yup": "^0.32.11"
},
"devDependencies": {
"@types/prettier": "^2.7.0",
"@types/yargs": "^17.0.11",
"rimraf": "^3.0.2",
"typescript": "^4.2.4"
}
}
71 changes: 71 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { generateSpec } from './generateSpec.js';
import type { CLIConfig } from './config.js';
import { logError } from './helpers.js';

const NAME = 'oa2ts';

yargs(hideBin(process.argv))
.scriptName(NAME)
.usage('Usage: $0 <cmd> [args]')
.command(
'import',
'Import OpenAPI specification and output TypeScript code',
(args) => {
return args
.option('file', {
type: 'string',
describe: 'Path to OpenAPI spec file. Can be either a JSON or YAML file.',
})
.option('url', {
type: 'string',
describe: 'URL to remote OpenAPI spec file.',
})
.option('output', {
type: 'string',
alias: 'o',
describe: 'Location for the output.',
})
.option('config', {
type: 'string',
alias: 'c',
describe: 'Location for the config file.',
})
.option('verbose', {
type: 'boolean',
describe: 'Shows verbose output',
})
.conflicts('file', 'url')
.check((argv) => {
if (argv.config) return true;

if (!argv.output) {
throw new Error('Missing required argument: output');
}

if (!argv.file && !argv.url) {
throw new Error('Either "--file" or "--url" is required');
}

return true;
});
},
(argv) => {
return generateSpec(argv as CLIConfig);
},
)
.help()
.fail((msg, err) => {
if (msg) {
logError(msg);
}

if (err) {
throw err; // preserve stack
}

process.exit(1);
})
.demandCommand().argv;
Loading

0 comments on commit 46589ed

Please sign in to comment.