Skip to content

feat(parser): add ParseObject to generate OpenAPI schemas #87

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 1 commit into from
May 31, 2025
Merged

Conversation

SVilgelm
Copy link
Member

@SVilgelm SVilgelm commented Dec 18, 2024

Introduce ParseObject function to parse Go types into OpenAPI schema
representations, supporting structs, pointers, maps, slices, and primitives.
Handle tags for customizing schema fields, references, and metadata. This
enables automatic schema generation from Go types, improving integration
with OpenAPI components and reducing manual schema definitions.

@SVilgelm SVilgelm force-pushed the parser branch 7 times, most recently from 812350e to 6b3be3c Compare December 23, 2024 18:18
@SVilgelm SVilgelm changed the title WIP: parse objects parse objects Dec 23, 2024
@SVilgelm SVilgelm force-pushed the parser branch 3 times, most recently from 54b5933 to bd1e279 Compare December 28, 2024 03:55
@SVilgelm SVilgelm force-pushed the parser branch 3 times, most recently from d5fbcf9 to 122744e Compare May 11, 2025 16:15
@SVilgelm SVilgelm marked this pull request as draft May 18, 2025 17:45
@SVilgelm SVilgelm force-pushed the parser branch 2 times, most recently from 5ae3297 to aa10b45 Compare May 31, 2025 22:37
@SVilgelm SVilgelm changed the title parse objects feat(parser): add ParseObject to generate OpenAPI schemas May 31, 2025
@SVilgelm SVilgelm marked this pull request as ready for review May 31, 2025 23:03
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 23:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new ParseObject function to automatically convert Go types into OpenAPI schemas, updates documentation, and applies minor formatting in component validation.

  • Introduce ParseObject, parseObject, and applyTag in parser.go to handle structs, pointers, maps, slices, primitives, and tags.
  • Document the new feature in README.md.
  • Insert a blank line in components.go for consistent formatting.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
parser.go Implement parsing logic to generate OpenAPI SchemaBuilder from Go types and tags.
components.go Add blank line in validateSpec for readability.
README.md Document ParseObject feature and supported tags.
Comments suppressed due to low confidence (3)

README.md:31

  • [nitpick] The README refers to SchemaBuilder, but the code type appears as SchemaBulder; ensure naming is consistent between documentation and code.
* Added `ParseObject` function to create `SchemaBuilder` by parsing an object.

parser.go:34

  • Consider adding unit tests for ParseObject, covering various Go types (structs with tags, pointers, maps, slices, primitives) to verify correct schema generation and prevent regressions.
func ParseObject(obj any, components *Extendable[Components]) (*SchemaBulder, error) {

parser.go:209

  • The arguments to strings.HasPrefix are reversed; it should be strings.HasPrefix(parts[0], "ref:") to correctly detect the ref tag.
if strings.HasPrefix("ref:", parts[0]) {

@SVilgelm SVilgelm force-pushed the parser branch 3 times, most recently from 9813279 to fdeadc3 Compare May 31, 2025 23:24
@SVilgelm SVilgelm requested a review from Copilot May 31, 2025 23:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Introduce a new ParseObject function that converts Go types into OpenAPI schemas with full support for structs, pointers, maps, slices, primitives, and customizable tags.

  • Add ParseObject and related helpers in parser.go to traverse Go types and build schema definitions.
  • Reserve and reference struct schemas in components.Spec.Schemas to avoid circular references.
  • Update README.md to document the new ParseObject function.
  • Minor formatting adjustment in components.go.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
parser.go Implements ParseObject, parseObject, and tag handling to generate SchemaBuilder instances.
components.go Added a blank line in validateSpec for formatting consistency.
README.md Documented the usage of the new ParseObject function.
Comments suppressed due to low confidence (1)

parser.go:47

  • [nitpick] Consider adding unit tests for ParseObject to verify struct, pointer, map, slice parsing and various tag combinations.
func ParseObject(obj any, components *Extendable[Components], opts ...ParseOption) (*SchemaBulder, error) {

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new ParseObject function to automatically generate OpenAPI schema representations from Go types while also refactoring the SchemaBuilder naming throughout the codebase.

  • Renamed SchemaBulder → SchemaBuilder in schema.go and related files.
  • Added ParseObject functionality in parser.go to support automatic schema generation.
  • Updated documentation and minor formatting changes in components.go, bool_or_schema.go, and README.md.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
schema.go Renamed SchemaBulder to SchemaBuilder for consistency.
parser.go Added ParseObject with logic to parse various Go types.
components.go Minor formatting update.
bool_or_schema.go Updated reference from SchemaBulder to SchemaBuilder.
README.md Documentation updated to reflect the new ParseObject.
Comments suppressed due to low confidence (1)

parser.go:248

  • [nitpick] The early return on detecting a '-' tag in applyTag could be clarified with an inline comment detailing that the '-' indicates the field should be skipped. This would improve code readability for future maintainers.
if name == "-" { return parts[0] }

Introduce ParseObject function to parse Go types into OpenAPI schema
representations, supporting structs, pointers, maps, slices, and primitives.
Handle tags for customizing schema fields, references, and metadata. This
enables automatic schema generation from Go types, improving integration
with OpenAPI components and reducing manual schema definitions.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a ParseObject function for converting Go types into OpenAPI schemas and renames/fixes the schema builder type.

  • Rename SchemaBulder to SchemaBuilder and update all its methods.
  • Add parser.go with ParseObject logic for structs, pointers, maps, slices, and primitives.
  • Update bool_or_schema.go and README.md to reflect the new builder and parsing feature.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

File Description
schema.go Renamed SchemaBulder to SchemaBuilder and updated all builder methods to match.
parser.go Added ParseObject (and helper parseObject) to generate schemas from Go types.
bool_or_schema.go Updated NewBoolOrSchema case to accept *SchemaBuilder.
README.md Documented the new ParseObject function in feature list.
Comments suppressed due to low confidence (1)

parser.go:48

  • Add unit tests for ParseObject covering structs, slices, maps, pointers, and primitives to ensure schema generation behaves as expected.
func ParseObject(obj any, components *Extendable[Components], opts ...ParseOption) (*SchemaBuilder, error) {

@SVilgelm SVilgelm merged commit 697b331 into main May 31, 2025
10 checks passed
@SVilgelm SVilgelm deleted the parser branch May 31, 2025 23:41
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.

1 participant