{"id":42482371,"url":"https://github.com/mikekonan/go-oas3","last_synced_at":"2026-01-28T11:14:43.455Z","repository":{"id":39484494,"uuid":"315667251","full_name":"mikekonan/go-oas3","owner":"mikekonan","description":"Open API v3 server code generator","archived":false,"fork":false,"pushed_at":"2025-12-03T15:37:59.000Z","size":9747,"stargazers_count":21,"open_issues_count":8,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-06T20:25:10.590Z","etag":null,"topics":["codegenerator","oas3","openapi","openapi-generator","openapi3","rest","rest-api","swagger","swagger-codegen"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikekonan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-24T15:03:56.000Z","updated_at":"2025-12-03T15:37:39.000Z","dependencies_parsed_at":"2022-08-01T08:19:59.479Z","dependency_job_id":"d16d92ce-be6e-4cef-b5ad-d0a2bfadcf15","html_url":"https://github.com/mikekonan/go-oas3","commit_stats":null,"previous_names":[],"tags_count":77,"template":false,"template_full_name":null,"purl":"pkg:github/mikekonan/go-oas3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikekonan%2Fgo-oas3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikekonan%2Fgo-oas3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikekonan%2Fgo-oas3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikekonan%2Fgo-oas3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikekonan","download_url":"https://codeload.github.com/mikekonan/go-oas3/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikekonan%2Fgo-oas3/sbom","scorecard":{"id":645620,"data":{"date":"2025-08-11","repo":{"name":"github.com/mikekonan/go-oas3","commit":"b6c40095a4f9b35991bc6c649be8e7956e92d0fa"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":3,"reason":"4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 2/17 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2025-3533 / GHSA-wq9g-9vfc-cfq9","Warn: Project is vulnerable to: GO-2025-3770 / GHSA-vrw8-fxc6-2r93"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-21T12:04:42.172Z","repository_id":39484494,"created_at":"2025-08-21T12:04:42.172Z","updated_at":"2025-08-21T12:04:42.172Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28844821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T10:53:21.605Z","status":"ssl_error","status_checked_at":"2026-01-28T10:53:20.789Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codegenerator","oas3","openapi","openapi-generator","openapi3","rest","rest-api","swagger","swagger-codegen"],"created_at":"2026-01-28T11:14:42.866Z","updated_at":"2026-01-28T11:14:43.449Z","avatar_url":"https://github.com/mikekonan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go OpenAPI v3 Server Code Generator\n\nA powerful, modern code generator that creates clean server boilerplate from OpenAPI v3 specifications. Built with Go 1.22+ and the latest dependencies, featuring enhanced error handling and extensive customization options.\n\n## Table of Contents\n\n- [Quick Start](#quick-start)\n- [Key Ideas](#key-ideas)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Complete Workflow Example](#complete-workflow-example)\n- [OpenAPI Features](#openapi-features)\n- [Extensions Reference](#extensions-reference)\n- [Limitations](#limitations)\n- [Questions or Feature Requests](#questions-or-feature-requests)\n- [Contributing](#contributing)\n\n## Quick Start\n\n### Prerequisites\n- **Go 1.22+** (updated for latest language features)\n- Valid OpenAPI 3.0+ specification file\n- Basic understanding of Go modules\n\n### Installation\n\n```bash\ngo install github.com/mikekonan/go-oas3@latest\n```\n\n### Basic Usage\n\n```bash\n# Generate from local file\ngo-oas3 -swagger-addr swagger.yaml -package myapi -path ./generated\n\n# Generate from remote URL\ngo-oas3 -swagger-addr https://example.com/api/swagger.yaml -package myapi -path ./generated\n```\n\n## Key Ideas\n\n- **Request Parsing**: Stubs handle all request parsing logic automatically\n- **Type Safety**: Response builders ensure you can only respond according to your specification  \n- **Validation**: Built-in validation for all request parameters and bodies\n- **Security**: Automatic security middleware generation from OpenAPI security schemes\n\n**Note:** Path stub generation relies on the **first tag** from your paths. While tags are not required, they are **strongly recommended** for better organization:\n- **With tags**: Creates separate service interfaces per tag (e.g., `UserService`, `OrderService`)\n- **Without tags**: All operations are grouped under a single `DefaultService` interface\n\nExample with tags:\n```yaml\npaths:\n  /users:\n    get:\n      tags: [users]  # Creates UserService interface\n  /orders:\n    post:\n      tags: [orders]  # Creates OrderService interface\n```\n## Usage\n\n### Command Line Arguments\n\n| Flag | Type | Description | Default |\n|------|------|-------------|---------|\n| `-swagger-addr` | string | Path or URL to OpenAPI specification | `swagger.yaml` |\n| `-package` | string | **Required.** Go package name for generated code | - |\n| `-path` | string | **Required.** Output directory for generated files | - |\n| `-componentsPackage` | string | Package name for components (if different from main) | Same as `-package` |\n| `-componentsPath` | string | Path for components (if different from main) | Same as `-path` |\n| `-authorization` | string | Headers for remote swagger files (`key1:value1,key2:value2`) | - |\n| `-prioritize-x-go-type` | bool | Prioritize `x-go-type` over schema properties | `false` |\n| `-pass-raw-request` | bool | Pass raw HTTP request to handler functions | `false` |\n\n### Examples\n\n```bash\n# Basic local generation\ngo-oas3 -swagger-addr swagger.yaml -package api -path ./generated\n\n# Remote file with custom components\ngo-oas3 \\\n  -swagger-addr https://petstore3.swagger.io/api/v3/openapi.json \\\n  -package petstore \\\n  -path ./api \\\n  -componentsPackage models \\\n  -componentsPath ./api/models\n\n# With authorization headers\ngo-oas3 \\\n  -swagger-addr https://api.example.com/swagger.yaml \\\n  -package myapi \\\n  -path ./generated \\\n  -authorization \"X-API-Key:secret,Authorization:Bearer token\"\n```\n\n## Complete Workflow Example\n\nHere's a complete example from an OpenAPI spec to a running server:\n\n### 1. Create OpenAPI Specification (`api.yaml`)\n```yaml\nopenapi: 3.0.0\ninfo:\n  title: User API\n  version: 1.0.0\npaths:\n  /users/{id}:\n    get:\n      tags: [users]\n      parameters:\n        - name: id\n          in: path\n          required: true\n          schema:\n            type: string\n            x-go-type: github.com/google/uuid.UUID\n      responses:\n        '200':\n          description: User found\n          content:\n            application/json:\n              schema:\n                $ref: '#/components/schemas/User'\n        '404':\n          description: User not found\ncomponents:\n  schemas:\n    User:\n      type: object\n      required: [id, email]\n      properties:\n        id:\n          type: string\n          format: uuid\n        email:\n          type: string\n          format: email\n        name:\n          type: string\n          x-go-omitempty: true\n```\n\n### 2. Generate Code\n```bash\ngo-oas3 -swagger-addr api.yaml -package userapi -path ./generated\n```\n\n### 3. Implement Handlers\n```go\npackage main\n\nimport (\n    \"context\"\n    \"net/http\"\n    \"github.com/go-chi/chi/v5\"\n    userapi \"./generated\"\n)\n\ntype UsersService struct{}\n\nfunc (s *UsersService) GetUsersId(ctx context.Context, request userapi.GetUsersIdRequestObject) userapi.GetUsersIdResponseObject {\n    // Your business logic here\n    user := userapi.User{\n        Id:    request.Id,\n        Email: \"user@example.com\",\n        Name:  \"John Doe\",\n    }\n    \n    return userapi.GetUsersId200JSONResponse{\n        Body: user,\n    }\n}\n\nfunc main() {\n    service := \u0026UsersService{}\n    \n    r := chi.NewRouter()\n    userapi.HandlerFromMux(service, r)\n    \n    http.ListenAndServe(\":8080\", r)\n}\n```\n\n### 4. Set Up Your Project\n```bash\n# Initialize Go module\ngo mod init myproject\n\n# Add dependencies and run\ngo mod tidy\ngo run main.go\n```\n\n### 5. Test Your API\n```bash\n# Test the endpoint\ncurl http://localhost:8080/users/550e8400-e29b-41d4-a716-446655440000\n\n# Response:\n# {\n#   \"id\": \"550e8400-e29b-41d4-a716-446655440000\",\n#   \"email\": \"user@example.com\", \n#   \"name\": \"John Doe\"\n# }\n```\n\nThe generated boilerplate includes:\n- **Type-safe handlers** - Request/response objects with proper Go types\n- **Automatic validation** - Built-in validation for all parameters and request bodies\n- **Router integration** - Ready-to-use chi router setup\n- **Error handling** - Structured error responses matching your OpenAPI spec\n\n## OpenAPI Features\n\n### Required Fields\nRequired fields in path, query, headers, and components are supported.\n\n### Security\nSecurity schemes for HTTP and API key (header/cookie) are supported.\n\n### Cookie\nResponse header `Set-Cookie` is supported. Cookies in requests are supported via security schemes only.\n\n### Validation\nType validation supports the following data types:\n- **string**: minLength, maxLength\n- **number**, **integer**: minimum, maximum, exclusiveMinimum, exclusiveMaximum\n\n### Custom Types\nThe generator supports several OpenAPI types for components:\n\n| OpenAPI Type | Go Type |\n|---|---|\n| uuid | [github.com/google/uuid.UUID](https://github.com/google/uuid) |\n| iso4217-currency-code | [github.com/mikekonan/go-types/v2/currency.Code](https://github.com/mikekonan/go-types) |\n| iso3166-alpha-2 | [github.com/mikekonan/go-types/v2/country.Alpha2Code](https://github.com/mikekonan/go-types) |\n| iso3166-alpha-3 | [github.com/mikekonan/go-types/v2/country.Alpha3Code](https://github.com/mikekonan/go-types) |\n\n## Extensions Reference\n\nThe generator supports powerful OpenAPI extensions to customize Go code generation:\n\n### Core Type Extensions\n\n#### `x-go-type` - Custom Go Types\nSpecify custom Go types for any schema:\n\n```yaml\n# Use encoding/json.RawMessage for flexible JSON\nmetadata:\n  type: object\n  x-go-type: encoding/json.RawMessage\n\n# Use third-party types\nuser_id:\n  type: string\n  x-go-type: github.com/google/uuid.UUID\n\n# Use custom domain types\namount:\n  type: string\n  x-go-type: github.com/shopspring/decimal.Decimal\n```\n\n#### `x-go-type-string-parse` - Custom Parsing\nFor string parameters that need custom parsing:\n\n```yaml\n# Custom UUID parsing from string\nuser_id:\n  type: string\n  x-go-type: github.com/google/uuid.UUID\n  x-go-type-string-parse: github.com/google/uuid.Parse\n\n# Custom time parsing\ncreated_at:\n  type: string\n  x-go-type: time.Time\n  x-go-type-string-parse: github.com/spf13/cast.ToTimeE\n```\n\n### Field Modifiers\n\n#### `x-go-pointer` - Force Pointer Types\n```yaml\n# Make field a pointer (useful for optional fields)\noptional_amount:\n  type: integer\n  x-go-pointer: true\n  # Generates: OptionalAmount *int `json:\"optional_amount,omitempty\"`\n```\n\n#### `x-go-omitempty` - JSON Omitempty Tag\n```yaml\n# Add omitempty to JSON tag\ndescription:\n  type: string\n  x-go-omitempty: true\n  # Generates: Description string `json:\"description,omitempty\"`\n```\n\n#### `x-go-string-trimmable` - Auto-trim Strings\n```yaml\n# Automatically trim whitespace before validation\ntitle:\n  type: string\n  minLength: 1\n  x-go-string-trimmable: true\n  # Trims spaces before checking minLength\n```\n\n### Validation Extensions\n\n#### `x-go-regex` - Regex Validation\n```yaml\n# Add regex validation to parameters\nphone:\n  type: string\n  x-go-regex: ^\\+?[1-9]\\d{1,14}$\n  # Generates validation code with regexp.MustCompile\n```\n\n#### `x-go-skip-validation` - Disable Validation\n```yaml\n# Skip validation for performance-critical paths\nlarge_payload:\n  type: object\n  properties:\n    data: \n      type: string\n  x-go-skip-validation: true\n```\n\n### Security Extensions\n\n#### `x-go-skip-security-check` - Skip Security Validation\n```yaml\n# For operations that parse auth but don't enforce it\npaths:\n  /health:\n    get:\n      x-go-skip-security-check: true\n      security:\n        - ApiKeyAuth: []\n      # Parses auth header but doesn't fail on missing/invalid auth\n```\n\n### Advanced Map Types\n\n#### `x-go-map-type` - Custom Map Types\n```yaml\n# Custom map with typed keys/values\nmetadata:\n  type: object\n  additionalProperties:\n    type: string\n  x-go-map-type: map[github.com/google/uuid.UUID]string\n  # Generates: map[uuid.UUID]string instead of map[string]string\n```\n\n### Complete Extension Example\n\n```yaml\ncomponents:\n  schemas:\n    User:\n      type: object\n      required: [id, email]\n      properties:\n        id:\n          type: string\n          x-go-type: github.com/google/uuid.UUID\n        email:\n          type: string\n          format: email\n          x-go-regex: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$\n        profile:\n          type: object\n          x-go-pointer: true\n          x-go-omitempty: true\n          properties:\n            bio:\n              type: string\n              x-go-string-trimmable: true\n        metadata:\n          type: object\n          additionalProperties:\n            type: string\n          x-go-type: map[string]interface{}\n      x-go-skip-validation: false\n\n  parameters:\n    UserID:\n      name: user_id\n      in: path\n      required: true\n      schema:\n        type: string\n        x-go-type: github.com/google/uuid.UUID\n        x-go-type-string-parse: github.com/google/uuid.Parse\n```\n\n## Limitations\n\n### Known Limitations\n\n#### Inline Schema Responses\nThe generator currently has limited support for inline schemas in responses. For example:\n\n```yaml\n# ❌ Not fully supported - may cause compilation issues\nresponses:\n  '200':\n    content:\n      application/json:\n        schema:\n          type: object\n          properties:\n            message: \n              type: string\n\n# ✅ Recommended - use $ref to components\nresponses:\n  '200':\n    content:\n      application/json:\n        schema:\n          $ref: '#/components/schemas/SuccessResponse'\n```\n\n**Workaround**: Define all response schemas in `components/schemas` and reference them using `$ref`.\n\n#### Anonymous Types\n- Anonymous slice elements and map entries have limited support\n- Complex nested anonymous types may not generate correctly\n\n**Workaround**: Define explicit component schemas for complex types.\n\n### Best Practices\n\n1. **Always use $ref for schemas** - Avoid inline type definitions\n2. **Define reusable components** - Create schemas in `components/schemas`\n3. **Use meaningful names** - Component names become Go type names\n4. **Test generated code** - Always compile and test after generation\n\n\n## Questions or Feature Requests\n\nHave a question or need some functionality? Feel free to open an issue or submit a pull request.\n\n## Contributing\n\nGo OpenAPI v3 server code generator uses [github.com/dave/jennifer](https://github.com/dave/jennifer) for code generation. \nUsing [github.com/aloder/tojen](https://github.com/aloder/tojen) is the suggested way to generate Jennifer code.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikekonan%2Fgo-oas3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikekonan%2Fgo-oas3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikekonan%2Fgo-oas3/lists"}