Skip to content

bring back enum generation #158

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

Closed
wants to merge 2 commits into from
Closed

bring back enum generation #158

wants to merge 2 commits into from

Conversation

sclasen
Copy link

@sclasen sclasen commented Mar 31, 2015

add back the enum template, and restore the needed funcs for massaging the enums from the schemata.

/cc @dpiddy

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

Fixes #155

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal using the ExportableName method yields some enums that are not go style guide approved, is this ok? I think the exportable func is more stylistically correct?

For instance

-       ConfigurationItemStatusOK         = "Ok"
+       ConfigurationItemStatusOk         = "Ok"

-       ResourceTypeAWSEC2VPNconnection    = "AWS::EC2::VPNConnection"
-       ResourceTypeAWSEC2VPNgateway       = "AWS::EC2::VPNGateway"
        ResourceTypeAWSEC2Volume           = "AWS::EC2::Volume"
+       ResourceTypeAWSEC2Vpnconnection    = "AWS::EC2::VPNConnection"
+       ResourceTypeAWSEC2Vpngateway       = "AWS::EC2::VPNGateway"

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal got rid of the map. Still seems to be an issue with ExportableName though. any advice?

ResourceTypeAWSEC2VPC = "AWS::EC2::VPC"
ResourceTypeAWSEC2Volume = "AWS::EC2::Volume"
ResourceTypeAWSEC2Vpnconnection = "AWS::EC2::VPNConnection"
ResourceTypeAWSEC2Vpngateway = "AWS::EC2::VPNGateway"
Copy link
Author

Choose a reason for hiding this comment

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

@lsegal here is a bad one.

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen ExportableName is used to generate all shape and operation names, so if there is a problem there it is likely affecting other generated names and we should resolve that there. Note that ExportableName needs to be used in the load passes of the API, not during template generation, in order to generate the proper errors when inflections fail.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

sclasen#1 shows the diff of using the original exportable function instead of ExportableName, which results in much better code imo.

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen only for those very specific examples, and it doesn't work in all cases. In order to guarantee consistency across all exported names going forward we need to explicitly whitelist all words (see inflections.csv) we will have to rely on ExportableName.

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen basically the ExportableName function is made to be a more consistent replacement system. If it's not working correctly we need to fix that rather than abandoning it for enums only. The diff showing incorrectly inflected terms like "VPN" lead me to believe that it's not being setup properly, because these terms are being correctly inflected for all other operation / shape names.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal do you mean not set up properly for enums alone somehow or in general not set up correctly?

is there a setup func that one can call on shape.API?

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen given that it works on other shapes, it's probably not setup correctly for enums. I mentioned above how to use the load passes to correctly setup enums while loading instead of while generating template output-- it doesn't look like this is being done.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

Aha missed that comment. wired it in passes instead, and make complains about a ton of missing inflections, I added them and things are looking better.

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

Looks good, but we probably need to go through those inflections and make sure they are correct. I see a few that need some changes.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal looking better, though now I am noticing that the generator is picking up older schemas, for example cloudfront has 2 schemas. Is there an incantation to make the generator pick the later schema?

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen you can explicitly call go run ./internal/model/cli/gen-api/main.go apis/rds/rds-YYYY-MM-DD.normal.json to call for that specific version.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal ok, I deleted the older cloudfront schemas and ran the generator and it is of course correct. Should older shcemas be deleted?

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

@sclasen no, old schemas are supported and may be generated in the future under different packages.

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

Alright, is there a mechanism for using only the latest generator other than explicitly enumerating the go:generate calls in service/generate.go ?

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

moved the old ones to the side for generation for now

@lsegal
Copy link
Contributor

lsegal commented Mar 31, 2015

is there a mechanism for using only the latest generator other than explicitly enumerating the go:generate calls in service/generate.go ?

@sclasen this is not yet supported. As mentioned in the comments, the SDK should be generating with the latest API version, but there might be another (unrelated) generator bug here.

Between:
Eip:EIP
Vpnconnection:VPNconnection
Vpngateway:VPNgateway
Copy link
Author

Choose a reason for hiding this comment

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

Assume these 2 should be VPNConnection and VPNGateway @lsegal ?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@sclasen
Copy link
Author

sclasen commented Mar 31, 2015

@lsegal deduped inflections, were a ton! let me know if anything else is needed.

@sclasen
Copy link
Author

sclasen commented Apr 1, 2015

squashed commits

@danp
Copy link
Contributor

danp commented Apr 1, 2015

👏

@sclasen
Copy link
Author

sclasen commented Apr 2, 2015

@lsegal anything needed here? we have a pile of code that uses the pre develop-merge code, and we use quite a ton of the consts, so we cant switch over till this goes in.

@lsegal
Copy link
Contributor

lsegal commented Apr 6, 2015

@sclasen looking through the generated inflections, I'm still seeing a lot of missing or incorrect entries. Ideally all country codes, for example, should be capitalized. We'll still need some time to look through the code in this PR and make sure it's generating the right things.

I think there's also still a general question about how these enums will be exposed and what kind of possible bloat will they be providing. Some of this discussion may change how the generation is done. Right now, the generated constants have no association to the structure types they are being used inside of, which makes for a poor documentation story. One thing that could alleviate this would be to create special string alias types for these constants, which would give better visibility to where these constants are used. Another thing I noticed is that the type prefix on these constants occasionally makes for very long names, which could potentially be resolved by relying on the type alias for communicating part of that name. Finally, I'm concerned about some constants bloating the package, specifically the country codes in Route53 Domains, which seems a little superfluous to me. Having a list of 100+ constants in documentation might be distracting and not really provide that much value.

Again, I'm not opposed to constants, but I'd like to see if we can address some of these points before merging.

In the meantime, while we look at the inflections and think about how to improve visibility in documentation, you should be able to generate these constant names in a separate package in your own codebase (i.e. copy paste the string consts you use) and import that for now. That should unblock you until this gets merged in while still allowing you to switch over the rest of your code.

@sclasen
Copy link
Author

sclasen commented Apr 6, 2015

Thanks @lsegal

fwiw I have found the type prefixes on the constants pretty helpful, especially from an autocomplete perspective, you type swf.EventType<autocomplete keystroke> and get a dropdown of all the correct consts.

My fear is that if we use type aliasing instead of prefixes, the tooling will have to be much smarter to give you a reasonable dropdown. Long names are not a problem with tooling.

Do you think adding a enum generation blacklist mechanism would help? Unhelpful enums such as route53domains country code could simply be skipped. Let me know if you'd like me to add that feature.

@sclasen
Copy link
Author

sclasen commented Apr 11, 2015

@lsegal another question here, but more general.

Is it sane to consider building other (external to this project) generators, based on internal/model/api/API.go

If it were fairly well documented/stable it would be pretty easy to show folks how to generate arbitrary code that you dont necessarily want in this project. For instance

package main

import(
    "github.com/awslabs/aws-sdk-go/internal/model/api"
    "os"
    "fmt"
)


func main(){
    service := "swf"
    date := "2012-01-25"
    gopath := os.Getenv("GOPATH")
    api := new(api.API)
    api.Attach(fmt.Sprintf("%s/src/github.com/awslabs/aws-sdk-go/apis/%s/%s.normal.json", gopath, service, date))
    for _, o := range api.ShapeList(){
        if len(o.Enum) > 0 {
            for _, e := range o.Enum {
                fmt.Printf("%s->%s\n", o.ShapeName, e)
            }
        }
    }
}

@danp
Copy link
Contributor

danp commented May 8, 2015

@lsegal any thoughts on @sclasen's responses? Would be great to get some movement on this. Looks like it needs a rebase as well.

@lsegal
Copy link
Contributor

lsegal commented May 12, 2015

@dpiddy @sclasen we're still looking at this. I think the best way to move forward is to use the generated enums in an external (vendored) package so you are not blocked by this pull request. Specifically, given the simplicity of the enums themselves, you don't even need to rely on the internal logic (i.e. #201) to parse the JSON models and pull out enum structures into Go code.

@lsegal
Copy link
Contributor

lsegal commented May 12, 2015

For example, here's a playground link for parsing enums out of an abridged version of the autoscaling/2011-01-01.normal.json file: http://play.golang.org/p/JLHAHwOusH

It would be fairly simple to convert this into a generalized executable to write enums for various service packages.

lsegal added a commit that referenced this pull request Jul 16, 2015
Note that this change disables inflections for all enum constants.

Resolves #158
Fixes #155
@lsegal lsegal mentioned this pull request Jul 16, 2015
@lsegal lsegal closed this in b311b2e Jul 28, 2015
jasdel added a commit that referenced this pull request Jul 28, 2015
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