-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed dependency on node-fetch
- Loading branch information
1 parent
cf6edc0
commit bf0ca91
Showing
2 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ This repository is the JavaScript generator for the [OpenAPI Forge](https://gith | |
|
||
https://github.com/ScottLogic/openapi-forge | ||
|
||
The client API it generates is suitable for running in the browser (after being bundled appropriately), or via node. The generated code uses the Fetch API, and as a result you'll need to use node v18 or greater. | ||
|
||
## Example | ||
|
||
You should consult the [OpenAPI Forge](https://github.com/ScottLogic/openapi-forge) repository for a complete user guide. The following is a very brief example that quikcly gets you up-and-running with this generator. | ||
|
@@ -17,19 +19,16 @@ $ openapi-forge forge \ | |
-o api | ||
``` | ||
|
||
This will generate various files in the `api` folder. The API depends on the node-fetch module, which provides Fetch API for node applications. To run this client you'll need to add that as a dependency: | ||
This will generate various files in the `api` folder. | ||
|
||
``` | ||
% npm init -y --silent | ||
% npm i [email protected] | ||
``` | ||
### Running with node (>= v18) | ||
|
||
Finally, add the following `index.js` in the `api` folder: | ||
Add the following `index.js` in the `api` folder: | ||
|
||
```javascript | ||
const ApiPet = require("./apiPet"); | ||
const Configuration = require("./configuration"); | ||
const transport = require("./nodeFetch"); | ||
const transport = require("./fetch"); | ||
|
||
// create an API client | ||
const config = new Configuration(transport); | ||
|
@@ -56,6 +55,24 @@ To test the API, this example adds a Pet named “Fido” to the Pet Store, then | |
Fido | ||
``` | ||
|
||
### Running in the browser | ||
|
||
You'll need to bundle the files into a single script, there are various tools that can be used for this purpose, but browserify is one of the simplest: | ||
|
||
``` | ||
% npx browserify index.js -o bundle.js | ||
``` | ||
|
||
Next create a simple HTML file that loads this script: | ||
|
||
``` | ||
<html> | ||
<script src="bundle.js"></script> | ||
</html> | ||
``` | ||
|
||
Load the above page in a browser and you should see `Fido` logged to the console. | ||
|
||
## Development | ||
|
||
The OpenAPI Forge project [details the process for creating a new generator](https://github.com/ScottLogic/openapi-forge#generator-development). The documentation gives a few generator-specific instructions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters