Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline definitions in openapi can overwrite classes #5967

Open
mealvaro-ionos opened this issue Jan 7, 2025 · 2 comments
Open

Inline definitions in openapi can overwrite classes #5967

mealvaro-ionos opened this issue Jan 7, 2025 · 2 comments

Comments

@mealvaro-ionos
Copy link

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 ```
</details>


### Other information

_No response_
@mealvaro-ionos mealvaro-ionos added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jan 7, 2025
@msgraph-bot msgraph-bot bot added this to Kiota Jan 7, 2025
@msgraph-bot msgraph-bot bot added the PHP label Jan 7, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jan 7, 2025
@baywet
Copy link
Member

baywet commented Jan 7, 2025

Hi @mealvaro-ionos
Thank you for using kiota and for reaching out.

This issue is probably impacting more than PHP, effectively all the languages that do not "support" inner class definitions. (Go, TypeScript, etc...)

It is most likely caused by the logic that moves those inner classes to their own class, creating the name.

if (nestedClass.Parent is not CodeClass parentClass) continue;

Is this something you'd like to submit a pull request for provided some guidance?

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jan 7, 2025
@baywet baywet moved this from Needs Triage 🔍 to New📃 in Kiota Jan 7, 2025
@mealvaro-ionos
Copy link
Author

Hi @baywet
Regrettably, I am not proficient in the C# programming language. Furthermore, I am currently constrained by time and unable to dedicate the necessary effort required to thoroughly address the issue.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New📃
Development

No branches or pull requests

2 participants