Skip to content
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

Implement discriminator support in v3 generator #113

Merged
merged 10 commits into from
Apr 2, 2018

Conversation

vladbarosan
Copy link

Fixes Azure/azure-sdk-for-go#1177

  • Port various fixes from v2 generator
  • port discriminator support
  • implement support in xml
  • Seperate xml and json marshallers

@ghost ghost assigned vladbarosan Mar 22, 2018
@ghost ghost added the review label Mar 22, 2018
@vladbarosan
Copy link
Author

vladbarosan commented Mar 22, 2018

/// <summary>
/// Gets if the property should be treated as a pointer
/// </summary>
public bool IsPointer => !(this.ModelType.HasInterface() || IsRequired || ModelType.CanBeNull() || ModelType is EnumTypeGo);
Copy link
Author

@vladbarosan vladbarosan Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnumTypeGo [](start = 120, length = 10)

in v2 we had the extra condition here to be a named enum to be a value type. But I saw we were not using that in v3. Let me know if we want to add the extra criteria

@@ -17,7 +17,6 @@ public class CodeGeneratorGo : CodeGenerator
private const string ModelsFileName = "models";
private const string ClientFileName = "client";
private const string VersionFileName = "version";
private const string MarshallingFileName = "marshalling";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarshallingFileName [](start = 29, length = 19)

note that I removed the marshalling file from the output. it seems most of it should go to the models file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this file was to separate the exported types from the non-exported types/implementation details (i.e. the content of marshalling.go is interesting to us but not to consumers of the SDK). If merging this into the models file makes it easier to generate the content then we can leave it merged.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, but I think to keep the generator code cleaner its easier to put them in the models also would prefer to have all the publicly used types ( and their marshallers ) to be in the models.

return d.DecodeElement(@local, &start)
}
</text>
}
Copy link
Author

@vladbarosan vladbarosan Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go in the marshallingxml template

@using AutoRest.Core.Model
@using AutoRest.Core.Utilities
@using AutoRest.Go
@using AutoRest.Go.Model
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main interest is on the xml so maybe focus on this one

@vladbarosan
Copy link
Author

Also note that right now for XML we are using the tag names to determine the specific type in polymorphic situations. This is what storage supports right now.

case PrimaryTypeGo primaryType:
primaryType.AddImports(imports);
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default [](start = 16, length = 7)

Could a different go type arrive here? Something different to a sequence?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have it the same in the v2 generator. looking at it, Composite Type also has AddImports but that will be just the imports of its fields

@EmptyLine
@if (values.Any())
@if (Model.Values.Any())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the above declaration of values no longer needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes ill remove

@olydis
Copy link
Contributor

olydis commented Mar 27, 2018

🤖 AutoRest automatic publish job 🤖

success (version: 3.0.46)

@vladbarosan vladbarosan force-pushed the implementDiscriminator branch 2 times, most recently from 7191b0e to 531d631 Compare March 30, 2018 19:22
@vladbarosan
Copy link
Author

for blobs look at changes introduced in the last commit : https://github.com/vladbarosan/azure-storage-blob-go/tree/vladdb

return $"Azure-SDK-For-Go/{Version} arm-{Namespace}/{ApiVersion}";
}
}
public string UserAgent => $"Azure-SDK-For-Go/{Version} arm-{Namespace}/{ApiVersion}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small tweak unrelated, could you remove that "arm-" prefix?

@@ -70,18 +70,18 @@ type Error struct {
}

// Response returns the raw HTTP response object.
func (e Error) Response() *http.Response {
return e.rawResponse
func (eVar Error) Response() *http.Response {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this var name changed? Not a big deal, just wondering.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we added a couple of reserved names and e was one of them.

Copy link
Member

@jhendrixMSFT jhendrixMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with just a few comments/questions.

@vladbarosan vladbarosan merged commit dfc293c into Azure:v3 Apr 2, 2018
@ghost ghost removed the review label Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants