-
Notifications
You must be signed in to change notification settings - Fork 304
Open
Labels
enhancementNew feature or requestNew feature or requestgeneratorIssues or improvements relater to generation capabilities.Issues or improvements relater to generation capabilities.
Milestone
Description
Description
When the default value of a field doesn't match the type a warning is emitted by kiota, but, in this case, the generated code is not going to compile for allOf the non-dynamic languages.
Original issue
Faced this issue here in the OpenAI spec.
Reproducer
A minimal spec like this:
openapi: 3.0.0
info:
title: Test
version: 1.0.0
description: something
paths:
/api/something/v1:
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
max_tokens:
default: inf
type: integer
nullable: true
responses:
"200":
description: "something"
content:
application/json: {}This would produce the following Warning:
OpenAPI warning: #/paths/~1api~1something~1v1/post/requestBody/content/application~1json/schema/properties/max_tokens/default - Data and type mismatch found.
But it generates code that is not going to compile:
public int? MaxTokens { get; set; }
...
MaxTokens = "inf";Desired resolution
I think that we can improve over the current situation, as having code generated but that is going to fail to compile is suboptimal.
There are a few directions we can consider:
- Decide that this mismatch is a fatal error (for all non-dynamic langs at least ...) and abort the generation
- Since we are already emitting a warning, skip the assignment so that the generated code will compile
- In this specific case the intention is pretty clear, should we handle special numeric values? ( upstream ref maybe @darrelmiller knows more about)
- Another option would be to generate code such as:
Int32.Parse("inf")so that the error will be moved at the user's runtime. Possibly throwing the relevant exception only in case thedefaultneeds to get applied.
Happy to hear more feedback!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgeneratorIssues or improvements relater to generation capabilities.Issues or improvements relater to generation capabilities.
Type
Projects
Status
New📃