Skip to content

Commit b110b22

Browse files
committed
- Removed javascript generation
1 parent e0b68a3 commit b110b22

File tree

90 files changed

+2795
-6937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2795
-6937
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
[![Build Status](https://badgen.net/travis/ferdikoomen/openapi-typescript-codegen/master)](https://travis-ci.org/ferdikoomen/openapi-typescript-codegen)
66
[![Quality](https://badgen.net/lgtm/grade/javascript/g/ferdikoomen/openapi-typescript-codegen)](https://lgtm.com/projects/g/ferdikoomen/openapi-typescript-codegen)
77

8-
> NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification.
8+
> NodeJS library that generates Typescript clients based on the OpenAPI specification.
99
1010
#### Why?
1111
- Frontend ❤️ OpenAPI, but we do not want to use JAVA codegen in our builds.
1212
- Quick, lightweight, robust and framework agnostic.
13-
- Supports generation of Typescript and Javascript clients.
13+
- Supports generation of Typescript clients.
1414
- Supports generations of fetch and XHR http clients.
1515
- Supports OpenAPI specification v2.0 and v3.0.
1616
- Supports JSON and YAML files for input.
@@ -20,7 +20,7 @@
2020
- If you use enums inside your models / definitions then those enums are now
2121
inside a namespace with the same name as your model. This is called declaration
2222
merging. However Babel 7 now support compiling of Typescript and right now they
23-
do not support namespaces.
23+
do not support namespaces.
2424

2525

2626
## Installation
@@ -41,7 +41,7 @@ npm install openapi-typescript-codegen --save-dev
4141
}
4242
```
4343

44-
Command line
44+
Command line
4545

4646
```
4747
npm install openapi-typescript-codegen -g
@@ -54,10 +54,8 @@ NodeJS API:
5454
```
5555
const OpenAPI = require('openapi-typescript-codegen');
5656
57-
const result = OpenAPI.generate(
57+
OpenAPI.generate(
5858
'./api/openapi.json',
5959
'./dist'
6060
);
61-
62-
console.log(result);
6361
```

bin/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ program
1010
.version(pkg.version)
1111
.option('--input [value]', 'Path to swagger specification', './spec.json')
1212
.option('--output [value]', 'Output directory', './generated')
13-
.option('--language [value]', 'Language to generate [typescript, javascript]', 'typescript')
1413
.option('--http-client [value]', 'HTTP client to generate [fetch, xhr]', 'fetch')
1514
.parse(process.argv);
1615

@@ -20,7 +19,6 @@ if (SwaggerCodegen) {
2019
SwaggerCodegen.generate(
2120
program.input,
2221
program.output,
23-
program.language,
2422
program.httpClient
2523
);
2624
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
"dist/index.d.ts",
4444
"dist/**/*.js",
4545
"dist/**/*.d.ts",
46-
"src/templates/javascript/**/*.hbs",
47-
"src/templates/javascript/**/*.js",
48-
"src/templates/typescript/**/*.hbs",
49-
"src/templates/typescript/**/*.ts"
46+
"src/templates/**/*.hbs",
47+
"src/templates/**/*.ts"
5048
],
5149
"scripts": {
5250
"clean": "rimraf \"./dist\" \"./coverage\" \"./test/result\"",

src/index.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import { parse as parseV3 } from './openApi/v3';
77
import { readHandlebarsTemplates } from './utils/readHandlebarsTemplates';
88
import { writeClient } from './utils/writeClient';
99

10-
export enum Language {
11-
TYPESCRIPT = 'typescript',
12-
JAVASCRIPT = 'javascript',
13-
}
14-
1510
export enum HttpClient {
1611
FETCH = 'fetch',
1712
XHR = 'xhr',
@@ -23,10 +18,9 @@ export enum HttpClient {
2318
* service layer, etc.
2419
* @param input The relative location of the OpenAPI spec.
2520
* @param output The relative location of the output directory.
26-
* @param language: The language that should be generated (Typescript or Javascript).
2721
* @param httpClient: The selected httpClient (fetch or XHR).
2822
*/
29-
export function generate(input: string, output: string, language: Language = Language.TYPESCRIPT, httpClient: HttpClient = HttpClient.FETCH): void {
23+
export function generate(input: string, output: string, httpClient: HttpClient = HttpClient.FETCH): void {
3024
const inputPath = path.resolve(process.cwd(), input);
3125
const outputPath = path.resolve(process.cwd(), output);
3226

@@ -35,22 +29,18 @@ export function generate(input: string, output: string, language: Language = Lan
3529
// handlebar templates for the given language
3630
const openApi = getOpenApiSpec(inputPath);
3731
const openApiVersion = getOpenApiVersion(openApi);
38-
const templates = readHandlebarsTemplates(language);
32+
const templates = readHandlebarsTemplates();
3933

40-
switch (language) {
41-
case Language.JAVASCRIPT:
42-
case Language.TYPESCRIPT:
43-
// Generate and write version 2 client
44-
if (openApiVersion === OpenApiVersion.V2) {
45-
const clientV2 = parseV2(openApi);
46-
writeClient(clientV2, language, httpClient, templates, outputPath);
47-
}
34+
switch (openApiVersion) {
35+
case OpenApiVersion.V2:
36+
const clientV2 = parseV2(openApi);
37+
writeClient(clientV2, httpClient, templates, outputPath);
38+
break;
4839

49-
// Generate and write version 3 client
50-
if (openApiVersion === OpenApiVersion.V3) {
51-
const clientV3 = parseV3(openApi);
52-
writeClient(clientV3, language, httpClient, templates, outputPath);
53-
}
40+
case OpenApiVersion.V3:
41+
const clientV3 = parseV3(openApi);
42+
writeClient(clientV3, httpClient, templates, outputPath);
43+
break;
5444
}
5545
} catch (e) {
5646
console.error(e);
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)