Skip to content

Support Go Initialisms#573

Closed
jaredpetersen wants to merge 1 commit intooapi-codegen:masterfrom
jaredpetersen:master
Closed

Support Go Initialisms#573
jaredpetersen wants to merge 1 commit intooapi-codegen:masterfrom
jaredpetersen:master

Conversation

@jaredpetersen
Copy link
Copy Markdown

Fixes #454

I'll leave it up to the library owners to determine whether or not this is breaking behavior. Generated code will have different names:

Before:

// Identifier defines model for Identifier.
type Identifier struct {
	Id string `json:"id"`
}

After:

// Identifier defines model for Identifier.
type Identifier struct {
        ID string `json:"id"`
}

Users still have some ability to override this behavior by adding in uppercase characters, e.g word_word_WORD -> WordWordWORD. We can override this behavior now that we have a more intense camelCase function (WordWordWord) but that might be too drastic of a change so I didn't include that.

@jaredpetersen
Copy link
Copy Markdown
Author

jaredpetersen commented May 15, 2022

Looks like there's a few failures related to the diff not lining up with what's expected. I'd like to get some initial thoughts on whether this is something that will likely be merged in this release before continuing. The hard part is done.

@jaredpetersen jaredpetersen marked this pull request as ready for review May 15, 2022 07:55
@deepmap-marcinr
Copy link
Copy Markdown
Contributor

I'm concerned about this breaking existing code. Can we put this new capital behavior behind a flag? You can default-on your behavior, but allow a way to override.

Please see this flag for an example. https://github.com/deepmap/oapi-codegen/blob/master/cmd/oapi-codegen/oapi-codegen.go#L81

@jaredpetersen
Copy link
Copy Markdown
Author

Yeah, that makes sense. It can be done but it will be a bit of a chore to route the configuration to the utility.

@jaredpetersen jaredpetersen marked this pull request as draft May 17, 2022 03:20
@deepmap-marcinr
Copy link
Copy Markdown
Contributor

There's a global options, no need to route anything:
https://github.com/deepmap/oapi-codegen/blob/master/pkg/codegen/schema.go#L336

@jaredpetersen
Copy link
Copy Markdown
Author

This regex implementation has a number of issues when you look closer, particularly if you pass in a string that is already camelCase.

I'm going to close this out for now.

@deepmap-marcinr
Copy link
Copy Markdown
Contributor

deepmap-marcinr commented May 18, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect initialisms for schema generation

2 participants