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

Use Stencil Templating engine to create service files #153

Merged
merged 23 commits into from
Aug 17, 2019

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Jul 29, 2019

Uses https://github.com/stencilproject/Stencil to create service files.

  • Stencil templates are in CodeGenerator/Templates folder.
  • CodeGenerator.swift now generates the dictionaries to send to Stencil
  • Did a general code tidy up
  • The Code Generator is not dependent on aws-sdk-swift-core anymore
    I added a few minor features while doing this
  • Markup deprecated AWS commands
  • Added xml namespaces where needed

This is so I can compare with newly generated files which are built from template files and seem to require a new line at the end
Updated stencils to get them to be as accurate to original output
One difference in ElasticBeanstalk_Shapes.swift where the parameters p99 and p999 are ordered differently
- Changed AUTOMATICALLY GENERATED message to point to swft-aws
- Removed newline near end of api files
- Tidied up template files to make them easier to read
- Sort variables by their lowercase version
I made an addition to Stencil which removes newlines immediately after blocks. Using this I could then clean up the stencil templates to make them a lot easier to read.
Unfortunately development on Stencil seems to have gone quiet so forked the repository and made the change locally.
Copy link
Member

@Yasumoto Yasumoto left a comment

Choose a reason for hiding this comment

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

Some minor questions; this is amazing!

To make sure I'm understanding, we now split this into two phases. The first builds up the contexts, then we drop those into the stencil templates.

This looks so great! Thanks for leading the charge here!!

.package(url: "https://github.com/swift-aws/aws-sdk-swift-core.git", .branch("master")),
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", .upToNextMajor(from: "17.0.2"))
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", .upToNextMajor(from: "17.0.2")),
.package(url: "https://github.com/adam-fowler/Stencil.git", .upToNextMajor(from: "0.13.4"))
Copy link
Member

Choose a reason for hiding this comment

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

And to confirm, the plan is to move back to upstream once this is merged, yah? (thanks for finding + fixing!)

stencilproject/Stencil#281

Copy link
Member Author

Choose a reason for hiding this comment

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

I have one other more important change, that implements the clearing of whitespace based on changes from another pull request. I struggled to merge that into the head so re-implemented it. It is more important that that PR is merged into the head of Stencil. For now when this goes into aws-sdk-swift I was going to create a fork Stencil with my changes into swift-aws so the code is centralised.

@@ -7,10 +7,10 @@ let package = Package(
.executable(name: "aws-sdk-swift-codegen", targets: ["CodeGenerator"])
],
dependencies: [
.package(url: "https://github.com/swift-aws/aws-sdk-swift-core.git", .branch("master")),
Copy link
Member

Choose a reason for hiding this comment

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

So awesome 👏

@@ -254,6 +258,7 @@ struct AWSService {
var shapes = [Shape]()
for (key, json) in apiJSON["shapes"].dictionaryValue {
do {
//if json["deprecated"].bool == true { continue }
Copy link
Member

Choose a reason for hiding this comment

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

Delete?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep ok

case .string(_):
return "String"
case .integer(_):
return "Int32"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should just use Int if possible, yah?

Unless you need to work with a specific size of integer, always use Int for integer values in your code.
Section on Int

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah gonna do that in a later change

return "let \(name.toSwiftVariableCase()): \(swiftTypeName)\(optionalSuffix)"

struct OperationContext {
let comment : [String.SubSequence]
Copy link
Member

Choose a reason for hiding this comment

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

A minor nit, how come the space before the :?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess that's something I've always done. Can change if required

@adam-fowler
Copy link
Member Author

So yes you are correct. We build up the contexts and then these are 'rendered' using the stencil templates. The dictionary keys / structure member names, correspond to the names used in the templates.

Copy link
Member

@Yasumoto Yasumoto left a comment

Choose a reason for hiding this comment

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

Thanks!

If partition endpoint is set ensure all regions setup their endpoint correctly
Copy link
Member

@jonnymacs jonnymacs left a comment

Choose a reason for hiding this comment

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

brilliant!

@adam-fowler adam-fowler merged commit b92ee54 into soto-project:master Aug 17, 2019
@adam-fowler adam-fowler deleted the stencil branch August 17, 2019 21:46
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.

3 participants