[C#][aspnet] use default in model constructors, supports enums#4573
Merged
wing328 merged 3 commits intoswagger-api:masterfrom Jan 18, 2017
Merged
[C#][aspnet] use default in model constructors, supports enums#4573wing328 merged 3 commits intoswagger-api:masterfrom
wing328 merged 3 commits intoswagger-api:masterfrom
Conversation
See original issue swagger-api#3608 This adds same model constructor logic to aspnetcore as what was added to csharp generator by PR swagger-api#4145. This doesn't include NancyFX because model construction relies more on object initialization in that generator.
This follows up to swagger-api#4145, and modifies model constructors to use default(x) instead of initializing to nulls. default(x) works in all cases using intuitive default values it is intended to support. Example: csharp> public enum Color { RED = -1, BLUE = 0, GREEN } csharp> var color = default(Color) csharp> color BLUE In the above example, The default of BLUE=0 is expected. For nullable enums, this would be null as a default. The aspnetcore generated code is also updated to support enums and nested enums to account for changed to the petstore.yaml used to generate the sample.
Contributor
|
@jimschubert thanks for the PR and the solution to address the SSL issue. |
davidgri
pushed a commit
to davidgri/swagger-codegen
that referenced
this pull request
May 11, 2017
…er-api#4573) * [aspnetcore] Use default rather than null in ctor See original issue swagger-api#3608 This adds same model constructor logic to aspnetcore as what was added to csharp generator by PR swagger-api#4145. This doesn't include NancyFX because model construction relies more on object initialization in that generator. * [aspnetcore] ctor defaults + enum support This follows up to swagger-api#4145, and modifies model constructors to use default(x) instead of initializing to nulls. default(x) works in all cases using intuitive default values it is intended to support. Example: csharp> public enum Color { RED = -1, BLUE = 0, GREEN } csharp> var color = default(Color) csharp> color BLUE In the above example, The default of BLUE=0 is expected. For nullable enums, this would be null as a default. The aspnetcore generated code is also updated to support enums and nested enums to account for changed to the petstore.yaml used to generate the sample. * [aspnetcore] Regenerate sample
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0branch for breaking (non-backward compatible) changes.Description of the PR
This addresses a couple of issues. As originally reported in #3608 and added to the C# client generator in #4145, this updates model constructors to use
default()rather than attempting to initialize parameters to nulls. I didn't modify the NancyFX generator here, because it relies on object initialization and doesn't perform the same types of constructor validations or DataAnnotations/JSON validation.The
petstore.yamlhas inner enums, so to get the sample code working against this yaml I've also added support for enums and inner enums, and regenerated the sample.Please note if you're having issues with newer versions of
dotnetCLI, there's a known issue (https://github.com/dotnet/corefx/issues/9171) with OS X/macOS support which requires linking openssl manually:To test:
NOTE:
If you receive the following error on build, you'll need to perform the openssl symlinks mentioned above: