{"id":15091533,"url":"https://github.com/dolegi/open-api-to-schema","last_synced_at":"2025-10-09T16:31:18.830Z","repository":{"id":95661669,"uuid":"169326919","full_name":"dolegi/open-api-to-schema","owner":"dolegi","description":"Converts open-api / swagger files to json schema objects ready to use with json schema validation libraries.","archived":false,"fork":false,"pushed_at":"2019-02-07T22:35:20.000Z","size":123,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-04T17:44:42.354Z","etag":null,"topics":["json-schema","open-api","swagger"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dolegi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-02-05T23:05:50.000Z","updated_at":"2025-03-22T10:57:39.000Z","dependencies_parsed_at":"2023-03-24T05:18:15.413Z","dependency_job_id":null,"html_url":"https://github.com/dolegi/open-api-to-schema","commit_stats":null,"previous_names":["dominicginger/open-api-to-schema"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dolegi/open-api-to-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolegi%2Fopen-api-to-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolegi%2Fopen-api-to-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolegi%2Fopen-api-to-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolegi%2Fopen-api-to-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dolegi","download_url":"https://codeload.github.com/dolegi/open-api-to-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dolegi%2Fopen-api-to-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001122,"owners_count":26083022,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["json-schema","open-api","swagger"],"created_at":"2024-09-25T10:41:40.984Z","updated_at":"2025-10-09T16:31:18.381Z","avatar_url":"https://github.com/dolegi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open api schema converter\n\nConverts open-api / swagger files to json schema objects ready to use with json schema validation libraries.\n\n## Usage\n`npm install --save open-api-to-schema`\n\n```javascript\nimport openApiToSchema from 'open-api-to-schema'\nimport Ajv from 'ajv'\n\nconst config = {\n  required: 'all',\n  optionalFields: {\n    Pet: [ 'id' ]\n  }\n}\n\nconst jsonSchemas = openApiToSchema('./test/fixtures/petstore-expanded.yaml', config)\n\nconst ajv = new Ajv()\nconst validator = ajv.compile(jsonSchema.paths['/pet'].get[200])\n\nconst valid = validator(response.data)\n\nif (!valid) {\n  console.error(validator.errors)\n}\n...\n```\n\n## Returns\nReturns a valid [JSON Schema draft 7](https://tools.ietf.org/html/draft-handrews-json-schema-01) object ready to be used with json validation libraries such as [ajv](https://www.npmjs.com/package/ajv).\n\nDefinitions and paths are root objects.\n\nSee [Example Response](##Example Response)\n\n## Config\n\n### `required`\nrequired is on of :-\n- `respect` // required fields from schema are used\n- `all` // all fields are required expect `optionalFields`\n- `none` // no fields are required expect `requiredFields`\n\n### `optionalFields`\nOnly used when `required` is set to `all`.\nDefines the fields that should not be set to required.\nHas definition name as key with array of optional fields\n\n```\n{\n  [definitionName]: [ 'unrequired' ]\n}\n```\n\n### `requiredFields`\nOnly used when `required` is set to `none`.\nDefines the fields that should be set to required.\nHas definition name as key with array of required fields\n\n```\n{\n  [definitionName]: [ 'required' ]\n}\n```\n## Features\n\n- [X] Allof\n- [ ] Oneof\n- [ ] Anyof\n- [X] Expose definitions\n- [X] Expose paths\n- [X] Override requiring\n\n## Example Response\n```json\n{\n  \"/pets\": {\n    \"get\": {\n      \"200\": {\n        \"type\": \"array\",\n        \"items\": {\n          \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n          \"$name\": \"Pet\",\n          \"properties\": {\n            \"name\": {\n              \"type\": \"string\"\n            },\n            \"tag\": {\n              \"type\": \"string\"\n            },\n            \"id\": {\n              \"type\": \"integer\",\n              \"format\": \"int64\"\n            }\n          },\n          \"required\": [\n            \"name\",\n            \"tag\"\n          ],\n          \"additionalProperties\": false\n        }\n      },\n      \"default\": {\n        \"required\": [\n          \"code\",\n          \"message\"\n        ],\n        \"properties\": {\n          \"code\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          },\n          \"message\": {\n            \"type\": \"string\"\n          }\n        },\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Error\"\n      }\n    },\n    \"post\": {\n      \"200\": {\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Pet\",\n        \"properties\": {\n          \"name\": {\n            \"type\": \"string\"\n          },\n          \"tag\": {\n            \"type\": \"string\"\n          },\n          \"id\": {\n            \"type\": \"integer\",\n            \"format\": \"int64\"\n          }\n        },\n        \"required\": [\n          \"name\",\n          \"tag\"\n        ],\n        \"additionalProperties\": false\n      },\n      \"default\": {\n        \"required\": [\n          \"code\",\n          \"message\"\n        ],\n        \"properties\": {\n          \"code\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          },\n          \"message\": {\n            \"type\": \"string\"\n          }\n        },\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Error\"\n      }\n    }\n  },\n  \"/pets/{id}\": {\n    \"get\": {\n      \"200\": {\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Pet\",\n        \"properties\": {\n          \"name\": {\n            \"type\": \"string\"\n          },\n          \"tag\": {\n            \"type\": \"string\"\n          },\n          \"id\": {\n            \"type\": \"integer\",\n            \"format\": \"int64\"\n          }\n        },\n        \"required\": [\n          \"name\",\n          \"tag\"\n        ],\n        \"additionalProperties\": false\n      },\n      \"default\": {\n        \"required\": [\n          \"code\",\n          \"message\"\n        ],\n        \"properties\": {\n          \"code\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          },\n          \"message\": {\n            \"type\": \"string\"\n          }\n        },\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Error\"\n      }\n    },\n    \"delete\": {\n      \"204\": {},\n      \"default\": {\n        \"required\": [\n          \"code\",\n          \"message\"\n        ],\n        \"properties\": {\n          \"code\": {\n            \"type\": \"integer\",\n            \"format\": \"int32\"\n          },\n          \"message\": {\n            \"type\": \"string\"\n          }\n        },\n        \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n        \"$name\": \"Error\"\n      }\n    }\n  }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolegi%2Fopen-api-to-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdolegi%2Fopen-api-to-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdolegi%2Fopen-api-to-schema/lists"}