Skip to content

Commit 003b49b

Browse files
committed
Add OpenAPI v3 support.
1 parent 0b2800d commit 003b49b

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ npx @api-platform/client-generator https://demo.api-platform.com/ output/ --reso
2727
npx @api-platform/client-generator https://demo.api-platform.com/docs.json output/ --resource Book --format swagger
2828
```
2929

30+
**Swagger** (experimental)
31+
```sh
32+
npx @api-platform/client-generator https://demo.api-platform.com/docs.json?spec_version=3 output/ --resource Book --format openapi3
33+
```
34+
3035
## Features
3136

3237
* 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"tmp": "^0.0.33"
3434
},
3535
"dependencies": {
36-
"@api-platform/api-doc-parser": "^0.7.2",
36+
"@api-platform/api-doc-parser": "^0.7.3",
3737
"babel-runtime": "^6.26.0",
3838
"chalk": "^2.4.1",
3939
"commander": "^2.18.0",

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

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# yarn lockfile v1
33

44

5-
"@api-platform/api-doc-parser@^0.7.2":
5+
"@api-platform/api-doc-parser@^0.7.3":
66
version "0.7.2"
77
resolved "https://registry.yarnpkg.com/@api-platform/api-doc-parser/-/api-doc-parser-0.7.2.tgz#c5ca5913fa6ee319016a635df5225e0db5ecc9ab"
88
integrity sha512-FHzAldq1/ZZZhRyI8sgfxIrf3NtKLNgaW6P8Z12cjK3qWDuYCjsQZ1H2Z4WGZk0tGhDxA3lVJXcw4HHD5kjTrQ==

0 commit comments

Comments
 (0)