-
Notifications
You must be signed in to change notification settings - Fork 31
Generate compiling models for formatted string fields #343
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
Open
arpitjain099
wants to merge
1
commit into
crossplane:main
Choose a base branch
from
arpitjain099:fix/schema-gen-formatted-string
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−1
Open
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge crossplane/cli /tmp/coderabbit-repo-knowledge/crossplane-cli-9b32699c/learnings /tmp/coderabbit-repo-knowledge/crossplane-cli-9b32699c/conventionsLength of output: 8752
🏁 Script executed:
Repository: crossplane/cli
Length of output: 5046
🏁 Script executed:
Repository: crossplane/cli
Length of output: 4949
🏁 Script executed:
Repository: crossplane/cli
Length of output: 50370
🔍 Additional research query:
Context7: inspect the version-applicable github.com/oapi-codegen/runtime/types.File implementation and its DeepCopy or Bytes semantics; identify whether File contains []byte and *multipart.FileHeader and whether copying by value aliases mutable state💡 Result:
No relevant context found from external knowledge sources.
🏁 Script executed:
Repository: crossplane/cli
Length of output: 50370
🌐 Web query:
github oapi-codegen runtime types.File source Bytes multipart.FileHeader💡 Result:
In the context of oapi-codegen,
types.File(found ingithub.com/oapi-codegen/runtime/types) is a specialized type designed to handle file uploads, particularly when working withmultipart/form-data[1][2][3]. Key interactions betweentypes.Fileand file data include: Initialization You can populate atypes.Filestruct from existing multipart data or raw bytes: - InitFromMultipart(header *multipart.FileHeader): This method allows you to initialize atypes.Fileinstance directly from amultipart.FileHeader, which is the standard Go type for files received in a multipart request [1]. - InitFromBytes(data []byte, filename string): This method allows you to manually create atypes.Fileby providing the file content as a byte slice along with a filename [1]. Accessing Data - Bytes: This method returns the underlying file content as a[]byte[1][2][3]. - Reader: This method returns anio.ReadCloserto stream the file content [1]. - Filename: Returns the associated filename [1][2]. - FileSize: Returns the size of the file in bytes [1]. Important Considerations - Binding: Whileoapi-codegengenerates structs usingtypes.Filefor multipart fields, automatic binding (e.g., using standard framework binders like Echo's) often faces challenges because framework binders typically do not recognizetypes.Fileas a standard multipart type and may require custom handling or strict server implementations to function correctly [4][5]. - Deprecation: Older versions of oapi-codegen usedgithub.com/deepmap/oapi-codegen/pkg/types. Newer versions usegithub.com/oapi-codegen/runtime/types, and you should ensure you are referencing the modern package to avoid deprecated code [3]. - Binary Format: When using JSON, note that thebinaryformat does not natively support raw binary data in JSON; it is intended for use with multipart or specific binary-capable content types [6]. If you encounter issues with JSON-encoded binary data, it is often because Go's JSON marshaling expects base64 encoding [6].Citations:
Do not classify
openapi_types.Fileas a scalar.classifyElemsends everyopenapi_typesselector to the scalar-copy path. That path copiesFileby value.Fileexposes its underlying byte slice and retains multipart file state, so a deep copy can share mutable state with the original. This affects directFilefields and[]Filefields.Could we add a dedicated
Filecopy path and regression coverage for both cases?🤖 Prompt for AI Agents
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 looks like a legitimate issue. Not sure what the right solution is, given that
File's fields are unexported. I think it's unlikely that anyone usesformat: binaryin an XRD, but we should probably still handle it in some way. Maybe it makes sense to handle it specially in the go generator, e.g. by settingx-go-typeto[]byte, which I believe would match how the k8s apiserver handles these fields.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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 31444
🏁 Script executed:
Length of output: 27857
@adamwg, I agree that mappingtype: string,format: binaryto[]bytein the Go generator is the safer direction.This avoids
openapi_types.Fileand its inaccessible internal state. It also better matches Kubernetes API conventions for binary data.There is one additional case to handle. A direct binary field will generate as
*[]byte, and the current deepcopy generator can copy its bytes. An array of binary fields will generate as*[][]byte. The current slice-copy path copies only the outer slice, so the copied model would still share the inner byte slices.I recommend that the change:
x-go-type: []byteto everystringschema withformat: binary.Email,Date, andUUIDin the scalar-copy path.Filefrom that scalar-copy path.format: binaryand an array whose items useformat: binary.This keeps the generated models independent after
DeepCopy, including the array case.Would you prefer to include this broader binary-format support in this PR, or track it as a follow-up to the email-format fix?
You are interacting with an AI system.