-
Notifications
You must be signed in to change notification settings - Fork 54
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
Generate basic Go module with structures #2
Conversation
Minor suggestion for file/folder naming. I think the following pattern will help the SDK breakup go files into smaller chunks making it easier to view source since the files can be so large. e.g. v1 SDK's service/ec2/api.go file is over 100k lines and no longer can be rendered in github. The v2 SDK's equivalent file is about 10k lines.
|
smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/CodegenVisitor.java
Outdated
Show resolved
Hide resolved
It would be helpful for all generated
General practice is to put it at the top of the file as first line for easier human discovery, but doesn't have to be. |
smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoDelegator.java
Outdated
Show resolved
Hide resolved
smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/GoSettings.java
Outdated
Show resolved
Hide resolved
smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/SymbolVisitor.java
Outdated
Show resolved
Hide resolved
This adds in a bunch of the basic infrastructure necessary to perform code generation. currently all that is generated is a basic `go.mod` file.
This adds the ability to generate structure shapes as well as most primitive shapes. Primitives that require imports and specializations of shapes based on traits (e.g. errors / enums) are also not yet supported. Wholly unsupported shape types currently output `nil` symbols.
`go mod init` will fail if the `go.mod` already exists, so this deletes it if it's present in the output. While it's technically possible to simply edit the file, it's easier to just start fresh.
9af9891
to
f557fdf
Compare
This removes the ability to infer which service should be generated for in a model, instead relying on the setting being explicit.
public String toString() { | ||
String contents = super.toString(); | ||
String[] packageParts = fullPackageName.split("/"); | ||
String header = String.format( | ||
"// Code generated by smithy-go-codegen DO NOT EDIT.%npackage %s%n%n", | ||
packageParts[packageParts.length - 1]); | ||
// TODO: add imports | ||
return header + contents; |
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.
Don't have to do it ATM but wanted to call out, that it would be good to consider how we'll generate summary/overview documentation API packages.
The package doc string should only appear in one file within a package, (e.g. doc.go file) and provides the documentation/summary/overview of a package. We can determine if this should be a canned string, or incorporate documentation provided by the API model, (e.g v1 sdk's ACM)
// Code generated by smithy-go-codegen DO NOT EDIT.
// Package weather provides the client, and types for the Weather API. <- first paragraph is summary
//
// ... could be more that only appears in API docs overview, not included in package's summary.
package weather
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.
Eventually we'll add a useFileWriter
to GoDelegator
, which we'll then use to write out such files. We should include the service shape's documentation there where available.
GoSettings settings = new GoSettings(); | ||
config.warnIfAdditionalProperties(Arrays.asList(SERVICE, MODULE_NAME, MODULE_DESCRIPTION, MODULE_VERSION)); | ||
|
||
settings.setService(config.expectStringMember(SERVICE).expectShapeId()); |
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.
Can you add a TODO for using inferService
from Smithy's codebase instead of just fully removing it?
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.
To be clear, the intent is to never infer the service.
public Symbol stringShape(StringShape shape) { | ||
// TODO: support specialized strings |
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.
assuming specialized strings are enums?
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.
correct
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.
and mediatype
This adds the ability to generate structure shapes as well as most primitive shapes. Primitives that require imports and specializations of shapes based on traits (e.g. errors / enums) are also not yet supported. Wholly unsupported shape types currently output
nil
symbols.The scope of this initial PR was deliberately limited to try to keep its size down, as it already requires a decent amount of infrastructure to get things going.
Currently the following files are generated:
The contents of
go.mod
will look like:The base module name here is configurable.
Based on the
smithy-go-codegen-test
model, the contents ofapi_types.go
will look like:(Note that
go fmt
is being run on the output)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.