-
Notifications
You must be signed in to change notification settings - Fork 72
feat: add oastools builder for OAS 2.0 and 3.x document generation #125
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
Conversation
This introduces an alternative document generation path using the oastools library, enabling support for OpenAPI 3.x specifications while maintaining full backward compatibility with OpenAPI 2.0. New APIs: - BuildOAS2(Config) - generates OpenAPI 2.0 documents via oastools - BuildOAS3(Config) - generates OpenAPI 3.x documents (3.0.x to 3.2.0) Config additions: - OASVersion: target OpenAPI version for OAS 3.x output - Servers: OAS 3.x server objects - Info: structured API metadata - SchemaNaming/GenericNaming: schema naming strategies - SchemaNameFunc: custom schema name function - SemanticDeduplication: deduplicate identical schemas - PostBuildOAS2Handler/PostBuildOAS3Handler: post-processing hooks Other changes: - Add definition name handlers (LowerSnakeCased, LowerCamelCased, GoLowerCamelCased) for customizing field names without json tags - Support "example" struct tag for property example values - Fix enum placement in array item definitions - Fix handling of time.Time fields - Fix embedded struct definitions not being referenced - Update README with comprehensive documentation - Add Makefile with test, lint, and coverage targets - Add golangci-lint configuration - Fix spec.ContactInfo and spec.License struct literal fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.
Pull request overview
This PR adds new OpenAPI document generation capabilities using the oastools library, introducing BuildOAS2 and BuildOAS3 functions that complement the existing BuildSwagger API. The changes support OpenAPI versions from 2.0 through 3.2.0, with configurable schema naming strategies, generic type handling, and semantic deduplication.
Key changes:
- Introduces new
BuildOAS2andBuildOAS3functions for generating OpenAPI specifications using the oastools library - Adds comprehensive configuration options for schema naming strategies, generic type formatting, and semantic deduplication
- Modernizes development tooling with updated
.golangci.yml(v2 format) and enhancedMakefile
Reviewed changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
oastools_types.go |
Defines type aliases and constants for OAS versions and naming strategies |
oastools_schema.go |
Provides legacy tag support functions (reserved for future dual-tag integration) |
oastools_builder.go |
Core implementation of BuildOAS2 and BuildOAS3 functions |
oastools_builder_test.go |
Comprehensive test coverage for new OAS builder functions |
config.go |
Extends Config struct with oastools-specific configuration options |
go.mod / go.sum |
Updates dependencies including new oastools library |
README.md |
Comprehensive documentation update with examples and migration guide |
.golangci.yml |
Updates to v2 format with refined linter configuration |
Makefile |
Enhanced with additional targets and improved structure |
utils_test.go |
Improves error handling by explicitly ignoring return values |
spec_resource.go |
Fixes spelling error and adds error handling |
spec_resource_test.go |
Simplifies conditional logic |
property_ext_test.go |
Removes unused variables in tests |
definition_builder.go |
Changes return type and improves code quality |
definition_builder_test.go |
Updates property access and adds linter directives |
lookup.go |
Simplifies switch statement with default case |
build_path_test.go |
Fixes spelling and improves test assertions |
examples/security/api.go |
Updates struct initialization for go-openapi/spec compatibility |
.gitignore |
Adds IDE and Claude Code file exclusions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@erraggy thank you for contributing. I will review this addition. |
|
Shouldn't the |
You've found a gap I left behind in my implementation. I'll have a commit to address this shortly. Thank you. |
|
@emicklei I've addressed it in commit 4be62f0.
This maintains full backward compatibility — existing users who don't set I also refactored to use a single any-typed document variable with an inline handler, which keeps the code DRY and eliminates the need for separate resource types. Added tests for both new paths; coverage is back to baseline. |
|
That led me to dig deeper and look for any other gaps or issues, and I found a bunch. LOL. Another commit is incoming once I get all tests completed. 😄 |
|
After a secondary thorough review, I've addressed all findings with 7be5e66: Error Handling:
Feature Parity with Legacy Builder:
Code Quality:
Tests:
Note: |
|
Wow! Thanks for merging this, @emicklei. I don't know how I didn't realize you had already merged this PR, but I kept right on going. LOL... 😂 I have a new release for I can submit a follow-up PR to incorporate the added support if you'd like. |
Summary
BuildOAS2andBuildOAS3functions that generate OpenAPI 2.0 and 3.x documents using the oastools library.golangci.yml(v2 format) and enhancedMakefileNew Features
BuildOAS3(config)BuildOAS2(config)PostBuildOAS2Handler/PostBuildOAS3HandlerTest plan
oastools_builder_test.gocovers OAS 2.0 and 3.x generationv2branch to incorporate upstream changes🤖 Generated with Claude Code
Notes
I worked to provide all that's required for producing ALL OAS versions in my
oastoolslibrary, and then used Claude Code and Opus 4.5 to implement this while keeping full backward compatibility. Please consider this as a replacement for thego-openapiproject of libraries, since they've stated no willingness to support OAS3.x.Resolves