Open zZHorizonZz opened 4 months ago
The core problem seems to be with GET requests that lack parameters. In those cases, this behavior occurs, as you can see here:
/v1/projects:
get:
tags:
- Project Management
summary: List Projects
description: Lists all projects
responses:
'200':
description: Projects retrieved successfully
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Project'
Hi @zZHorizonZz Thanks for using kiota and for reaching out. Here is a minimal repro that works, and uncommenting the baseEnvironment, baseRole and environments properties makes the issue appear.
openapi: 3.0.3
info:
title: api-service API
version: 0.0.1
description: API for managing environments, projects, and private services
contact:
name: API Support
email: api@support.com
servers:
- url: http://localhost:8080
description: Local server
tags:
- name: Environment Management
description: API for managing environments
- name: Private Service Management
description: API for managing private services
- name: Project Management
description: API for managing projects
- name: Proxy Admin Service
description: API for managing proxy rules
paths:
/v1/projects:
get:
operationId: listProjects
tags:
- Project Management
summary: List Projects
description: Lists all projects
responses:
'200':
description: Projects retrieved successfully
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Project'
components:
schemas:
Action:
enum:
- ADMIN
- READ
- WRITE
type: string
Environment:
description: Represents an environment within a project
type: object
properties:
uid:
description: Unique identifier for the environment
type: string
allOf:
- $ref: '#/components/schemas/UUID'
project:
description: The project to which this environment belongs
type: object
allOf:
- $ref: '#/components/schemas/Project'
name:
description: The name of the environment
type: string
description:
description: The description of the environment
type: string
isActive:
description: Indicates if the environment is active
type: boolean
createdAt:
description: The timestamp when the environment was created
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
updatedAt:
description: The timestamp when the environment was last updated
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
active:
type: boolean
LocalDateTime:
format: date-time
type: string
example: '2022-03-10T12:15:50'
Project:
description: Represents a project containing environments
type: object
properties:
uid:
description: Unique identifier for the project
type: string
allOf:
- $ref: '#/components/schemas/UUID'
name:
description: Name of the project
type: string
description:
description: Description of the project
type: string
purpose:
description: Purpose of the project
type: string
createdBy:
description: User ID who created the project
type: string
# baseEnvironment:
# description: Base environment for the project
# type: object
# allOf:
# - $ref: '#/components/schemas/Environment'
# baseRole:
# description: Base role for the project
# type: object
# allOf:
# - $ref: '#/components/schemas/ProjectRole'
# environments:
# description: List of environments associated with the project
# type: array
# items:
# description: Represents an environment within a project
# type: object
# properties:
# uid:
# description: Unique identifier for the environment
# type: string
# allOf:
# - $ref: '#/components/schemas/UUID'
# project:
# description: The project to which this environment belongs
# type: object
# allOf:
# - $ref: '#/components/schemas/Project'
# name:
# description: The name of the environment
# type: string
# description:
# description: The description of the environment
# type: string
# isActive:
# description: Indicates if the environment is active
# type: boolean
# createdAt:
# description: The timestamp when the environment was created
# type: string
# allOf:
# - $ref: '#/components/schemas/LocalDateTime'
# updatedAt:
# description: The timestamp when the environment was last updated
# type: string
# allOf:
# - $ref: '#/components/schemas/LocalDateTime'
# active:
# type: boolean
createdAt:
description: Timestamp when the project was created
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
updatedAt:
description: Timestamp when the project was last updated
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
ProjectRole:
description: Represents a role within a project with associated permissions
type: object
properties:
uid:
description: Unique identifier for the project role
type: string
allOf:
- $ref: '#/components/schemas/UUID'
project:
description: The project to which this role belongs
type: object
allOf:
- $ref: '#/components/schemas/Project'
name:
description: Unique name of the role
type: string
displayName:
description: Display name of the role (for user interfaces)
type: string
description:
description: Description of the role's purpose
type: string
permissions:
description: List of permissions associated with the role
type: array
items:
type: object
properties:
api:
type: string
actions:
type: array
items:
$ref: '#/components/schemas/Action'
createdBy:
description: User ID who created the role
type: string
createdAt:
description: Timestamp when the role was created
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
updatedAt:
description: Timestamp when the role was last updated
type: string
allOf:
- $ref: '#/components/schemas/LocalDateTime'
UUID:
format: uuid
pattern: '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}'
type: string
securitySchemes:
SecurityScheme:
type: http
description: Authentication
scheme: bearer
bearerFormat: Opaque
This description is causing a stackoverflow due to circular references. Even if kiota could generate the code, it's most likely that compilers in most languages would complain about the result. This description seems auto-generated, you should look into tweaking the generation so it does not produce circular references.
After a closer look, I noticed this as well basically I'm generating OpenAPI specs based on a database model that includes references to other models. This is valid for me, as these models are retrieved lazily from database to prevent an infinite loop. However, I understand why this could be an issue in OpenAPI.
Still, I think the "freeze/stale" behavior is inappropriate in this case, as the user doesn't know what happened. If there's schema validation, perhaps the generate command could throw an error. Otherwise, a timeout with details about the cause might be helpful.
The "freeze" is caused by a stackoverflow, itself caused by infinite recursion of the engine. It is strange however that you're experiencing a freeze behaviour, I get an exception. Reliably detecting the loop (without causing false positives) ahead of time would be extremely difficult/costly. We could catch the stack overflow exception and display a better message as a first stopgap, but that assumes the exception gets thrown. I'm curious to why you don't get an exception? Any specific setup? Did you download the executable manually or are you using dotnet tool?
This issue occurs both with the executable on my work PC and with the dotnet tool command on my private PC. I don't recall if I tested it via a regular command prompt, but I have a script defined in my package.json file. After running yarn generate, it executes the command:
"scripts": {
"generate": "kiota generate -l typescript -d http://localhost:8080/openapi?format=json -c Client -o ./src/client --co",
"type-check": "tsc --noEmit"
},
Though the behavior seems normal meaning if there is an error, it is shown in the console the output appears the same as if I executed a regular command.
ah, it might be the environment host for node script runner that's not bubbling up the exception for some reason. Can you test with the command directly on the same machines with the same descriptions to see if you get and exception/terminal execution?
I tried this in both the terminal and PowerShell, and the result is the same. I waited for five minutes to see if any errors would be thrown, but it's still stuck on InitializeInheritanceIndex.
https://github.com/microsoft/kiota/assets/60035933/1039d7a1-9932-469d-927f-761961ec0eb0
What are you generating using Kiota, clients or plugins?
Kiota plugin
In what context or format are you using Kiota?
Windows executable
Client library/SDK language
TypeScript
Describe the bug
I'm trying to generate the client based on the specified OpenAPI file, but Kiota freezes when it tries to generate the client.
Expected behavior
Kiota shouldn't freeze. I don't think there's an error with the specifications, as other client generators generate valid clients from my tests.
How to reproduce
Try to generate client via generate command I'm using this:
Your path will be different obviously.
Open API description file
Kiota Version
1.14.0+fc4b39c65d89f7bfc8c7f1813c197e95e206da09
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
No response
Configuration
Debug output
Click to expand log
``` Warning: the TypeScript language is in preview (Preview) some features are not fully supported and source breaking changes will happen with future updates. info: Kiota.Builder.KiotaBuilder[0] Cleaning output directoryOther information
I have tried this on 2 devices on one device kiota is installed via dotnet on second I have binaries added in path and both have same version.