Skip to content

Commit fd32280

Browse files
Alan-ChaErikWittern
authored andcommitted
Add provideErrorExtensions option to CLI
Signed-off-by: Alan Cha <[email protected]>
1 parent c8c28d0 commit fd32280

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

packages/oasgraph-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Options:
3232
-o, --operationIdFieldNames create field names based on the operationId
3333
--cors enable Cross-origin resource sharing (CORS)
3434
--no-viewer do not create GraphQL viewer objects for passing authentication credentials
35+
--no-extensions do not add extentions, containing information about failed REST calls, to the GraphQL errors objects
3536
--save <file path> save schema to path and do not start server
3637
-h, --help output usage information
3738
```

packages/oasgraph-cli/lib/oasgraph.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/oasgraph-cli/lib/oasgraph.js.map

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/oasgraph-cli/src/oasgraph.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ program
2525
.option('-o, --operationIdFieldNames', 'create field names based on the operationId')
2626
.option('--cors', 'enable Cross-origin resource sharing (CORS)')
2727
.option('--no-viewer', 'do not create GraphQL viewer objects for passing authentication credentials')
28+
.option('--no-extensions', 'do not add extentions, containing information about failed REST calls, to the GraphQL errors objects')
2829
.option('--save <file path>', 'save schema to path and do not start server')
2930
.parse(process.argv)
3031

@@ -136,7 +137,8 @@ function startGraphQLServer(oas, port) {
136137
viewer: program.viewer,
137138
fillEmptyResponses: program.fillEmptyResponses,
138139
baseUrl: program.url,
139-
operationIdFieldNames: program.operationIdFieldNames
140+
operationIdFieldNames: program.operationIdFieldNames,
141+
provideErrorExtensions: program.extensions
140142
})
141143
.then(({schema, report}) => {
142144
console.log(JSON.stringify(report, null, 2))

packages/oasgraph/lib/types/options.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export declare type Options = {
8080
*/
8181
requestOptions?: NodeRequest.OptionsWithUrl;
8282
/**
83-
* The error extension is part of the GraphQLErrors that will be returned if
84-
* the query cannot be fulfilled. It provides information about the REST call
85-
* that could be fulfilled (e.g. the method, path, status code, response
83+
* The error extensions is part of the GraphQLErrors that will be returned if
84+
* the query cannot be fulfilled. It provides information about the failed
85+
* REST call(e.g. the method, path, status code, response
8686
* headers, and response body). It can be useful for debugging but may
8787
* unintentionally leak information.
8888
*
89-
* This option prevents the extension from being created.
89+
* This option prevents the extensions from being created.
9090
*/
9191
provideErrorExtensions?: boolean;
9292
};
@@ -159,13 +159,13 @@ export declare type InternalOptions = {
159159
*/
160160
requestOptions?: NodeRequest.OptionsWithUrl;
161161
/**
162-
* The error extension is part of the GraphQLErrors that will be returned if
163-
* the query cannot be fulfilled. It provides information about the REST call
164-
* that could be fulfilled (e.g. the method, path, status code, response
162+
* The error extensions is part of the GraphQLErrors that will be returned if
163+
* the query cannot be fulfilled. It provides information about the failed
164+
* REST call(e.g. the method, path, status code, response
165165
* headers, and response body). It can be useful for debugging but may
166166
* unintentionally leak information.
167167
*
168-
* This option prevents the extension from being created.
168+
* This option prevents the extensions from being created.
169169
*/
170170
provideErrorExtensions: boolean;
171171
};

packages/oasgraph/src/types/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export type Options = {
9696

9797
/**
9898
* The error extensions is part of the GraphQLErrors that will be returned if
99-
* the query cannot be fulfilled. It provides information about the REST call
100-
* that could be fulfilled (e.g. the method, path, status code, response
99+
* the query cannot be fulfilled. It provides information about the failed
100+
* REST call(e.g. the method, path, status code, response
101101
* headers, and response body). It can be useful for debugging but may
102102
* unintentionally leak information.
103103
*
@@ -184,8 +184,8 @@ export type InternalOptions = {
184184

185185
/**
186186
* The error extensions is part of the GraphQLErrors that will be returned if
187-
* the query cannot be fulfilled. It provides information about the REST call
188-
* that could be fulfilled (e.g. the method, path, status code, response
187+
* the query cannot be fulfilled. It provides information about the failed
188+
* REST call(e.g. the method, path, status code, response
189189
* headers, and response body). It can be useful for debugging but may
190190
* unintentionally leak information.
191191
*

packages/oasgraph/test/example_api.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ test('Error contains extension', () => {
689689
expect(extensions).toEqual({
690690
"method": "get",
691691
"path": "/users/{username}",
692-
"statusCode": 401,
692+
"statusCode": 404,
693693
"responseBody": {
694694
"message": "Wrong username."
695695
}

packages/oasgraph/test/example_api_server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function startServer (PORT) {
281281
if (req.params.username in Users) {
282282
res.send(Users[req.params.username])
283283
} else {
284-
res.status(401).send({
284+
res.status(404).send({
285285
message: 'Wrong username.'
286286
})
287287
}
@@ -291,7 +291,7 @@ function startServer (PORT) {
291291
console.log(req.method, req.path)
292292
if (typeof req.params.username !== 'string' ||
293293
req.params.username === 'undefined') {
294-
res.status(401).send({
294+
res.status(404).send({
295295
message: 'Wrong username.'
296296
})
297297
} else {

0 commit comments

Comments
 (0)