-
Notifications
You must be signed in to change notification settings - Fork 6
Refactor and test enum type creation #347
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 squinted at this for a while and I think there's a potential bug if a property has
enumwith more than one value, but I'm not sure if a spec like this would even make sense. I think, in general, you would create more variants?The bug I saw by playing around with the tests is that
convertToValidGoTypeusespropNamefor the struct name whenenumFieldis empty, and so we end up with two structs with the same name (ImageSourcein this case):But again, I think this is an unrealistic scenario, so probably safe to ignore.
The other thing I noticed is that this path is currently triggered once:
But that sounds like a false positive? The generated code looks correct. This is just a bit of noise, so I think safe to ignore if it's hard to avoid 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.
I was also looking at duplicate struct generation when a pathological OpenAPI specification is created with
oneOfvariants. I updated theAddressLotKindscheme like so.{ "description": "The kind associated with an address lot.", "oneOf": [ { "description": "Infrastructure address lots are used for network infrastructure like addresses assigned to rack switches.", "type": "string", "enum": [ "infra" ] }, { "description": "Pool address lots are used by IP pools.", "type": "string", "enum": [ "pool" ] }, { "description": "Testing things.", "type": "object", "properties": { "type": { "type": "string", "enum": [ "foo" ] }, "foo": { "type": "string" } }, "required": [ "allow", "type" ] } ] }Both the changes on this pull request and the current
mainchanges generated the following duplicate types.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.
This was an interesting one since it only occurs for this variant of
DiskSourceeven though another variant usesblock_sizeas well.{ "description": "Create a blank disk that will accept bulk writes or pull blocks from an external source.", "type": "object", "properties": { "block_size": { "$ref": "#/components/schemas/BlockSize" }, "type": { "type": "string", "enum": [ "importing_blocks" ] } }, "required": [ "block_size", "type" ] }It's because the
block_sizehere directly references theBlockSizeschema whereas the other variant usesblock_sizebehind anallOf, like so.