OpenAPITools / OpenAPITools/openapi-generator
[BUG] The Field name is Duplicated when use `modelNamePrefix: Api` or `modelNameSuffix: Api` in go
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [ x ] Have you provided a full/minimal spec to reproduce the issue?
- [ x ] Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- [ x ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The struct name is Duplicated when use modelNamePrefix: Api or modelNameSuffix: Api.
When the code is generated, the struct ApiTag name is ok.
In api_model_pet.go , the struct ApiPet has a field is Tags []ApiApiTag json:"tags,omitempty".
ApiApiTag is modelNamePrefix duplicated. Its name should be ApiTag.
openapi-generator version
7.14.0 open-generator-cli
OpenAPI declaration file content or url
petstore-api.yaml
openapi: 3.0.0
info:
contact:
email: support@petstore.com
name: API Support
url: https://petstore.com/support
description: |
A sample API that demonstrates OpenAPI 3.1 features including:
- CRUD operations for pets
- File upload for pet avatars
- Advanced validation and examples
- Webhooks support
license:
name: MIT
url: https://opensource.org/licenses/MIT
title: Petstore API
version: 1.0.0
servers:
- description: Production server
url: https://api.petstore.com/v1
- description: Staging server
url: https://staging-api.petstore.com/v1
- description: Local development server
url: http://localhost:8080/v1
security:
- petstore_auth:
- read:pets
- write:pets
- api_key: []
tags:
- description: Pet management operations
name: pets
- description: File upload operations
name: upload
paths:
/pets:
get:
description: Retrieve a list of all pets with optional filtering and pagination
operationId: listPets
parameters:
- description: Maximum number of pets to return
explode: true
in: query
name: limit
required: false
schema:
default: 20
maximum: 100
minimum: 1
type: integer
style: form
- description: Number of pets to skip for pagination
explode: true
in: query
name: offset
required: false
schema:
default: 0
minimum: 0
type: integer
style: form
- description: Filter pets by status
explode: true
in: query
name: status
required: false
schema:
enum:
- available
- pending
- sold
type: string
style: form
- description: Filter pets by category
explode: true
in: query
name: category
required: false
schema:
type: string
style: form
responses:
"200":
content:
application/json:
examples:
success:
summary: Successful response
value:
pets:
- id: 1
name: Fluffy
category: cat
status: available
tags:
- name: friendly
- name: playful
photoUrls:
- https://example.com/fluffy.jpg
- id: 2
name: Buddy
category: dog
status: available
tags:
- name: loyal
photoUrls:
- https://example.com/buddy.jpg
total: 2
limit: 20
offset: 0
schema:
$ref: "#/components/schemas/listPets_200_response"
description: A list of pets
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"500":
$ref: "#/components/responses/InternalServerError"
summary: List all pets
tags:
- pets
post:
description: Add a new pet to the store
operationId: createPet
requestBody:
content:
application/json:
examples:
cat:
summary: Create a cat
value:
name: Whiskers
category: cat
status: available
tags:
- name: independent
- name: clean
photoUrls:
- https://example.com/whiskers.jpg
dog:
summary: Create a dog
value:
name: Max
category: dog
status: available
tags:
- name: energetic
- name: friendly
photoUrls:
- https://example.com/max.jpg
schema:
$ref: "#/components/schemas/PetInput"
required: true
responses:
"201":
content:
application/json:
examples:
created:
summary: Pet created
value:
id: 123
name: Whiskers
category: cat
status: available
tags:
- name: independent
- name: clean
photoUrls:
- https://example.com/whiskers.jpg
createdAt: 2024-01-15T10:30:00Z
updatedAt: 2024-01-15T10:30:00Z
schema:
$ref: "#/components/schemas/Pet"
description: Pet created successfully
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"422":
$ref: "#/components/responses/ValidationError"
summary: Create a new pet
tags:
- pets
/pets/{petId}:
delete:
description: Remove a pet from the store
operationId: deletePet
parameters:
- description: ID of the pet to retrieve
examples:
valid_id:
summary: Valid pet ID
value: 123
invalid_id:
summary: Invalid pet ID
value: -1
explode: false
in: path
name: petId
required: true
schema:
minimum: 1
type: integer
style: simple
responses:
"204":
description: Pet deleted successfully
"404":
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"
summary: Delete pet
tags:
- pets
get:
description: Retrieve a specific pet by its ID
operationId: getPetById
parameters:
- description: ID of the pet to retrieve
examples:
valid_id:
summary: Valid pet ID
value: 123
invalid_id:
summary: Invalid pet ID
value: -1
explode: false
in: path
name: petId
required: true
schema:
minimum: 1
type: integer
style: simple
responses:
"200":
content:
application/json:
examples:
cat:
summary: Cat pet
value:
id: 1
name: Fluffy
category: cat
status: available
tags:
- name: friendly
- name: playful
photoUrls:
- https://example.com/fluffy.jpg
createdAt: 2024-01-10T09:00:00Z
updatedAt: 2024-01-15T14:30:00Z
schema:
$ref: "#/components/schemas/Pet"
description: Pet found
"404":
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"
summary: Get pet by ID
tags:
- pets
put:
description: Update an existing pet's information
operationId: updatePet
parameters:
- description: ID of the pet to retrieve
examples:
valid_id:
summary: Valid pet ID
value: 123
invalid_id:
summary: Invalid pet ID
value: -1
explode: false
in: path
name: petId
required: true
schema:
minimum: 1
type: integer
style: simple
requestBody:
content:
application/json:
examples:
update:
summary: Update pet information
value:
name: Fluffy Updated
category: cat
status: sold
tags:
- name: friendly
- name: adopted
photoUrls:
- https://example.com/fluffy-updated.jpg
schema:
$ref: "#/components/schemas/PetInput"
required: true
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
description: Pet updated successfully
"400":
$ref: "#/components/responses/BadRequest"
"404":
$ref: "#/components/responses/NotFound"
"422":
$ref: "#/components/responses/ValidationError"
summary: Update pet
tags:
- pets
/pets/{petId}/avatar:
post:
description: Upload an avatar image for a specific pet
operationId: uploadPetAvatar
parameters:
- description: ID of the pet to upload avatar for
explode: false
in: path
name: petId
required: true
schema:
minimum: 1
type: integer
style: simple
requestBody:
content:
multipart/form-data:
encoding:
file:
contentType: "image/jpeg, image/png, image/gif, image/webp"
style: form
schema:
$ref: "#/components/schemas/uploadPetAvatar_request"
required: true
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/uploadPetAvatar_200_response"
description: Avatar uploaded successfully
"400":
$ref: "#/components/responses/BadRequest"
"404":
$ref: "#/components/responses/NotFound"
"413":
content:
application/json:
schema:
$ref: "#/components/schemas/uploadPetAvatar_413_response"
description: File too large
"415":
content:
application/json:
schema:
$ref: "#/components/schemas/uploadPetAvatar_415_response"
description: Unsupported media type
summary: Upload pet avatar
tags:
- pets
- upload
/pets/findByStatus:
get:
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- description: Status values that need to be considered for filter
explode: true
in: query
name: status
required: true
schema:
items:
enum:
- available
- pending
- sold
type: string
type: array
style: form
responses:
"200":
content:
application/json:
schema:
items:
$ref: "#/components/schemas/Pet"
type: array
description: Successful operation
"400":
$ref: "#/components/responses/BadRequest"
summary: Find pets by status
tags:
- pets
components:
responses:
BadRequest:
content:
application/json:
examples:
invalid_input:
summary: Invalid input
value:
code: 400
message: Bad Request
details:
- field: name
message: Name is required
- field: status
message: "Status must be one of: available, pending, sold"
schema:
$ref: "#/components/schemas/Error"
description: Bad request
Unauthorized:
content:
application/json:
examples:
no_auth:
summary: No authentication
value:
code: 401
message: Unauthorized - Authentication required
schema:
$ref: "#/components/schemas/Error"
description: Unauthorized
NotFound:
content:
application/json:
examples:
pet_not_found:
summary: Pet not found
value:
code: 404
message: Pet not found
schema:
$ref: "#/components/schemas/Error"
description: Pet not found
ValidationError:
content:
application/json:
examples:
validation_failed:
summary: Validation failed
value:
code: 422
message: Validation failed
details:
- field: name
message: Name must be between 1 and 100 characters
- field: category
message: "Category must be one of: cat, dog, bird, fish, reptile,\
\ other"
schema:
$ref: "#/components/schemas/Error"
description: Validation error
InternalServerError:
content:
application/json:
examples:
server_error:
summary: Server error
value:
code: 500
message: Internal server error
schema:
$ref: "#/components/schemas/Error"
description: Internal server error
schemas:
Pet:
example:
createdAt: 2024-01-10T09:00:00Z
photoUrls:
- https://example.com/fluffy.jpg
name: Fluffy
id: 123
category: cat
status: available
tags:
- name: friendly
id: 1
- name: friendly
id: 1
updatedAt: 2024-01-15T14:30:00Z
properties:
id:
description: Unique identifier for the pet
example: 123
format: int64
type: integer
name:
description: Pet's name
example: Fluffy
maxLength: 100
minLength: 1
type: string
category:
description: Pet category
enum:
- cat
- dog
- bird
- fish
- reptile
- other
example: cat
type: string
status:
description: Pet status in the store
enum:
- available
- pending
- sold
example: available
type: string
tags:
description: Tags associated with the pet
items:
$ref: "#/components/schemas/Tag"
type: array
photoUrls:
description: URLs of pet photos
example:
- https://example.com/fluffy.jpg
items:
format: uri
type: string
type: array
createdAt:
description: When the pet was created
example: 2024-01-10T09:00:00Z
format: date-time
type: string
updatedAt:
description: When the pet was last updated
example: 2024-01-15T14:30:00Z
format: date-time
type: string
required:
- name
- status
type: object
PetInput:
properties:
name:
description: Pet's name
example: Fluffy
maxLength: 100
minLength: 1
type: string
category:
description: Pet category
enum:
- cat
- dog
- bird
- fish
- reptile
- other
example: cat
type: string
status:
description: Pet status in the store
enum:
- available
- pending
- sold
example: available
type: string
tags:
description: Tags associated with the pet
items:
$ref: "#/components/schemas/Tag"
type: array
photoUrls:
description: URLs of pet photos
example:
- https://example.com/fluffy.jpg
items:
format: uri
type: string
type: array
required:
- name
- status
type: object
Tag:
example:
name: friendly
id: 1
properties:
id:
description: Tag ID
example: 1
format: int64
type: integer
name:
description: Tag name
example: friendly
maxLength: 50
minLength: 1
type: string
type: object
Error:
example:
code: 400
details:
- field: name
message: Name is required
- field: status
message: "Status must be one of: available, pending, sold"
message: Bad Request
properties:
code:
description: Error code
example: 400
format: int32
type: integer
message:
description: Error message
example: Bad Request
type: string
details:
description: Detailed error information
example:
- field: name
message: Name is required
- field: status
message: "Status must be one of: available, pending, sold"
items:
$ref: "#/components/schemas/Error_details_inner"
type: array
required:
- code
- message
type: object
listPets_200_response:
example:
pets:
- createdAt: 2024-01-10T09:00:00Z
photoUrls:
- https://example.com/fluffy.jpg
name: Fluffy
id: 123
category: cat
status: available
tags:
- name: friendly
id: 1
- name: friendly
id: 1
updatedAt: 2024-01-15T14:30:00Z
- createdAt: 2024-01-10T09:00:00Z
photoUrls:
- https://example.com/fluffy.jpg
name: Fluffy
id: 123
category: cat
status: available
tags:
- name: friendly
id: 1
- name: friendly
id: 1
updatedAt: 2024-01-15T14:30:00Z
total: 0
offset: 1
limit: 6
properties:
pets:
items:
$ref: "#/components/schemas/Pet"
type: array
total:
description: Total number of pets
type: integer
limit:
description: Number of pets returned
type: integer
offset:
description: Number of pets skipped
type: integer
type: object
uploadPetAvatar_request:
properties:
file:
description: Pet avatar image file
format: binary
maxLength: 10485760
type: string
description:
description: Optional description for the avatar
maxLength: 500
type: string
required:
- file
type: object
uploadPetAvatar_200_response:
example:
avatarUrl: https://example.com/avatars/pet-123-avatar.jpg
fileSize: 245760
uploadedAt: 2024-01-15T15:30:00Z
message: Avatar uploaded successfully
properties:
message:
example: Avatar uploaded successfully
type: string
avatarUrl:
example: https://example.com/avatars/pet-123-avatar.jpg
format: uri
type: string
fileSize:
description: File size in bytes
example: 245760
type: integer
uploadedAt:
example: 2024-01-15T15:30:00Z
format: date-time
type: string
type: object
uploadPetAvatar_413_response:
example:
error: File size exceeds maximum limit of 10MB
properties:
error:
example: File size exceeds maximum limit of 10MB
type: string
type: object
uploadPetAvatar_415_response:
example:
error: "Unsupported file type. Please use JPEG, PNG, GIF, or WebP"
properties:
error:
example: "Unsupported file type. Please use JPEG, PNG, GIF, or WebP"
type: string
type: object
Error_details_inner:
properties:
field:
description: Field name with error
type: string
message:
description: Error message for the field
type: string
type: object
securitySchemes:
petstore_auth:
description: OAuth 2.0 authentication for Petstore API
flows:
authorizationCode:
authorizationUrl: https://petstore.com/oauth/authorize
scopes:
read:pets: Read pets
write:pets: Write pets
admin:pets: Admin access to pets
tokenUrl: https://petstore.com/oauth/token
implicit:
authorizationUrl: https://petstore.com/oauth/authorize
scopes:
read:pets: Read pets
write:pets: Write pets
admin:pets: Admin access to pets
type: oauth2
api_key:
description: API key for authentication
in: header
name: X-API-Key
type: apiKey
Generation Details
config.yaml
generatorName: go-gin-server
outputDir: ./generated
inputSpec: ./petstore-api.yaml
modelNamePrefix: Api
additionalProperties:
generateInterfaces: true
apiPath: go
interfaceOnly: true
packageName: my_api
serverPort: "9000"
openapi-generator-cli generate -c openapi-gen-petstore.yaml
Steps to reproduce
Related issues/PRs
Suggest a fix
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
Reproduce the issue with the provided petstore-api.yaml and the Go generator using modelNamePrefix or modelNameSuffix set to Api. Inspect the generated api_model_pet.go and the Go generator's model-name handling; done means the Tags field refers to ApiTag rather than ApiApiTag for both prefix and suffix cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100