Skip to content

Commit

Permalink
feat: allow specifying additional-initialisms (oapi-codegen#1733)
Browse files Browse the repository at this point in the history
As well as the inbuilt initialisms that are found in `oapi-codegen`,
there are additional initialisms that shouldn't exist upstream as they
are either contentious in the community  or that are user- or
organisation-specific.

To handle this, we can introduce a new configuration option,
`additional-initialisms`, for user-provided initialisms.

We need to make sure that this provides an early indication of these
settings being set incorrectly by failing early to indicate that the
configuration isn't valid without using the `name-normalizer:
ToCamelCaseWithInitialisms`.

This also requires that we refactor the `initalismsMap` to pull this
into the `globalState`, as it's now dependent on the configuration used,
and this ensures that the settings are isolated.

Co-authored-by: Jamie Tanna <[email protected]>
  • Loading branch information
micaelmalta and jamietanna authored Nov 28, 2024
1 parent 38b8c53 commit b07f7ea
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 8 deletions.
7 changes: 7 additions & 0 deletions configuration-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@
"type": "boolean",
"description": "Whether to use the initialism overrides"
},
"additional-initialisms": {
"type": "array",
"description": "AdditionalInitialisms defines additional initialisms to be used by the code generator. Has no effect unless the `name-normalizer` is set to `ToCamelCaseWithInitialisms`",
"items": {
"type": "string"
}
},
"nullable-type": {
"type": "boolean",
"description": "Whether to generate nullable type for nullable fields"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# yaml-language-server: $schema=../../../../../configuration-schema.json
package: tocamelcasewithadditionalinitialisms
generate:
gorilla-server: true
client: true
models: true
embedded-spec: true
output: name_normalizer.gen.go
output-options:
skip-prune: true
name-normalizer: ToCamelCaseWithInitialisms
additional-initialisms:
- NAME
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package tocamelcasewithadditionalinitialisms

//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../spec.yaml
Loading

0 comments on commit b07f7ea

Please sign in to comment.