-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Conversation
...napi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
Outdated
Show resolved
Hide resolved
I thought the signature got changed here public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache
Outdated
Show resolved
Hide resolved
Does it makes sense to use static files when swashbuckle is not used? In pure WebApi scenarios? |
Yes - but the old style is still available with a deprecation warning: There are a couple more such warnings that will have to be cleaned up (aside from support for new routing and json libraries) before it is fully ready. |
@ALL |
Does not break 2.2 - did not want to send the PR till the break was fixed. |
edit: n/m. I read the issue before looking at the PR. |
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.
Thanks for this PR. It's looking pretty good. I think the biggest issue is that newtonsoft is still referenced, although it's possible to exclude the library. I had a handful of other logic or user (of the generator) clarifications.
...napi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
Outdated
Show resolved
Hide resolved
@@ -60,18 +64,22 @@ | |||
private boolean useSwashbuckle = true; | |||
protected int serverPort = 8080; | |||
protected String serverHost = "0.0.0.0"; | |||
protected CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 2.2 (default), 2.1, 2.0 (deprecated)"); | |||
protected CliOption swashbuckleVersion = new CliOption(SWASHBUCKLE_VERSION, "Swashbucke version: 3.0.0 (default), 4.0.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.
We should remove default version definition from being embedded in the help text. This will already be displayed via config-help:
swashbuckleVersion
Swashbucke version: 3.0.0 (default), 4.0.0 (Default: 3.0.0)
...napi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
Outdated
Show resolved
Hide resolved
|
||
private void setIsFramework() { | ||
if (aspnetCoreVersion.getOptValue().startsWith("3.")) { | ||
// default, do nothing |
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.
...napi-generator/src/main/java/org/openapitools/codegen/languages/AspNetCoreServerCodegen.java
Show resolved
Hide resolved
private void setUseNewtonsoft() { | ||
if (aspnetCoreVersion.getOptValue().startsWith("2.")) { | ||
LOGGER.warn("ASP.NET core version is " + aspnetCoreVersion.getOptValue() + " so staying on default json library."); | ||
useNewtonsoft = false; |
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 from 3.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 it
} | ||
|
||
private void setSwashbuckleVersion() { | ||
setCliOption(swashbuckleVersion); |
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.
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.
{{#compatibilityVersion}} | ||
.SetCompatibilityVersion(CompatibilityVersion.{{compatibilityVersion}}) | ||
{{/compatibilityVersion}} | ||
.AddJsonOptions(opts => | ||
.{{#useNewtonsoft}}AddNewtonsoftJson{{/useNewtonsoft}}{{^useNewtonsoft}}AddJsonOptions{{/useNewtonsoft}}(opts => |
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 in controller.mustache
and model.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 in 3.x
it is included via the package dependency and for 2.x
is there as part of core fw.
…licitly clear. Also fix small messages for the review comments
I am beginning to think that instead of automatically correcting the value if invalid, then just throw an error. It will simplify some of the logic. The PR does not address supporting the new features of 3.0 - it simply ensure that you can use 3.0 in a backward compatible way. Thoughts? |
Here is what I also would like to hear the opinion. Because if we use the new features of 3.0 we will have to use a new template otherwise maintaining backwards compatibility will be too much. |
What about merging this PR into master and then ask the community for feedback? |
This is not going to work yet. Routing changes are missing. |
@wing328 @A-Joshi
New changes needed
|
Thanks - will take a look this week. Was out of action for some personal
reasons.
…On 6/3/19 4:37 PM, sunn wrote:
@wing328 <https://github.com/wing328> @A-Joshi
<https://github.com/A-Joshi>
I would like to give to give feedback after 3 weeks of using ASP.NET
Core 3.0 Preview 5.
* |Utf8JsonReader| is not feature complete so we are better off for
now using |JSON.NET|
* API Controllers and Controller with views use the Utf8JsonReader
so incompatibility with net core client models. So we should
continue to use ASP.NetCore MVC package
* We can add Razor to to MVC so not an issue there.
* We can continue to use the same generator because the diff from
here mainly is the Configure.
New changes needed
* In |Configure|, endpoint routing has to be activated
* |JSON.NET| has to be added a an external dependency in |.csproj|
* JSON camel case NamingStartegy has to use instead of deprecated
option.
* docker alpine runtime is available
* rest is same :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2824?email_source=notifications&email_token=ADKAIINE3UG6LNGQSIXXINLPYV6HNA5CNFSM4HK3HBRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODW2T2TY#issuecomment-498416975>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADKAIIONWOZI6Y3RXOMUMZ3PYV6HNANCNFSM4HK3HBRA>.
|
Could you give sample of what the changes you needed to do were?
What did you have to change? parameter value to be set?
What was the dependency you needed to add? I think its already there.
Not sure what the change needed was?
Can look at this for the next round.
Can we get the PR added in ? It does not break 2.x and it will be easier to work against the master once this is merged in. |
I did these
In
In
In |
@etherealjoy: Can you test the new push please? @wing328, @jimschubert - Assuming @etherealjoy is good then I suggest we merge it in - there are no changes for the version 2.1/2.2 while this will add preliminary support for 3.0 preview 5 in compatibility mode. |
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache
Show resolved
Hide resolved
I will try this out and give feedback. |
Regarding the recommendation of having 3.0 be a separate generator… Rather than conditionally assigning locations for files between versions (e.g. |
Sounds like a good idea - for now though I would like to keep the
current PR focused on the current changes and then add new changes/ideas
later via different PR.
…On 6/7/19 12:54 PM, Jim Schubert wrote:
Regarding the recommendation of having 3.0 be a separate generator…
Rather than conditionally assigning locations for files between
versions (e.g. |2.2/filename.mustache| and |3.0/filename.mustache|),
why not just use the core generation's |library| feature? These are
different versions of the same library, but there's no reason we can't
use that option to reference library versions. This allows us to put
common code under |resources/aspnetcore| and any version-specific
overrides under their respective library folders. This would be a
breaking change for anyone who has extended templates, so such a
change would have to be done in release 4.1.0. This is just a thought
about managing the concern of maintainability as Microsoft makes
breaking changes between versions. I think it would be much easier to
manage these as libraries rather than completely separate generators.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2824?email_source=notifications&email_token=ADKAIIIYD4XE4IQA4ZF5UK3PZKHEZA5CNFSM4HK3HBRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXGMPQI#issuecomment-499959745>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADKAIIPD72AHSDPOYWBCQ7TPZKHEZANCNFSM4HK3HBRA>.
|
modules/openapi-generator/src/main/resources/aspnetcore/2.1/Startup.mustache
Outdated
Show resolved
Hide resolved
I tried this and it works using these options. java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i \
/home/dev/api/swagger.yaml -o /home/dev/gen --additional-properties \
aspnetCoreVersion=3.0,useNewtonsoft=true,useDefaultRoutng=false,useSwashbuckle=false \
-g aspnetcore However |
You can change the swashbuckle version using the parameter "swashbuckleVersion=4.0.0" I have added 5.0.0 as a possible value but have not tested with that. |
@etherealjoy are you OK with it now? |
Ok from my side. |
Update to swashbuckle 5 is needed to use it with 3.0 but we can do this later. |
Let's merge this and gather feedback from the community. |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{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\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
Preliminary support for ASP.NET Core 3.0 (preview 4). See issue #2350
No support for the new style routing or new Json library (still uses Newtonsoft).