Skip to content

Commit 33b301c

Browse files
Alan-ChaErikWittern
authored andcommitted
Add singularNames option
Signed-off-by: Alan Cha <[email protected]>
1 parent 404e844 commit 33b301c

23 files changed

+479
-97
lines changed

packages/openapi-to-graphql-cli/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ Options:
3232
3333
-o, --operationIdFieldNames create field names based on the operationId
3434
-f, --fillEmptyResponses create placeholder schemas for operations with no response body rather than ignore them
35-
-a, --addLimitArgument add a limit argument on fields returning lists of objects/lists to control the data size
36-
-g, --genericPayloadArgName Sets argument name for the payload of a mutation to 'requestBody'
37-
-N, --simpleNames Only remove illegal characters from names in the OAS and ignore casing and formatting
35+
--addLimitArgument add a limit argument on fields returning lists of objects/lists to control the data size
36+
--genericPayloadArgName Sets argument name for the payload of a mutation to 'requestBody'
37+
--simpleNames Only remove illegal characters from names in the OAS and ignore casing and formatting
38+
--singularNames Experimental feature that will create more meaningful names from the operation path
3839
3940
-H, --header <key:value> add headers to every request; repeatable flag; set using key:value notation (default: [])
4041
-Q, --queryString <key:value> add query parameters to every request; repeatable flag; set using key:value notation (default: [])

packages/openapi-to-graphql-cli/lib/openapi-to-graphql.js

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql-cli/lib/openapi-to-graphql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openapi-to-graphql-cli/src/openapi-to-graphql.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ program
4747
'create placeholder schemas for operations with no response body rather than ignore them'
4848
)
4949
.option(
50-
'-a, --addLimitArgument',
50+
'--addLimitArgument',
5151
'add a limit argument on fields returning lists of objects/lists to control the data size'
5252
)
5353
.option(
54-
'-g, --genericPayloadArgName',
54+
'--genericPayloadArgName',
5555
"Sets argument name for the payload of a mutation to 'requestBody'"
5656
)
5757
.option(
58-
'-N, --simpleNames',
58+
'--simpleNames',
5959
'Only remove illegal characters from names in the OAS and ignore casing and formatting'
6060
)
61+
.option(
62+
'--singularNames',
63+
'Experimental feature that will create more meaningful names from the operation path'
64+
)
6165

6266
// Resolver options
6367
.option(
@@ -112,6 +116,7 @@ const options: Options = {
112116
addLimitArgument: program.addLimitArgument,
113117
genericPayloadArgName: program.genericPayloadArgName,
114118
simpleNames: program.simpleNames,
119+
singularNames: program.singularNames,
115120

116121
// Resolver options
117122
headers,

packages/openapi-to-graphql/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ Schema options:
162162

163163
- `simpleNames` (type: `boolean`, default: `false`): By default, field names are sanitized to conform with GraphQL conventions, i.e. types should be in PascalCase, fields should be in camelCase, and enum values should be in ALL_CAPS. This option will prevent OTG from enforcing camelCase field names and PascalCase type names, only removing illegal characters and staying as true to the provided names in the OAS as possible.
164164

165+
- `singularNames` (type: `boolean`, default: `false`): Experimental feature that will try to create more meaningful names from the operation path than the response object by leveraging common conventions. For example, given the operation `GET /users/{userId}/car`, OtG will create a `Query` field `userCar`. Note that because `users` is followed by the parameter `userId`, it insinuates that this operation will get the car that belongs to a singular user. Hence, the name `userCar` is more fitting than `usersCar` so the pluralizing 's' is dropped. This option will also consider irregular plural forms.
166+
165167
***
166168

167169
Resolver options:
@@ -257,9 +259,9 @@ OpenAPI-to-GraphQL further provides `anyAuth` viewers (for queries and mutations
257259
password: "secret"
258260
}
259261
) {
260-
patentWithId (patentId: "test") { // requires "exampleApiKeyProtocol"
262+
patent (patentId: "test") { // requires "exampleApiKeyProtocol"
261263
patentId
262-
inventor { // requires "exampleBasicProtocol"
264+
inventor { // requires "exampleBasicProtocol"
263265
name
264266
}
265267
}

0 commit comments

Comments
 (0)