-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[CSHARP] Fix how the array type is set when using NULLABLE_REFERENCE_TYPES #22071
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
Open
Mattias-Sehlstedt
wants to merge
2
commits into
OpenAPITools:master
Choose a base branch
from
Mattias-Sehlstedt:deep-alias-with-optional-collection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1624,7 +1624,7 @@ public String getTypeDeclaration(Schema p) { | |
Schema<?> target = ModelUtils.isGenerateAliasAsModel() ? p : schema; | ||
if (ModelUtils.isArraySchema(target)) { | ||
Schema<?> items = getSchemaItems(schema); | ||
return getSchemaType(target) + "<" + getTypeDeclarationForArray(items) + ">"; | ||
return typeMapping.get("array") + "<" + getTypeDeclarationForArray(items) + ">"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have reverted this type calculation to the previous static |
||
} else if (ModelUtils.isMapSchema(p)) { | ||
// Should we also support maps of maps? | ||
Schema<?> inner = ModelUtils.getAdditionalProperties(p); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is different about this new spec? Can you just put the diff in the http-signature spec and revert this? If not, I suggest leaving the new spec and adding a new file to bin/configs, but still reverting this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the new spec I have added objects that are inline aliases.
I initially placed it in the original specification, but since that was used everywhere it caused such a huge delta that I thought it was clearer to isolate the representation in a separate specification.
But if we prefer to have fewer specifications that represent a wider array of scenarios I can change it so that these models are included in the main specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer fewer specs. If it doesnt work in RestSharp or HttpClient then we can use a new spec minimized as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'll look into reverting the new specification and instead extending the existing one.
A question on another topic, how should we best handle the scenarios that have been presented here?
TL;DR: The
NULLABLE_REFERENCE_TYPES
has more scenarios now with deep aliases. These are difficult to represent with the current approach. How should one best leave them out to make it clear that they are not supported? Is the GitHub PR and issue ticket and our discussion here sufficient?Longer: Previously the Csharp generator did not support deep aliases (more than one in depth), it failed by generating code that accidentally compiled (it just made the type
List
). Now with support for deep aliases, there are all of a sudden a lot more of possibleNULLABLE_REFERENCE_TYPES
scenarios (as per the comment linked earlier).My current understanding of how the setting is realized is that it injects the config with the mustache file and
!nrt
at the end of the type. This has previously worked, since the depth was only one (so either inject it at the end, or not). Now with a dynamic depth, this is not really suitable for a mustache config anymore. It would be easier and clearer if the type was completely calculated in the Codegen. Implementing and testing this is a large task, and not something I can myself fix easily. I wonder how to best handle this?The current solution presented would generate valid code, it is just that it will be
Option<List<List<string>>?>
when it should have beenOption<List<List<string>?>?>
for deep aliases (i.e., any?
that isn't the last will be omitted).But as previously stated, this has never been supported before to begin with, so is it something that one should consider too much?