-
Notifications
You must be signed in to change notification settings - Fork 6
chore: go generate ./... #61
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1d8eb0
regenerate
moredure 3cc88c8
chore: regenerate management spec
victoreronmosele 848de6a
chore: upgrade github.com/quic-go/quic-go to v0.59.1
victoreronmosele 92be3bb
management_api: add compat aliases for DeleteAPIAppliationScope rename
dtoxvanilla1991 c529d78
management_api: fail closed on ambiguous connection options oneOf
dtoxvanilla1991 8cad83c
management_api: make the oneOf fail-closed fix durable across regens
dtoxvanilla1991 237c72d
fix: fail go generate when a oneOf fallback survives patching
Koosha-Owji 9521303
fix: validate before writing
Koosha-Owji 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Hand-written compatibility shim: not generated by ogen, not touched by `go generate ./...`. | ||
| package management_api | ||
|
|
||
| import "context" | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeOperation. Kept for source | ||
| // compatibility with the pre-typo-fix operation name. | ||
| const DeleteAPIAppliationScopeOperation = DeleteAPIApplicationScopeOperation | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeParams. | ||
| type DeleteAPIAppliationScopeParams = DeleteAPIApplicationScopeParams | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeRes. | ||
| type DeleteAPIAppliationScopeRes = DeleteAPIApplicationScopeRes | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeOK. | ||
| type DeleteAPIAppliationScopeOK = DeleteAPIApplicationScopeOK | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeBadRequest. | ||
| type DeleteAPIAppliationScopeBadRequest = DeleteAPIApplicationScopeBadRequest | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeForbidden. | ||
| type DeleteAPIAppliationScopeForbidden = DeleteAPIApplicationScopeForbidden | ||
|
|
||
| // Deprecated: use DeleteAPIApplicationScopeTooManyRequests. | ||
| type DeleteAPIAppliationScopeTooManyRequests = DeleteAPIApplicationScopeTooManyRequests | ||
|
|
||
| // DeleteAPIAppliationScope invokes DeleteAPIApplicationScope operation. | ||
| // | ||
| // Deprecated: use DeleteAPIApplicationScope. | ||
| func (c *Client) DeleteAPIAppliationScope(ctx context.Context, params DeleteAPIAppliationScopeParams) (DeleteAPIAppliationScopeRes, error) { | ||
| return c.DeleteAPIApplicationScope(ctx, params) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| //go:build ignore | ||
| // +build ignore | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "os" | ||
| "regexp" | ||
| "strings" | ||
| ) | ||
|
|
||
| // This tool patches the generated oas_json_gen.go file to stop ambiguous oneOf | ||
| // decoding from silently defaulting to variant 0. When one oneOf variant has | ||
| // no fields unique to it, ogen makes it the sum type's default mapping and | ||
| // falls back to it whenever no discriminating key matches, which can misroute | ||
| // a payload (e.g. decode a SAML/enterprise connection config as a plain OAuth | ||
| // one) once sibling variants share field names. This makes it fail closed. | ||
|
|
||
| const targetFile = "oas_json_gen.go" | ||
|
|
||
| // Matches the generated "if !found { s.Type = <value> }" fallback. <value> is | ||
| // checked separately for the "X0X" sum-type-variant-0 shape (Go's regexp | ||
| // package has no backreferences), e.g. | ||
| // CreateConnectionReqOptions0CreateConnectionReqOptions. | ||
| var fallbackPattern = regexp.MustCompile(`if !found \{\n\t\ts\.Type = (\w+)\n\t\}`) | ||
|
|
||
| // remainingFallbackPattern is a looser tripwire: any `if !found` block that | ||
| // still assigns s.Type before its closing brace. If it matches after the | ||
| // patch pass, the generated shape has drifted past fallbackPattern (or a sum | ||
| // type gained a non-variant-0 default) and the generate run must fail rather | ||
| // than ship the silent-default behaviour. | ||
| var remainingFallbackPattern = regexp.MustCompile(`if !found \{[^}]*s\.Type\s*=`) | ||
|
|
||
| // isVariant0Assignment reports whether value has the "X0X" shape ogen uses | ||
| // for a sum type's zero-variant constant. | ||
| func isVariant0Assignment(value string) bool { | ||
| n := len(value) | ||
| if n < 3 || n%2 == 0 { | ||
| return false | ||
| } | ||
| half := (n - 1) / 2 | ||
| return value[half] == '0' && value[:half] == value[half+1:] | ||
| } | ||
|
|
||
| func main() { | ||
| fmt.Printf("Patching %s for ambiguous oneOf handling...\n", targetFile) | ||
|
|
||
| content, err := os.ReadFile(targetFile) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| patched := 0 | ||
| newContent := fallbackPattern.ReplaceAllFunc(content, func(match []byte) []byte { | ||
| sub := fallbackPattern.FindSubmatch(match) | ||
| if sub == nil || !isVariant0Assignment(string(sub[1])) { | ||
| return match | ||
| } | ||
| patched++ | ||
| return []byte(`if !found { | ||
| return errors.New("unable to detect sum type variant") | ||
| }`) | ||
| }) | ||
|
|
||
| // Validate before writing so a failed run leaves the file exactly as ogen | ||
| // generated it, never partially patched. | ||
| if locs := remainingFallbackPattern.FindAllIndex(newContent, -1); len(locs) > 0 { | ||
| fmt.Fprintf(os.Stderr, "Error: %d oneOf fallback(s) would still assign s.Type after patching:\n", len(locs)) | ||
| for _, loc := range locs { | ||
| line := 1 + bytes.Count(newContent[:loc[0]], []byte("\n")) | ||
| snippet := strings.Join(strings.Fields(string(newContent[loc[0]:loc[1]])), " ") | ||
| fmt.Fprintf(os.Stderr, " %s:%d: %s\n", targetFile, line, snippet) | ||
| } | ||
| fmt.Fprintf(os.Stderr, "The generated shape has likely changed (ogen upgrade?) - update fix_oneof.go\n") | ||
| fmt.Fprintf(os.Stderr, "%s left unmodified\n", targetFile) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if patched == 0 { | ||
| fmt.Println("No ambiguous oneOf fallback found - already patched or no longer generated") | ||
| return | ||
| } | ||
|
|
||
| if err := os.WriteFile(targetFile, newContent, 0644); err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error writing patched file: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("✅ Patched %d ambiguous oneOf fallback(s) to fail closed\n", patched) | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.