-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to tweak generated names (including use of initiali…
…sms) As noted in #454, the generated code we produce defaults to performing `CamelCase` - which is fine - but doesn't take into account common initialisms that are idiomatic to Go. This was previously attempted in #1007, but we had to roll it back due to it changing underlying generated code, which would result in a breaking change for consumers. To avoid this, we can make this opt-in via a new output option, `name-normalizer`, which provides the ability to control the functionality. This is also available for folks using the project as a library, which makes it more convenient to change behaviour. Closes #454. Co-authored-by: Dmitriy Lukiyanchuk <dmitriy.lukiyanchuk@instamart.ru> Co-authored-by: Jamie Tanna <jamie@jamietanna.co.uk> Co-authored-by: Jamie Tanna <jamie.tanna@elastic.co>
- Loading branch information
1 parent
fd4a0ef
commit af43038
Showing
24 changed files
with
3,126 additions
and
16 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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Example code for the `name-normalizer` output option | ||
paths: | ||
/api/pets/{petId}: | ||
get: | ||
summary: Get pet given identifier. | ||
operationId: getHttpPet | ||
parameters: | ||
- name: petId | ||
in: path | ||
required: true | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: valid pet | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Pet' | ||
components: | ||
schemas: | ||
Pet: | ||
type: object | ||
required: | ||
- uuid | ||
- name | ||
properties: | ||
uuid: | ||
type: string | ||
description: The pet uuid. | ||
name: | ||
type: string | ||
description: The name of the pet. | ||
Error: | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
description: Error code | ||
message: | ||
type: string | ||
description: Error message | ||
OneOf2things: | ||
description: "Notice that the `things` is not capitalised" | ||
oneOf: | ||
- type: object | ||
required: | ||
- id | ||
properties: | ||
id: | ||
type: integer | ||
- type: object | ||
required: | ||
- id | ||
properties: | ||
id: | ||
type: string | ||
format: uuid |
11 changes: 11 additions & 0 deletions
11
internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/config.yaml
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# yaml-language-server: $schema=../../../../../configuration-schema.json | ||
package: tocamelcasewithdigits | ||
generate: | ||
gorilla-server: true | ||
client: true | ||
models: true | ||
embedded-spec: true | ||
output: name_normalizer.gen.go | ||
output-options: | ||
skip-prune: true | ||
name-normalizer: ToCamelCaseWithDigits |
3 changes: 3 additions & 0 deletions
3
internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/generate.go
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package tocamelcasewithdigits | ||
|
||
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml |
Oops, something went wrong.