Skip to content

Commit 31a14da

Browse files
authored
Merge pull request #146 from bpolaszek/openapi3
Add OpenAPI v3 support.
2 parents d5ccc01 + af0cd07 commit 31a14da

File tree

5 files changed

+1972
-1816
lines changed

5 files changed

+1972
-1816
lines changed

.babelrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"plugins": [
3-
"transform-runtime",
4-
"transform-flow-strip-types"
3+
"@babel/transform-runtime",
4+
"@babel/transform-flow-strip-types",
5+
"@babel/plugin-proposal-export-default-from",
6+
"@babel/plugin-proposal-class-properties"
57
],
68
"presets": [
7-
"es2015",
8-
"stage-0"
9+
"@babel/preset-env"
910
]
1011
}

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![npm version](https://badge.fury.io/js/%40api-platform%2Fclient-generator.svg)](https://badge.fury.io/js/%40api-platform%2Fclient-generator)
55
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)
66

7-
API Platform Client Generator is a generator to scaffold app with Create-Retrieve-Update-Delete features for any API exposing a Hydra or Swagger documentation for:
7+
API Platform Client Generator is a generator to scaffold app with Create-Retrieve-Update-Delete features for any API exposing a [Hydra](http://www.hydra-cg.com/spec/latest/core/) or [OpenAPI](https://www.openapis.org/) documentation for:
88
* React/Redux
99
* React Native
1010
* Vue.js
@@ -22,11 +22,22 @@ The documentation of API Platform's Client Generator can be browsed [on the offi
2222
npx @api-platform/client-generator https://demo.api-platform.com/ output/ --resource Book
2323
```
2424

25-
**OpenAPI** (experimental)
25+
**OpenAPI v2 (formerly known as Swagger)** (experimental)
2626
```sh
2727
npx @api-platform/client-generator https://demo.api-platform.com/docs.json output/ --resource Book --format swagger
2828
```
2929

30+
or
31+
32+
```sh
33+
npx @api-platform/client-generator https://demo.api-platform.com/docs.json output/ --resource Book --format openapi2
34+
```
35+
36+
**OpenAPI v3** (experimental)
37+
```sh
38+
npx @api-platform/client-generator https://demo.api-platform.com/docs.json?spec_version=3 output/ --resource Book --format openapi3
39+
```
40+
3041
## Features
3142

3243
* Generate high-quality ES6 components and files built with [React](https://facebook.github.io/react/), [Redux](http://redux.js.org), [React Router](https://reacttraining.com/react-router/) and [Redux Form](http://redux-form.com/) including:

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,26 @@
1616
"author": "Kévin Dunglas",
1717
"license": "MIT",
1818
"devDependencies": {
19-
"babel-cli": "^6.26.0",
20-
"babel-core": "^6.26.3",
19+
"@babel/cli": "^7.0.0",
20+
"@babel/core": "^7.0.0",
2121
"babel-eslint": "^10.0.0",
22-
"babel-jest": "^23.6.0",
23-
"babel-plugin-transform-flow-strip-types": "^6.22.0",
24-
"babel-plugin-transform-runtime": "^6.23.0",
25-
"babel-preset-es2015": "^6.24.1",
26-
"babel-preset-stage-0": "^6.24.1",
22+
"babel-jest": "^24.0.0",
2723
"eslint": "^5.6.0",
24+
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
25+
"@babel/plugin-transform-runtime": "^7.0.0",
26+
"@babel/plugin-proposal-export-default-from": "^7.0.0",
27+
"@babel/plugin-proposal-class-properties": "^7.0.0",
28+
"@babel/preset-env": "^7.6.0",
2829
"eslint-config-prettier": "^3.1.0",
2930
"eslint-plugin-import": "^2.14.0",
3031
"eslint-plugin-prettier": "^2.6.2",
31-
"jest": "^23.6.0",
32+
"jest": "^24.0.0",
3233
"prettier": "^1.14.3",
3334
"tmp": "^0.0.33"
3435
},
3536
"dependencies": {
36-
"@api-platform/api-doc-parser": "^0.7.2",
37-
"babel-runtime": "^6.26.0",
37+
"@api-platform/api-doc-parser": "^0.8.0",
38+
"@babel/runtime": "^7.0.0",
3839
"chalk": "^2.4.1",
3940
"commander": "^2.18.0",
4041
"handlebars": "^4.0.12",

src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "isomorphic-fetch";
44
import program from "commander";
55
import parseHydraDocumentation from "@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation";
66
import parseSwaggerDocumentation from "@api-platform/api-doc-parser/lib/swagger/parseSwaggerDocumentation";
7+
import parseOpenApi3Documentation from "@api-platform/api-doc-parser/lib/openapi3/parseOpenApi3Documentation";
78
import { version } from "../package.json";
89
import generators from "./generators";
910

@@ -66,12 +67,14 @@ const resourceToGenerate = program.resource
6667
const serverPath = program.serverPath ? program.serverPath.toLowerCase() : null;
6768

6869
const parser = entrypointWithSlash => {
69-
const parseDocumentation =
70-
"swagger" === program.format
71-
? parseSwaggerDocumentation
72-
: parseHydraDocumentation;
73-
74-
return parseDocumentation(entrypointWithSlash);
70+
switch (program.format) {
71+
case "swagger":
72+
return parseSwaggerDocumentation(entrypointWithSlash);
73+
case "openapi3":
74+
return parseOpenApi3Documentation(entrypointWithSlash);
75+
default:
76+
return parseHydraDocumentation(entrypointWithSlash);
77+
}
7578
};
7679

7780
// check generator dependencies

0 commit comments

Comments
 (0)