-
Notifications
You must be signed in to change notification settings - Fork 737
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
Refactor code model #1444
Refactor code model #1444
Conversation
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.
Only minor changes. If you want to make the Plugin change before submitting, I can take a look again
/// <returns></returns> | ||
public abstract Task Generate(ServiceClient serviceClient); | ||
public virtual /* async */ Task Generate(CodeModel codeModel) |
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.
Are we moving towards making Generate async?
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.
Yes
{ | ||
using (_context.Activate()) | ||
{ | ||
try { File.WriteAllText(@"c:\tmp\orig.json",jsonText); } catch { } |
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.
Non-windows? Maybe use Path.GetTempPath?
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.
ah, that was there for my debugging pleasure. Will be gone in the next commit.
@@ -0,0 +1,16 @@ | |||
// Copyright (c) Microsoft Corporation. All rights reserved. | |||
// Licensed under the MIT License. See License.txt in the project root for license information. | |||
// |
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.
Very minor: a few of these files have extra comment lines in the header
/// <summary> | ||
/// Allows a type to append extra documentation on a property | ||
/// </summary> | ||
public virtual string ExtendedDocumentation => null; |
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 ExtendedDocumentation is another one that we'll want fixable eventually, but I can't think of the use case right now. I imagine we'll convert them on an as-needed basis?
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.
Yeah, we may make a lot of them fixable in the long run. First step was just to get it working, refinements can be made along the way.
Merging into branch -- will promote to master once the other generators are converted |
* Refactor code model (#1444) * CodeModel Refactoring - Moved/Renamed Files * CodeModel Refactoring - Changes to AutoRest/AutoRest.Core * CodeModel Refactoring - Core Tests changes * CodeModel Refactoring - AutoRest.Extensions changes * CodeModel Refactoring - AutoRest.Extensions Tests changes * CodeModel Refactoring - Fix compiler warnign * CodeModel Refactoring - CSharp Generator * CodeModel Refactoring - CSharp Azure Generator * CodeModel Refactoring - CSharp Tests Changes * CodeModel Refactoring - NodeJS changes * CodeModel Refactoring - NodeJS Azure changes * CodeModel Refactoring - Modeler changes * Fix/enable all tests * Fix up c# unit tests * small fixes in Moder * Some last-minute tweaks to the generators to pass tests * Changes to finish getting all the tests to run (in core) * Extensions tests cleanup * Resharper settings * Tweaking the build to build and test ok via gulp * accidentally overwrote fix for in memory assemblies * Fixed glitch in builing * Tweaking build for linux * cleaning up small issues and removing superflous junk * cleaned up stuff around nullability (and some other minor cleanups) * cleaned up stuff around nullability (and some other minor cleanups) - c# * Regenerated Tests Expected files * small code cleanups * Adding compare script to validate against rest-api-specs repo * added report generation to compare script (requires Araxis Merge installed and configured) * fixed use of clientproperty == null (should use !IsClientProperty) * Introduced Plugin Model (refactored plugin classes) (#1509) * Adding validation rules for subscriptionId/api-version params * Introduced Plugin Model (refactored plugin classes) * [Python] CloudError updates (#1510) * Updated CloudError * Added exception documentation * Regenerated tests * All tests working * [Go] Paging tests and general paging fixes (#1489) * Trying to delete duplication * Graph doesn't duplicate odatanextlink * OdataNextLink not duplicated and correctly named * Not needed preparers for paged results are no longer included in models file. This also causes that if there is already a next method defined in swagger for that model (including generic next methods), autorest wont generate the specific next links. * Added paging tests (except fragment link) * Added fragment next link test * Fixed code about preparer for pages types * msrestazure 0.4.4 (#1514) * Addressed PR comments * Remove Python msrest/msrestazure from Autorest repo (#1518) * Remove msrest from Autorest repo * Remove Python msrest from gulpfile * Remove hack in msrestazure to read ../msrest * Update dependencies of Python msrestazure to get msrest from PyPI * Adding mock in msrestazure tests * Simplify tox config for msrestazure * msrestazure 0.4.4 (#1514) * Remove msrestazure Python * Minor code cleanup * Fixing json descriptions * Add min length and max length support to schema generator (#1503) * Add ServiceBus AzureResourceSchema acceptance test * Add minLength and maxLength support to schema generator * Fixing logic to add missing schema resources * Add sql schema test (#1486) * Add ServiceBus AzureResourceSchema acceptance test * Add SQL schema test and fix NotificationHubs schema test * Add service fabric schema tests (#1485) * Add ServiceBus AzureResourceSchema acceptance test * Add ServiceFabric schema test, fix NotificationHubs schema test * Updates/cleanups to plugin model,core and node/c# * small updates to modeler classes * updated project.json files * fixing tests * fixed loader test * Bumping version to fix nuget problem * Updated AzureResourceGenerator to work in new code model * Ruby Refactored To New Code Model (#1535) * Ruby Refactored To New Code Model * fixed small glitches in generator * reverted incorrect fix * checkpoint - work in progress * checkpoint - work in progress #2 * checkpoint - work in progress #3 * stop generating tmp files * Upcased Module name for enums * Added ModuleName to EnumTypeRb * Used Rb type EnumType in Plugin * sigh * Deleted missing paren * Update CodeGeneratorRba.cs * Update CodeGeneratorRb.cs * merge from master and regenerate a couple files * Update gulpfile.js * Fixing property names with leading underscores (#1546) Fixing property names with leading underscores * Changes to the Python Code Generator for the Refactored Code Model (#1539) * Checkpoint - Merged RefactorCodeModel and NewPython branches * Checkpoint - Merged RefactorCodeModel and NewPython branches * Missed file * Checkpoint - Python, tracking down last glitches (still have to fix the composite swagger merge problem) * Checkpoint - Python cleaned up some more glitches * Make sure that compositemodeler is using types from the model. * Python Changes, reviewed by @anna and @lmazuel * regenerated tests * fixup node test failure after refactor * fixed overzealous use of capital 'd' Decimal * updated version to 1.0 ( still in preview) * Temporarily removing Go, Java, Fluent projects from solution until stable in new model
Welcome to the great Code Model Refactor!
[Still editing this doc]
The overall purpose of this rather large refactoring is to make the whole
CodeModel
(aka,ServiceClient
) smarter, more consistent, and drive behavior into the code model classes, and remove unnecessary mutability from the model. (a small example: if a property was using anEnumType
as nullable, then it modified the actualEnumType
to be nullable, and every use of that would be.)There were also these huge 'normalization' steps which would go thru and rewrite parts of the model. This made it kinda tricky to handle certain kinds of behavior, and track down where stuff went...
After the refactoring, behavior is delegated to the actual type (so, rather than have a
normalize
method change the output name of aPrimaryType
), that name is simply overrideable in the subclass directly.Everything now has a ref to their parent, (so a
parameter
can walk back up to themethod
, themethodgroup
or even up to the top of the model now)Plus, all 'transformation' of a model are now handled in discrete steps (and can be spit out to JSON and brought back in between steps.)
The foundation for a pluggable transformer model is in here too
Initially, this was not going to be such a radical change, but in order to accomplish certain things, one thing led to another, and, well, this gets us to a really nice spot.
Notable Changes:
Dependency Injection System
With this patch, I've introduced the the
Least Offensive Dependency Injection System
™️ (akaLODIS
)See: https://github.com/Azure/autorest/wiki/Least-Offensive-Dependency-Injection-System
Fixable
valuesThe notion of values which the final value can be both derived or a fixed literal value: https://github.com/Azure/autorest/wiki/Fixable-T----When-a-value-is-both-calculated-and-or-fixed.
Generator/Transformer/Namer model
Basics of the new Code Model: https://github.com/Azure/autorest/wiki/CodeModel-and-the-Language-specific-Generator-Transformer-Namer
Name Disambiguation
Learn a bit about the name disambiguation here: https://github.com/Azure/autorest/wiki/Name-Disambiguation