Skip to content

Commit

Permalink
Added operationIdFieldName option
Browse files Browse the repository at this point in the history
Related to #108

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
  • Loading branch information
Alan-Cha authored and ErikWittern committed Feb 19, 2019
1 parent 768edca commit 0eb6691
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 29 deletions.
21 changes: 11 additions & 10 deletions packages/oasgraph-cli/README.md
Expand Up @@ -24,16 +24,17 @@ npm i -g oasgraph-cli
Usage: oasgraph <OAS JSON file path or remote url> [options]
Options:
-V, --version output the version number
-p, --port <port> select the port where the server will start
-u, --url <url> select the base url which paths will be built on
-s, --strict throw an error if OASGraph cannot run without compensating for errors or missing data in the OAS
-a, --addSubOperations nest operations based on path hierarchy
-f, --fillEmptyResponses create placeholder schemas for operations with HTTP status code 204 (no response) rather than ignore them
--cors enable Cross-origin resource sharing (CORS)
--no-viewer do not create GraphQL viewer objects for passing authentication credentials
--save <file path> save schema to path and do not start server
-h, --help output usage information
-V, --version output the version number
-p, --port <port> select the port where the server will start
-u, --url <url> select the base url which paths will be built on
-s, --strict throw an error if OASGraph cannot run without compensating for errors or missing data in the OAS
-a, --addSubOperations nest operations based on path hierarchy
-f, --fillEmptyResponses create placeholder schemas for operations with HTTP status code 204 (no response) rather than ignore them
-o, --operationIdFieldNames create field names based on the operationId
--cors enable Cross-origin resource sharing (CORS)
--no-viewer do not create GraphQL viewer objects for passing authentication credentials
--save <file path> save schema to path and do not start server
-h, --help output usage information
```

The basic usage of the CLI takes the specified OAS, creates a GraphQL interface for it, and starts a server to host the GraphQL interface.
Expand Down
4 changes: 3 additions & 1 deletion packages/oasgraph-cli/lib/oasgraph.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/oasgraph-cli/lib/oasgraph.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/oasgraph-cli/package.json
Expand Up @@ -52,12 +52,12 @@
"request": "^2.88.0"
},
"devDependencies": {
"@types/node": "^10.12.0",
"jest": "^23.6.0",
"@types/node": "^11.9.4",
"jest": "^24.1.0",
"standard": "^12.0.1",
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.1.3"
"typescript": "^3.3.3"
},
"bin": {
"oasgraph": "./lib/oasgraph.js"
Expand Down
4 changes: 3 additions & 1 deletion packages/oasgraph-cli/src/oasgraph.ts
Expand Up @@ -26,6 +26,7 @@ program
.option('-s, --strict', 'throw an error if OASGraph cannot run without compensating for errors or missing data in the OAS')
.option('-a, --addSubOperations', 'nest operations based on path hierarchy')
.option('-f, --fillEmptyResponses', 'create placeholder schemas for operations with HTTP status code 204 (no response) rather than ignore them')
.option('-o, --operationIdFieldNames', 'create field names based on the operationId')
.option('--cors', 'enable Cross-origin resource sharing (CORS)')
.option('--no-viewer', 'do not create GraphQL viewer objects for passing authentication credentials')
.option('--save <file path>', 'save schema to path and do not start server')
Expand Down Expand Up @@ -118,7 +119,8 @@ function startGraphQLServer(oas, port) {
viewer: program.viewer,
addSubOperations: program.addSubOperations,
fillEmptyResponses: program.fillEmptyResponses,
baseUrl: program.url
baseUrl: program.url,
operationIdFieldNames: program.operationIdFieldNames
})
.then(({schema, report}) => {
console.log(JSON.stringify(report, null, 2))
Expand Down
2 changes: 2 additions & 0 deletions packages/oasgraph/README.md
Expand Up @@ -81,6 +81,8 @@ The options object can contain the following properties:

* `baseUrl` (type: `string`): Used to manual specify the base URL which all paths will be built on. Normally, OASGraph will select a base URL from the [server object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#serverObject) defined in the OAS. However, if the server object contains multiple URLs, OASGraph will randomly select one. The purpose of this option is to provide greater control over the base URL in these situations, especially when the OAS cannot be modified. This option may also prove to be useful in testing and development.

* `operationIdFieldNames` (type: `boolean`, default: `false`): By default, query field names are based on the return type type name and mutation field names are based on the [`operationId`](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operation-object), which may be generated if it does not exist. This option forces OASGraph to only create field names based on the operationId.

Consider this example of passing options:

```javascript
Expand Down
14 changes: 10 additions & 4 deletions packages/oasgraph/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0eb6691

Please sign in to comment.