OpenAPI: Add type hints on 'id' parameters and properties #1595
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds type hints to the string-based
id
parameters and properties.The resulting experience is less awesome than I hoped. Effectively, it only makes a difference in NSwag/Kiota when
TId
is a guid (uuid
in OpenAPI). This is because client generators don't generate a numeric type when the type isstring
, despite a type hint such asint64
. That's understandable, because it would produce an invalid JSON:API request (sending"id": 3
would fail because the value must be a string).The type hints do show up in SwaggerUI for all
TId
types, which could be helpful.A corner case surfaced in NSwag when using
Guid
as theid
type and/GenerateNullableReferenceTypes
is turned on, butGenerateOptionalPropertiesAsNullable
andGenerateOptionalParameters
are off. In that case, the generated type for theId
property becomesGuid
(non-nullable), so omitting it from the request body sendsGuid.Empty
, which produces an error. This is a problem whenClientIdGenerationMode
is set toAllowed
, because there's no way to not send the ID. To fix that,TId
must beGuid?
, so a nullable type gets generated. However this is such a corner case that I've updated the existing tests to run withGenerateOptionalPropertiesAsNullable
andGenerateOptionalParameters
turned on, which I expect users to do anyway.Once we update to NSwag v14, its MSBuild properties enable us to set the switches we need/recommend from the
JsonApiDotNetCore.OpenApi.Client.NSwag
NuGet package via an imported.props
file, so the limitation is even less likely to surface.Closes #1572.
QUALITY CHECKLIST