Repository navigation
feat(schema): add GoType and GoPackage fields to Schema - #99
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds custom GoType and GoPackage fields to the Schema struct and extends the SchemaBuilder API while also preventing modifications on referenced schemas and improving component name validation. Key changes include:
- Introducing GoType and GoPackage fields and corresponding builder methods.
- Adding early returns in SchemaBuilder methods when a reference is detected.
- Incorporating regex-based validation of component names in components.go, though some errors in the error message context remain.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| validation.go | Refactored JSON conversion to use ConvertToJSON; modified error handling. |
| types.go | Improved nil handling in getKind. |
| schema.go | Added Go fields and updated SchemaBuilder methods (note potential typographical error). |
| components.go | Updated component validations with regex checks, but location labels are mis-assigned. |
| bool_or_schema.go | Expanded schema conversion to support SchemaBulder. |
Comments suppressed due to low confidence (3)
validation.go:229
- Consider wrapping the error returned from ConvertToJSON with contextual information (e.g., "unmarshaling value failed") to aid debugging.
if err != nil { return err }
schema.go:726
- [nitpick] The type name 'SchemaBulder' appears to be misspelled; renaming it to 'SchemaBuilder' would improve clarity and consistency.
func NewSchemaBuilder() *SchemaBulder {
schema.go:729
- The removal of the default $schema value (e.g., Draft202012) in NewSchemaBuilder may lead to unintended behavior; consider reintroducing it if it is necessary for proper schema validation.
spec: NewRefOrSpec[Schema](&Schema{}),
Add custom GoType and GoPackage fields to the Schema struct to store Go-specific type information. Extend SchemaBuilder with GoType and GoPackage methods to set these fields, enabling better integration with Go code generation. fix(schemabuilder): prevent modifications on referenced schemas Add checks in SchemaBuilder methods to return early if the schema is a reference. This avoids unintended mutations on referenced schemas, ensuring immutability and correctness when building schemas. fix(components): validate component names against pattern Introduce a regex pattern to validate component names in Components. Emit validation errors for names that do not match the allowed pattern, improving schema correctness and adherence to naming conventions. fix(reflect): handle nil values in getKind function Update getKind to handle nil reflect.Type values safely by returning reflect.Invalid. This prevents panics when passing nil values and improves robustness of type inspection utilities.
SVilgelm
force-pushed
the
add-json-conversion-and-schema-builder-guards
branch
from
May 11, 2025 16:08
68e2d24 to
1defd66
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces Go-specific fields and methods to the Schema and Schema builder, along with enhancements to improve schema immutability and component name validation. Key changes include:
- Adding new GoType and GoPackage fields to the Schema struct with corresponding builder methods.
- Introducing early-return checks in Schema builder methods to prevent modifications on referenced schemas.
- Enhancing component name validation using a regex pattern and adding support for *SchemaBulder in BoolOrSchema conversion.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| validation.go | Replaces direct JSON conversion with a ConvertToJSON helper function. |
| types.go | Improves getKind to handle nil reflect.Type values. |
| schema.go | Adds GoType/GoPackage fields along with new SchemaBulder methods. |
| components.go | Integrates regex-based component name validation checks. |
| bool_or_schema.go | Extends type handling to accept *SchemaBulder by building the final schema. |
Comments suppressed due to low confidence (1)
schema.go:727
- The identifier 'SchemaBulder' appears to be a misspelling of 'SchemaBuilder'. Consider renaming it for clarity and consistency.
func NewSchemaBuilder() *SchemaBulder {
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add custom GoType and GoPackage fields to the Schema struct to store
Go-specific type information. Extend SchemaBuilder with GoType and
GoPackage methods to set these fields, enabling better integration
with Go code generation.
fix(schemabuilder): prevent modifications on referenced schemas
Add checks in SchemaBuilder methods to return early if the schema is
a reference. This avoids unintended mutations on referenced schemas,
ensuring immutability and correctness when building schemas.
fix(components): validate component names against pattern
Introduce a regex pattern to validate component names in Components.
Emit validation errors for names that do not match the allowed pattern,
improving schema correctness and adherence to naming conventions.
fix(reflect): handle nil values in getKind function
Update getKind to handle nil reflect.Type values safely by returning
reflect.Invalid. This prevents panics when passing nil values and
improves robustness of type inspection utilities.