Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"plugins": [
"transform-runtime",
"transform-flow-strip-types"
"@babel/transform-runtime",
"@babel/transform-flow-strip-types",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-class-properties"
],
"presets": [
"es2015",
"stage-0"
"@babel/preset-env"
]
}
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm version](https://badge.fury.io/js/%40api-platform%2Fclient-generator.svg)](https://badge.fury.io/js/%40api-platform%2Fclient-generator)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)

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:
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:
* React/Redux
* React Native
* Vue.js
Expand All @@ -22,11 +22,22 @@ The documentation of API Platform's Client Generator can be browsed [on the offi
npx @api-platform/client-generator https://demo.api-platform.com/ output/ --resource Book
```

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

or

```sh
npx @api-platform/client-generator https://demo.api-platform.com/docs.json output/ --resource Book --format openapi2
```

**OpenAPI v3** (experimental)
```sh
npx @api-platform/client-generator https://demo.api-platform.com/docs.json?spec_version=3 output/ --resource Book --format openapi3
```

## Features

* 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:
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@
"author": "Kévin Dunglas",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"babel-eslint": "^10.0.0",
"babel-jest": "^23.6.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-jest": "^24.0.0",
"eslint": "^5.6.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.6.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^2.6.2",
"jest": "^23.6.0",
"jest": "^24.0.0",
"prettier": "^1.14.3",
"tmp": "^0.0.33"
},
"dependencies": {
"@api-platform/api-doc-parser": "^0.7.2",
"babel-runtime": "^6.26.0",
"@api-platform/api-doc-parser": "^0.8.0",
"@babel/runtime": "^7.0.0",
"chalk": "^2.4.1",
"commander": "^2.18.0",
"handlebars": "^4.0.12",
Expand Down
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "isomorphic-fetch";
import program from "commander";
import parseHydraDocumentation from "@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation";
import parseSwaggerDocumentation from "@api-platform/api-doc-parser/lib/swagger/parseSwaggerDocumentation";
import parseOpenApi3Documentation from "@api-platform/api-doc-parser/lib/openapi3/parseOpenApi3Documentation";
import { version } from "../package.json";
import generators from "./generators";

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

const parser = entrypointWithSlash => {
const parseDocumentation =
"swagger" === program.format
? parseSwaggerDocumentation
: parseHydraDocumentation;

return parseDocumentation(entrypointWithSlash);
switch (program.format) {
case "swagger":
return parseSwaggerDocumentation(entrypointWithSlash);
case "openapi3":
return parseOpenApi3Documentation(entrypointWithSlash);
default:
return parseHydraDocumentation(entrypointWithSlash);
}
};

// check generator dependencies
Expand Down
Loading