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.
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
[aspnetcore]: Preliminary support for ASP.NET 3.0 Core preview 5 #2824
[aspnetcore]: Preliminary support for ASP.NET 3.0 Core preview 5 #2824
Changes from 4 commits
e79107f
07a9a15
a99b3c7
e165cfe
1ebc2fb
e8a1597
2864707
6e92c84
2d5229e
8e0aa95
1c543c7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
We should remove default version definition from being embedded in the help text. This will already be displayed via config-help:
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.
this block is setting a field and has a side effect of assigning a key/value in
additionalProperties
. Saying "do nothing" could be confusing. Similarly, "3.x" isn't the default defined in this type and could be confusing. Should probably remove comment since the log message below provides runtime and in-code explanation.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 feel like there's either a typo here or on the conditional a couple lines above. Is it intentional to disallow JSON.net in aspnetcore 2.x? If so, this may be considered a breaking change and should probably be done separately from this PR to generate discussion.
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.
The change is not a breaking change:
This one is a little tricky - the MVC configuration in 2.x and 3.x use AddJsonOptions but mean different things: the default JSON in 2.x is implicitly Newtonsoft, while in 3.x and later it will be the Microsoft one.
I can change it use something like useDefaultJson or jsonLibrary. I don't like the former since the default in different cases means different things. Maybe explicitly defining the jsonLibrary as Newtonsoft or Microsoft but that makes the mustache file complex - since mustache does not have conditionals based on values.
What are your thoughts there?
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.
My main concern is that for 2.x, when
useNewtonSoft
is false, this results in the NewtonSoft library not being referenced, but is still used on controllers and models. From a maintainability perspective (both built-in templates and custom user templates), I find that very confusing.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
2.x
NewtonSoft
is used by the framework by default itself because it is part of the fw, but MS removed it from the framework starting from3.x
and manual addition of package is needed.Which in this case the user really has no choice to not use NewtonSoft in
2.x
Since we would need to use
NewtonSoft
for model compatibility reasons it does not makes sense to allow the user to set this flag because if the fw is >3.x
we will need to add itThere 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.
Long comment, but minor (can be addressed later).
Only the CLI should be setting CLI options. We should read options once (in
processOpts
), then have nothing to do with CLIOption types. That is, we should load into fields and work from those fields directly. I'm concerned that making this method side-effecting as it is and assuming options parsing within the generator, things can become out of sync.For example, a user can pass
--additional-properties=swashbuckleVersion=3.0.5". Although this isn't defined in the enum of available versions, this is a valid use case that we allow for properties defined in
additionalProperties; this is why you often see the guard that we only set the value if it doesn't already exist.
CodegenConfiguratoralso allows for JSON deserialization into the
CodegenConfigurator` type (to load these values from a config), which sorta bypasses both the cli options and additional properties (see CodegenConfigurator).In all of these cases, this method will reset the user-provided value to whatever is originally hardcoded as the swashbuckleVersion default within the generator.
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.
The other choice here is to check the version of Swashbuckle is valid for the ASP.NET Core chosen and throw an error if the version is not valid.
In this particular case I think you can use v 4.0.0 with version 2.x and 3.x but you cannot use v3.0.0 with 3.x and later.
What are you thoughts here - error or warn and correct - not sure what the general policy for this is.
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 think my preference would be to set a default if one doesn't exist, and warn if it's something we don't expect will work. We'll probably want to be clear that anything below 4.0.0 may not work, but trust that the user understands the versioning. For example, someone might have a fork of Swashbuckle which does work, and they could reference and add the file with the reference to
.openapi-generator-ignore
. In that case, a warn+correct would be unexpected if the value was explicitly provided.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.
Variable
useNewtonsoft
will also need to be evaluated incontroller.mustache
andmodel.mustache
. Currently, the artifact won't be loaded, but controllers and models are still tightly coupled to json serialize/deserialize using the library.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.
see the earlier comment about setting the value of useNewtonsoft.
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'm not sure I follow.
To put the concern a different way, as a user if I set
useNewtonSoft=false
, and the controller/model generation still includes NewtonSoft imports, I'd consider that a bug. Maybe the variable name is what's misleading here.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.
Indeed, since the models are generated with
Netwonsoft
in mind it is required that in3.x
it is included via the package dependency and for2.x
is there as part of core fw.