{"id":13713975,"url":"https://github.com/chanced/openapi","last_synced_at":"2025-06-10T09:37:03.567Z","repository":{"id":43675195,"uuid":"433235623","full_name":"chanced/openapi","owner":"chanced","description":"an OpenAPI 3.x library for go","archived":false,"fork":false,"pushed_at":"2022-10-01T17:55:59.000Z","size":5100,"stargazers_count":26,"open_issues_count":5,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T06:32:06.625Z","etag":null,"topics":["go","golang","openapi","openapi-spec","openapi-validation","openapi3","openapi3-1"],"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/chanced.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":"security_requirement.go","support":null}},"created_at":"2021-11-30T00:04:28.000Z","updated_at":"2024-05-30T08:21:32.000Z","dependencies_parsed_at":"2023-01-19T04:01:01.343Z","dependency_job_id":null,"html_url":"https://github.com/chanced/openapi","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fopenapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fopenapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fopenapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fopenapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chanced","download_url":"https://codeload.github.com/chanced/openapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fopenapi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259049233,"owners_count":22797899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","openapi","openapi-spec","openapi-validation","openapi3","openapi3-1"],"created_at":"2024-08-02T23:01:49.110Z","updated_at":"2025-06-10T09:37:03.505Z","avatar_url":"https://github.com/chanced.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# openapi - An OpenAPI 3.x library for go\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/chanced/openapi.svg)](https://pkg.go.dev/github.com/chanced/openapi)\n[![Latest Version](https://img.shields.io/github/v/tag/chanced/openapi.svg?sort=semver\u0026style=flat-square\u0026label=version\u0026color=blue)](https://img.shields.io/github/v/tag/chanced/openapi.svg?sort=semver\u0026style=flat-square\u0026label=version\u0026color=blue)\n![Build Status](https://img.shields.io/github/workflow/status/chanced/openapi/Build?style=flat-square)\n\nopenapi is a library for parsing and validating OpenAPI\n[3.1](https://spec.openapis.org/oas/v3.1.0),\n[3.0](https://spec.openapis.org/oas/v3.0.3). The intent of the library is to\noffer building blocks for code and documentation generation.\n\n:warning: This library is under active development; there may be breaking changes and bugs.\n\n## Features\n\n-   `$ref` resolution\n-   All keys retain their order from the markup using slices of key/values which\n    aids in code generation.\n-   Validation ([see the validation section](#validation))\n-   All non-primitive nodes have an absolute \u0026 relative location\n-   Strings are [text.Text](https://github.com/chanced/caps) which has case\n    conversions and `strings` functions as methods.\n-   Extensions, unknown JSON Schema keywords, examples, and a few other fields\n    are instances of [jsonx.RawMessage](https://github.com/chanced/jsonx) which\n    comes with a few helper methods.\n-   Supports both JSON and YAML\n\n## Usage\n\n```go\npackage main\n\nimport (\n    \"github.com/chanced/openapi\"\n    \"github.com/chanced/uri\"\n    \"github.com/santhosh-tekuri/jsonschema/v5\"\n    \"embed\"\n    \"io\"\n    \"path/filepath\"\n    \"log\"\n)\n\n//go:embed spec\nvar specFiles embed.FS\n\nfunc main() {\n    ctx := context.Background()\n\n    c, err := openapi.SetupCompiler(jsonschema.NewCompiler()) // adding schema files\n    if err != nil {\n        log.Fatal(err)\n    }\n    v, err := openapi.NewValidator(c)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    fn := func(_ context.Context, uri uri.URI, kind openapi.Kind) (openapi.Kind, []byte, error){\n        f, err := specFiles.Open(fp)\n        if err != nil {\n            log.Fatal(err)\n        }\n        // you can return either JSON or YAML\n        d, err := io.ReadAll(f)\n        if err != nil{\n            log.fatal(err)\n        }\n        // use the uri or the data to determine the Kind\n        return openapi.KindDocument, d, nil\n    }\n    // you can Load either JSON or YAML\n    // Load validates the Document as well.\n    doc, err := openapi.Load(ctx, \"spec/openapi.yaml\", v, fn)\n    if err != nil{\n        log.Fatal(err)\n    }\n    _ = doc // *openapi.Document\n}\n```\n\n## Validation\n\nThe standard validator (`StdValidator`) currently validates OpenAPI documents\nwith JSON Schema. Per OpenAPI's documentation, this may not be enough to\nproperly encapsulate all the nuances of a specification. However, JSON Schema is\nable to successfully validate the current OpenAPI 3.1 Specification test suite.\n\nValidation is an area that still needs work. If you do find cases where the\ncurrent validator is not sufficient, please open an issue so that the library\ncan be updated with proper coverage of that case.\n\n## Dependencies\n\n| Dependency                                                                                   | Usage                                                                                         |\n| -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |\n| [github.com/santhosh-tekuri/jsonschema/v5](https://github.com/santhosh-tekuri/jsonschema/v5) | used in the `StdValidator` to validate OpenAPI documents \u0026 components                         |\n| [github.com/chanced/caps/text](https://github.com/chanced/caps)                              | used for all string fields to provide case conversion and functions from `strings` as methods |\n| [github.com/chanced/jsonpointer](https://github.com/chanced/jsonpointer)                     | relative locations of all non-scalar nodes                                                    |\n| [github.com/tidwall/gjson](https://github.com/tidwall/gjson)                                 | JSON parsing                                                                                  |\n| [github.com/chanced/jsonx](https://github.com/chanced/jsonx)                                 | raw JSON type and a toolkit for json type detection \u0026 parsing                                 |\n| [github.com/chanced/maps](https://github.com/chanced/maps)                                   | small utility used to sort `Extensions`                                                       |\n| [github.com/chanced/transcode](https://github.com/chanced/transcode)                         | used to transform YAML into JSON and vice versa                                               |\n| [github.com/chanced/uri](https://github.com/chanced/uri)                                     | used to represent URIs                                                                        |\n| [github.com/Masterminds/semver](https://github.com/Masterminds/semver)                       | openapi field and version detection of OpenAPI documents                                      |\n| [gopkg.in/yaml.v3](https://gopkg.in/yaml.v3)                                                 | needed to satisfy `yaml.Marshaler` and `yaml.Unmarshaler`                                     |\n| [github.com/google/go-cmp](https://github.com/google/go-cmp)                                 | testing purposes                                                                              |\n\n## Contributions\n\nPlease feel free to open up an issue or create a pull request if you find issues\nor if there are features you'd like to see added.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fopenapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanced%2Fopenapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fopenapi/lists"}