Inline definitions in openapi can overwrite classes
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
### What are you generating using Kiota, clients or plugins?
API Client/SDK
### In what context or format are you using Kiota?
Linux executable
### Client library/SDK language
PHP
### Describe the bug
Generating coded in PHP, when in the openapi we have a definition of a component (B) inside another component (A) the class name is generated concatenating parent component with underscores (A_B). This generated name can collide with the name of another component, so the generated class overwrites the existing one.
For example, in we have an openapi with a component _test_case_ and a component _test_, that includes another component called _case_.
`"definitions": {
"test_case": {
"properties": {
"name": {
"example": 1,
"type": "integer"
},
"uuid": {
"example": "e22e3261-2bcf-4ca8-acc7-819cf9f19548",
"type": "string"
}
},
"type": "object"
},
"test": {
"properties": {
"case": {
"properties": {
"name2": {
"example": 2,
"type": "integer"
},
"uuid2": {
"example": "6d5b5321-c25c-4dbb-a3e1-da0a506131d2",
"type": "string"
}
}
}
},
"type": "object"
}
}`
When we generate code, we have only two classes:
* Test
* Test_case
The class _Test_case_ has been generated for component _case_ having properties _name2_ and _uuid2_, but overwritten by the generation of component _test_case_ having properties _name_ and _uuid_ eventually, so we have lost the functionality of component _case_.
Class name generation for inline components should check if a class already exists and, in that case, rename it.
### Expected behavior
In the example:
`"definitions": {
"test_case": {
"properties": {
"name": {
"example": 1,
"type": "integer"
},
"uuid": {
"example": "e22e3261-2bcf-4ca8-acc7-819cf9f19548",
"type": "string"
}
},
"type": "object"
},
"test": {
"properties": {
"case": {
"properties": {
"name2": {
"example": 2,
"type": "integer"
},
"uuid2": {
"example": "6d5b5321-c25c-4dbb-a3e1-da0a506131d2",
"type": "string"
}
}
}
},
"type": "object"
}
}`
After generation code, we should have 3 classes instead of only 2:
* Test
* Test_case
* Test_case1 (or any other name different from the existing _Test_case_)
### How to reproduce
Use the attached openapi description and generate code in PHP.
### Open API description file
```
{
"basePath": "/api",
"consumes": [
"application/json",
"application/hal+json"
],
"info": {
"contact": {
"name": "Test",
"url": "https://test.lan"
},
"title": "ONTAP REST API Online Reference",
"version": "v1"
},
"paths": {
"/tests_cases": {
"get": {
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/test_case"
}
}
}
}
},
"/tests": {
"get": {
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/test"
}
}
}
}
}
},
"produces": [
"application/json",
"application/hal+json"
],
"schemes": [
"https"
],
"security": [
{
"simple": []
}
],
"securityDefinitions": {
"simple": {
"type": "basic"
}
},
"swagger": "2.0",
"definitions": {
"test_case": {
"properties": {
"name": {
"example": 1,
"type": "integer"
},
"uuid": {
"example": "e22e3261-2bcf-4ca8-acc7-819cf9f19548",
"type": "string"
}
},
"type": "object"
},
"test": {
"properties": {
"case": {
"properties": {
"name2": {
"example": 2,
"type": "integer"
},
"uuid2": {
"example": "6d5b5321-c25c-4dbb-a3e1-da0a506131d2",
"type": "string"
}
}
}
},
"type": "object"
}
}
}
```
### Kiota Version
1.21.0
### Latest Kiota version known to work for scenario above?(Not required)
_No response_
### Known Workarounds
_No response_
### Configuration
- OS: Ubuntu 22.04
### Debug output
Click to expand log
```
```
### Other information
_No response_
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 collision with the attached OpenAPI description using the PHP target and Kiota 1.21.0. Trace the class-name generation for the inline case component and the existing test_case component; done means generation preserves both components as distinct classes, such as Test_case and Test_case1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100