OpenAPITools / OpenAPITools/openapi-generator
[BUG] go generator generates wrong field names, when it ends Id
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi
golint does not accept data types if a field name or struct name is ended by "Id", since it just accepets ID (or at least it suggest to use ID instead of id or Id)
Currently the go generator cannot make this, so after the generator we have to change all ending Id to ID.
It would be nice, if you can add this enhancement in the generator.
info:
version: '1.0.0'
title: 'Test'
paths: {}
components:
schemas:
TestId:
type: object
properties:
field1Id:
type: string
field2id:
type: string
generated datatype:
// TestId struct for TestId
type TestId struct {
Field1Id *string `json:"field1Id,omitempty"`
Field2id *string `json:"field2id,omitempty"`
}
Should be
// TestId struct for TestId
type TestID struct {
Field1ID *string `json:"field1Id,omitempty"`
Field2ID *string `json:"field2id,omitempty"`
}
note: that the json part should be untouched, only the field/struct names requires this enhancement.
Thanks
Akos
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Go generator's identifier/name-conversion logic and reproduce the issue with the OpenAPI schema in the report. Verify that generated struct and field names convert a trailing Id to ID while JSON tags remain unchanged; the expected output in the issue defines done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100