-
Notifications
You must be signed in to change notification settings - Fork 6k
[csharp] clean boolean additional properties #6899
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
[csharp] clean boolean additional properties #6899
Conversation
It appears as though "false" strings in additionalProperties are no longer treated as false booleans. This may be an issue elsewhere, but a simple fix is to always explicitly set the boolean value in a generator class back to the additionalProperties map to convert boolean Strings to boolean Objects.
Some functionality is missing from .NET 4.0, such as IReadonlyDictionary and Type.GetTypeInfo(). This commit resolves compilation of generated .NET 4.0 code, requiring no conditional versioning of Newtonsoft.Json.
I've resolved compilation of .NET 4.0 sample via Jetbrains Rider. The
I'll need to look more closely and see why this error occurs, considering ReadOnlyDictionary wasn't introduced until .net 4.5. |
Sample build.sh wasn't accounting for targeting different FCL correctly. That is, when passing "net40" to the -sdk option, it would use the default -sdk:4 and -langversion:6. These don't necessarily match with what is installed on a machine with only .NET 4.0 (which is our targeted use case here). To resolve, we need to define another version-specific value for passing to the mcs -sdk option (see man mcs for details). This option currently isn't overridable in the client codegen class. Also, langversion is set specifically to the version of C# available to the targeted SDK version. If there is need, we may extend this to something like: langversion=${MCS_LANG_VERSION:-6} To allow users to run as: env MCS_LANG_VERSION=5 sh build.sh I haven't done this because I doubt there's much of a use case via this script. I'm assuming most consumers will build via IDE or MSBuild.
So the issue was that the targetFramework (used in project files) was being used for the To resolve this issue, I've explicitly added a translation value to Once I resolved this issue, I found that specifying After making these changes and cleaning up some of the bash scripts under I know a lot of the commits in the PR are unrelated to the sanitization of booleans, but I figured the build cleanup was directly related. |
@@ -26,6 +26,6 @@ fi | |||
|
|||
# if you've executed sbt assembly previously it will use that instead. | |||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" | |||
ags="generate $@ -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClientNet40 --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} -c ./bin/csharp-petstore-net-40.json" | |||
ags="generate $@ -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l csharp -o samples/client/petstore/csharp/SwaggerClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C}" |
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.
@wing328 Your commit when you implemented .NET 4.0 generator added csharp-petstore-net-40.sh
as well as modifying this file. It looked to me like you may not have meant to make csharp-petstore.sh
compile .NET 4.0?
Feel free to revert this change and the changes in csharp-petstore-all.sh
.
I would actually be cool with making this file compile .NET 4.5 as the minimal example (since 4.5 is an in-place update to 4.0 anyway), and create a separate script for .NET 3.5.
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 was my mistake. Thanks for fixing it.
@@ -17,21 +18,33 @@ | |||
private static final String NET45 = "v4.5"; | |||
private static final String NET40 = "v4.0"; | |||
private static final String NET35 = "v3.5"; | |||
// TODO: v5.0 is PCL, not netstandard version 1.3, and not a specific .NET Framework. This needs to be updated, | |||
// especially because it will conflict with .NET Framework 5.0 when released, and PCL 5 refers to Framework 4.0. |
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.
PCL 5.0 actually refers to .NET Framework 4.6 and higher, .NET Core 1.0 and Windows Universal 10.0. I commented this correctly later in the file. As a TODO, I don't think it's a huge issue.
I'd like to straighten this out before 2.3.0 release.
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.
Yup, 2.3.0 is a release with breaking changes so please feel free to fix these wordings before the release.
} else if (NETSTANDARD.equals(this.targetFramework)) { | ||
// TODO: NETSTANDARD here is misrepresenting a PCL v5.0 which supports .NET Framework 4.6+, .NET Core 1.0, and Windows Universal 10.0 | ||
additionalProperties.put(MCS_NET_VERSION_KEY, "4.6-api"); |
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.
NOTE: I added this, although this NETSTANDARD
isn't writing build.sh
at the moment.
* Revert "[csharp] clean boolean additional properties 6784 (#6899)" This reverts commit 2c9f98c. * Revert "[Swift4] Add throw to reserved words (#6952)" This reverts commit 970de01. * Revert "add a docker build tag for pushing docker image instead of just latest (#6837)" This reverts commit 4e482ee.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
/cc @mandrean @wing328
This is a general cleanup of how we store booleans on
additionalProperties
. It seems as though either"false"
used to be treated in template asfalse
or we were more consistent in replacing false strings with false booleans on theadditionalProperties
object in the C# generators. I personally implemented and tested the functionality in the linked issue, so I'm not sure why something like{{^property}}
is generated regardless of the boolean value now (unless I was crazy when I implemented it 💃 ). I tried to determine why some functionality that has worked before (e.g.nonPublicApi
) doesn't work in 2.2.3 but I was unable to track down any issue. I assume a git bisect would take quite a long time, and handling booleans explicitly seemed both easier and a best practice.I've also taken this opportunity to expose both
supportsAsync
andvalidatable
as options on the C# generator, since these are valid user-defined settings.I've also added some warnings to clarify when the generator removes an explicit setting due to lack of support in the target framework or template. This removal of settings may not be ideal, but my changes in this PR were done to remain consistent with other settings which remove values.
see #6784