Skip to content

Commit 7a01062

Browse files
authored
Minor improvments to JS apollo generator (#5714)
* minor improvments to js apollo generator * comment out apollo
1 parent 94b962e commit 7a01062

41 files changed

Lines changed: 4141 additions & 29 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g javascript-apollo -o samples\client\petstore\javascript-apollo --additional-properties appName=PetstoreClient
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The following generators are available:
3333
* [haskell-http-client](generators/haskell-http-client.md)
3434
* [java](generators/java.md)
3535
* [javascript](generators/javascript.md)
36+
* [javascript-apollo (beta)](generators/javascript-apollo.md)
3637
* [javascript-closure-angular](generators/javascript-closure-angular.md)
3738
* [javascript-flowtyped](generators/javascript-flowtyped.md)
3839
* [jaxrs-cxf-client](generators/jaxrs-cxf-client.md)

docs/generators/javascript-apollo.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@ sidebar_label: javascript-apollo
66
| Option | Description | Values | Default |
77
| ------ | ----------- | ------ | ------- |
88
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
9+
|apiPackage|package for generated api classes| |null|
10+
|emitJSDoc|generate JSDoc comments| |true|
911
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
10-
|enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat|
11-
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase|
12-
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original|
13-
|npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null|
12+
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
13+
|invokerPackage|root package for generated code| |null|
14+
|licenseName|name of the license the project uses (Default: using info.license.name)| |null|
15+
|modelPackage|package for generated models| |null|
16+
|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase|
17+
|moduleName|module name for AMD, Node or globals (Default: generated from <projectName>)| |null|
1418
|npmRepository|Use this property to set an url your private npmRepo in the package.json| |null|
15-
|npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0|
16-
|nullSafeAdditionalProps|Set to make additional properties types declare that their indexer may return undefined| |false|
1719
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
18-
|snapshot|When setting this property to true, the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm| |false|
20+
|projectDescription|description of the project (Default: using info.description or "Client library of <projectName>")| |null|
21+
|projectName|name of the project (Default: generated from info.title or "openapi-js-client")| |null|
22+
|projectVersion|version of the project (Default: using info.version or "1.0.0")| |null|
1923
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
2024
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
25+
|sourceFolder|source folder for generated code| |src|
26+
|useInheritance|use JavaScript prototype chains & delegation for inheritance| |true|
2127

2228
## IMPORT MAPPING
2329

@@ -39,12 +45,12 @@ sidebar_label: javascript-apollo
3945
<ul class="column-ul">
4046
<li>Array</li>
4147
<li>Blob</li>
48+
<li>Boolean</li>
4249
<li>Date</li>
4350
<li>File</li>
51+
<li>Number</li>
4452
<li>Object</li>
45-
<li>boolean</li>
46-
<li>number</li>
47-
<li>string</li>
53+
<li>String</li>
4854
</ul>
4955

5056
## RESERVED WORDS
@@ -78,11 +84,9 @@ sidebar_label: javascript-apollo
7884
<li>finally</li>
7985
<li>float</li>
8086
<li>for</li>
81-
<li>formparams</li>
8287
<li>function</li>
8388
<li>goto</li>
8489
<li>hasownproperty</li>
85-
<li>headerparams</li>
8690
<li>if</li>
8791
<li>implements</li>
8892
<li>import</li>
@@ -108,8 +112,6 @@ sidebar_label: javascript-apollo
108112
<li>protected</li>
109113
<li>prototype</li>
110114
<li>public</li>
111-
<li>queryparameters</li>
112-
<li>requestoptions</li>
113115
<li>return</li>
114116
<li>short</li>
115117
<li>static</li>
@@ -126,11 +128,8 @@ sidebar_label: javascript-apollo
126128
<li>try</li>
127129
<li>typeof</li>
128130
<li>undefined</li>
129-
<li>useformdata</li>
130131
<li>valueof</li>
131132
<li>var</li>
132-
<li>varlocaldeferred</li>
133-
<li>varlocalpath</li>
134133
<li>void</li>
135134
<li>volatile</li>
136135
<li>while</li>
@@ -144,7 +143,7 @@ sidebar_label: javascript-apollo
144143
### Client Modification Feature
145144
| Name | Supported | Defined By |
146145
| ---- | --------- | ---------- |
147-
|BasePath||ToolingExtension
146+
|BasePath||ToolingExtension
148147
|Authorizations|✗|ToolingExtension
149148
|UserAgent|✗|ToolingExtension
150149

@@ -204,7 +203,7 @@ sidebar_label: javascript-apollo
204203
|MultiServer|✗|OAS3
205204
|ParameterizedServer|✗|OAS3
206205
|ParameterStyling|✗|OAS3
207-
|Callbacks||OAS3
206+
|Callbacks||OAS3
208207
|LinkObjects|✗|OAS3
209208

210209
### Parameter Feature
@@ -229,14 +228,14 @@ sidebar_label: javascript-apollo
229228
### Security Feature
230229
| Name | Supported | Defined By |
231230
| ---- | --------- | ---------- |
232-
|BasicAuth||OAS2,OAS3
233-
|ApiKey||OAS2,OAS3
231+
|BasicAuth||OAS2,OAS3
232+
|ApiKey||OAS2,OAS3
234233
|OpenIDConnect|✗|OAS3
235-
|BearerToken||OAS3
236-
|OAuth2_Implicit||OAS2,OAS3
237-
|OAuth2_Password||OAS2,OAS3
238-
|OAuth2_ClientCredentials||OAS2,OAS3
239-
|OAuth2_AuthorizationCode||OAS2,OAS3
234+
|BearerToken||OAS3
235+
|OAuth2_Implicit||OAS2,OAS3
236+
|OAuth2_Password||OAS2,OAS3
237+
|OAuth2_ClientCredentials||OAS2,OAS3
238+
|OAuth2_AuthorizationCode||OAS2,OAS3
240239

241240
### Wire Format Feature
242241
| Name | Supported | Defined By |

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
3-
* Copyright 2018 SmartBear Software
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
65
* you may not use this file except in compliance with the License.
@@ -25,6 +24,8 @@
2524
import org.apache.commons.io.FilenameUtils;
2625
import org.apache.commons.lang3.StringUtils;
2726
import org.openapitools.codegen.*;
27+
import org.openapitools.codegen.meta.GeneratorMetadata;
28+
import org.openapitools.codegen.meta.Stability;
2829
import org.openapitools.codegen.meta.features.DocumentationFeature;
2930
import org.openapitools.codegen.utils.ModelUtils;
3031
import org.slf4j.Logger;
@@ -90,6 +91,10 @@ public JavascriptApolloClientCodegen() {
9091

9192
modifyFeatureSet(features -> features.includeDocumentationFeatures(DocumentationFeature.Readme));
9293

94+
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
95+
.stability(Stability.BETA)
96+
.build();
97+
9398
outputFolder = "generated-code/js";
9499
modelTemplateFiles.put("model.mustache", ".js");
95100
modelTestTemplateFiles.put("model_test.mustache", ".js");
@@ -199,7 +204,7 @@ public String getName() {
199204

200205
@Override
201206
public String getHelp() {
202-
return "Generates a JavaScript client library using Apollo RESTDatasource.";
207+
return "Generates a JavaScript client library (beta) using Apollo RESTDatasource.";
203208
}
204209

205210
@Override

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@
12391239
<module>samples/server/petstore/php-slim</module>
12401240
<module>samples/server/petstore/php-slim4</module>
12411241
<module>samples/client/petstore/javascript</module>
1242-
<module>samples/client/petstore/javascript-apollo</module>
1242+
<!--<module>samples/client/petstore/javascript-apollo</module>-->
12431243
<module>samples/client/petstore/javascript-es6</module>
12441244
<module>samples/openapi3/client/petstore/javascript-es6</module>
12451245
<module>samples/client/petstore/javascript-promise</module>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4.3.0-SNAPSHOT
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
cache: npm
3+
node_js:
4+
- "6"
5+
- "6.1"
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# open_api_petstore
2+
3+
OpenApiPetstore - JavaScript client for open_api_petstore
4+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
5+
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
6+
7+
- API version: 1.0.0
8+
- Package version: 1.0.0
9+
- Build package: org.openapitools.codegen.languages.JavascriptApolloClientCodegen
10+
11+
## Installation
12+
13+
### For [Node.js](https://nodejs.org/)
14+
15+
#### npm
16+
17+
To publish the library as a [npm](https://www.npmjs.com/), please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages).
18+
19+
Then install it via:
20+
21+
```shell
22+
npm install open_api_petstore --save
23+
```
24+
25+
Finally, you need to build the module:
26+
27+
```shell
28+
npm run build
29+
```
30+
31+
##### Local development
32+
33+
To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing `package.json` (and this README). Let's call this `JAVASCRIPT_CLIENT_DIR`. Then run:
34+
35+
```shell
36+
npm install
37+
```
38+
39+
Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`:
40+
41+
```shell
42+
npm link
43+
```
44+
45+
To use the link you just defined in your project, switch to the directory you want to use your open_api_petstore from, and run:
46+
47+
```shell
48+
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>
49+
```
50+
51+
Finally, you need to build the module:
52+
53+
```shell
54+
npm run build
55+
```
56+
57+
#### git
58+
59+
If the library is hosted at a git repository, e.g.https://github.com/GIT_USER_ID/GIT_REPO_ID
60+
then install it via:
61+
62+
```shell
63+
npm install GIT_USER_ID/GIT_REPO_ID --save
64+
```
65+
66+
### For browser
67+
68+
The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following
69+
the above steps with Node.js and installing browserify with `npm install -g browserify`,
70+
perform the following (assuming *main.js* is your entry file):
71+
72+
```shell
73+
browserify main.js > bundle.js
74+
```
75+
76+
Then include *bundle.js* in the HTML pages.
77+
78+
### Webpack Configuration
79+
80+
Using Webpack you may encounter the following error: "Module not found: Error:
81+
Cannot resolve module", most certainly you should disable AMD loader. Add/merge
82+
the following section to your webpack config:
83+
84+
```javascript
85+
module: {
86+
rules: [
87+
{
88+
parser: {
89+
amd: false
90+
}
91+
}
92+
]
93+
}
94+
```
95+
96+
## Getting Started
97+
98+
Please follow the [installation](#installation) instruction and execute the following JS code:
99+
100+
```javascript
101+
var OpenApiPetstore = require('open_api_petstore');
102+
103+
var defaultClient = OpenApiPetstore.ApiClient.instance;
104+
// Configure OAuth2 access token for authorization: petstore_auth
105+
var petstore_auth = defaultClient.authentications['petstore_auth'];
106+
petstore_auth.accessToken = "YOUR ACCESS TOKEN"
107+
108+
var api = new OpenApiPetstore.PetApi()
109+
var body = new OpenApiPetstore.Pet(); // {Pet} Pet object that needs to be added to the store
110+
var callback = function(error, data, response) {
111+
if (error) {
112+
console.error(error);
113+
} else {
114+
console.log('API called successfully.');
115+
}
116+
};
117+
api.addPet(body, callback);
118+
119+
```
120+
121+
## Documentation for API Endpoints
122+
123+
All URIs are relative to *http://petstore.swagger.io/v2*
124+
125+
Class | Method | HTTP request | Description
126+
------------ | ------------- | ------------- | -------------
127+
*OpenApiPetstore.PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store
128+
*OpenApiPetstore.PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
129+
*OpenApiPetstore.PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
130+
*OpenApiPetstore.PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
131+
*OpenApiPetstore.PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID
132+
*OpenApiPetstore.PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet
133+
*OpenApiPetstore.PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
134+
*OpenApiPetstore.PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
135+
*OpenApiPetstore.StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID
136+
*OpenApiPetstore.StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status
137+
*OpenApiPetstore.StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID
138+
*OpenApiPetstore.StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet
139+
*OpenApiPetstore.UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user
140+
*OpenApiPetstore.UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array
141+
*OpenApiPetstore.UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array
142+
*OpenApiPetstore.UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user
143+
*OpenApiPetstore.UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name
144+
*OpenApiPetstore.UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system
145+
*OpenApiPetstore.UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session
146+
*OpenApiPetstore.UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user
147+
148+
149+
## Documentation for Models
150+
151+
- [OpenApiPetstore.ApiResponse](docs/ApiResponse.md)
152+
- [OpenApiPetstore.Category](docs/Category.md)
153+
- [OpenApiPetstore.Order](docs/Order.md)
154+
- [OpenApiPetstore.Pet](docs/Pet.md)
155+
- [OpenApiPetstore.Tag](docs/Tag.md)
156+
- [OpenApiPetstore.User](docs/User.md)
157+
158+
159+
## Documentation for Authorization
160+
161+
162+
163+
### api_key
164+
165+
166+
- **Type**: API key
167+
- **API key parameter name**: api_key
168+
- **Location**: HTTP header
169+
170+
171+
172+
### petstore_auth
173+
174+
175+
- **Type**: OAuth
176+
- **Flow**: implicit
177+
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
178+
- **Scopes**:
179+
- write:pets: modify pets in your account
180+
- read:pets: read your pets
181+

0 commit comments

Comments
 (0)