{"_id":"@apitomy/data-models","_rev":"3-a39ead8bf1f9ce6015a483c60af6765f","name":"@apitomy/data-models","dist-tags":{"latest":"3.1.3"},"versions":{"3.1.0":{"name":"@apitomy/data-models","version":"3.1.0","license":"Apache-2.0","_id":"@apitomy/data-models@3.1.0","maintainers":[{"name":"apitomy.ci","email":"apitomy.ci@gmail.com"}],"homepage":"https://github.com/Apitomy/apitomy-data-models#readme","bugs":{"url":"https://github.com/Apitomy/apitomy-data-models/issues"},"dist":{"shasum":"bafa82bd65b5edbd4913d4101b9f7b7479595bc8","tarball":"https://registry.npmjs.org/@apitomy/data-models/-/data-models-3.1.0.tgz","fileCount":6,"integrity":"sha512-ij8tKqQx6Gyj6R1e3sNLbXNBZhF52/Hb7mqndF4brTL8TTUcRezVp0G9rDUGftJbfG+nlw5ECRc4J442tOj66g==","signatures":[{"sig":"MEYCIQDuDccksDSUAuZysq7xR5dUa306qZHBrLDXD/ea2AdvTAIhAK0nY7N7JqjmbhNeKKygLjQ8BwUmAh3xe+xvH3ZuneKE","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19352421},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"a773db87fe6f7fe89c1b6841def3f739a2abeb37","scripts":{"test":"jest","package":"tsup index.ts --format esm,cjs --dts --clean --target es2020"},"_npmUser":{"name":"apitomy.ci","email":"apitomy.ci@gmail.com"},"repository":{"url":"git+https://github.com/Apitomy/apitomy-data-models.git","type":"git"},"_npmVersion":"10.9.2","description":"A library to read, write, and manipulate OpenAPI and AsyncAPI content.","directories":{},"sideEffects":false,"_nodeVersion":"22.17.0","_hasShrinkwrap":false,"devDependencies":{"diff":"8.0.4","jest":"30.3.0","tsup":"8.5.1","ts-jest":"29.4.9","typescript":"5.9.3","@types/jest":"30.0.0","@types/filesystem":"0.0.36"},"_npmOperationalInternal":{"tmp":"tmp/data-models_3.1.0_1779386282718_0.816356094115354","host":"s3://npm-registry-packages-npm-production"}},"3.1.1":{"name":"@apitomy/data-models","version":"3.1.1","license":"Apache-2.0","_id":"@apitomy/data-models@3.1.1","maintainers":[{"name":"apitomy.ci","email":"apitomy.ci@gmail.com"}],"homepage":"https://github.com/Apitomy/apitomy-data-models#readme","bugs":{"url":"https://github.com/Apitomy/apitomy-data-models/issues"},"dist":{"shasum":"a5061c97bee17b641cdc41b5706d18c45edffbad","tarball":"https://registry.npmjs.org/@apitomy/data-models/-/data-models-3.1.1.tgz","fileCount":6,"integrity":"sha512-7MhxDNi1XicpvfjOi6PK9V4eGqt299bi9pKaCq08/0VLLwlzTkfeUV++A95YR9Y1dbqw9ZFxKJqMZhQQFXi78Q==","signatures":[{"sig":"MEYCIQCZ1K+FkTgi+aGFNgcVmDIp5u2LPCS/j8tMWJn7Y9J6iAIhALcqgw0rawg2MQMxJzrQaG37vnB9H0cwWjdNGXHGmDq0","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apitomy%2fdata-models@3.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":19364638},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"0bb39cc89a40b5706e0f7b185071c37f96b0a5b7","scripts":{"test":"jest","package":"tsup index.ts --format esm,cjs --dts --clean --target es2020"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e8be7e0a-38be-4393-8b49-2c0bd4e10885"}},"repository":{"url":"git+https://github.com/Apitomy/apitomy-data-models.git","type":"git"},"_npmVersion":"11.16.0","description":"A library to read, write, and manipulate OpenAPI and AsyncAPI content.","directories":{},"sideEffects":false,"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"devDependencies":{"diff":"8.0.4","jest":"30.4.2","tsup":"8.5.1","ts-jest":"29.4.11","typescript":"5.9.3","@types/jest":"30.0.0","@types/filesystem":"0.0.36"},"_npmOperationalInternal":{"tmp":"tmp/data-models_3.1.1_1781101357716_0.9331276956993337","host":"s3://npm-registry-packages-npm-production"}},"3.1.3":{"name":"@apitomy/data-models","version":"3.1.3","description":"A library to read, write, and manipulate OpenAPI and AsyncAPI content.","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/Apitomy/apitomy-data-models.git"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"sideEffects":false,"scripts":{"test":"jest","package":"tsup index.ts --format esm,cjs --dts --clean --target es2020"},"devDependencies":{"@types/filesystem":"0.0.36","@types/jest":"30.0.0","diff":"9.0.0","jest":"30.4.2","ts-jest":"29.4.11","tsup":"8.5.1","typescript":"5.9.3"},"gitHead":"9a0eb7b3504fe835d5a55f5575571206c5bfd605","_id":"@apitomy/data-models@3.1.3","bugs":{"url":"https://github.com/Apitomy/apitomy-data-models/issues"},"homepage":"https://github.com/Apitomy/apitomy-data-models#readme","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-vSTGTXx9Gw/clY8b6vys1TeeuGLZMH9U2CtrO7iU5kaG41esdfU3UWrMtSt/fNm3yMQFebxlYY3vsXqUiygv0A==","shasum":"20c207245c1f1d820368ee625db8d47172951bdf","tarball":"https://registry.npmjs.org/@apitomy/data-models/-/data-models-3.1.3.tgz","fileCount":6,"unpackedSize":21813578,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@apitomy%2fdata-models@3.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDK20diaKxnnSEh89h8WqtkZ5yQhSJuxAHltChLUlXbDAiAEArl2e4rhBLbZgeY1EcoQkprS3Mz8iyx2kqpSleD+0Q=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e8be7e0a-38be-4393-8b49-2c0bd4e10885"}},"directories":{},"maintainers":[{"name":"apitomy.ci","email":"apitomy.ci@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/data-models_3.1.3_1783962152328_0.7511324701841484"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-21T17:58:02.334Z","modified":"2026-07-13T17:02:32.784Z","3.1.0":"2026-05-21T17:58:02.969Z","3.1.1":"2026-06-10T14:22:37.912Z","3.1.3":"2026-07-13T17:02:32.507Z"},"bugs":{"url":"https://github.com/Apitomy/apitomy-data-models/issues"},"license":"Apache-2.0","homepage":"https://github.com/Apitomy/apitomy-data-models#readme","repository":{"type":"git","url":"git+https://github.com/Apitomy/apitomy-data-models.git"},"description":"A library to read, write, and manipulate OpenAPI and AsyncAPI content.","maintainers":[{"name":"apitomy.ci","email":"apitomy.ci@gmail.com"}],"readme":"# Apitomy Datamodels\n\nA Typescript library for reading, manipulating, and writing OpenAPI and AsyncAPI documents.\n\nInstall with `npm install @apitomy/data-models`.\n\n## Overview\n\nYou can use this library to read an OpenAPI or AsyncAPI document, resulting in an instance\nof a data model.  The data model can then be read or manipulated.  It can also be validated.\n\nThe data model can be accessed directly, but there is also a robust visitor\npattern available for more advanced analysis or transformation of the model.\n\nThe next section (Quickstart) explains, in a nutshell, how to use the library\nfor standard/basic tasks.  The API section below contains more information,\nnecessary to fully leverage the capabilities of the library.\n\n## See It In Action!\n\nIf you want to quickly see what this library can do, you can check out \n[this simple demo](https://apitomy-data-models-demo.stackblitz.io), or go all out and\n[give Apitomy a try](https://www.apicur.io/) (this library is used by the \nApitomy editor when editing an OpenAPI or AsyncAPI definition).\n\n## Quickstart\n\nThe easiest way to get started is to use the library utility class:\n\n_Typescript:_\n\n```Typescript\n// Get the OpenAPI document from somewhere\nconst openApiData: string = ...;\n\n// Use the library util to create a data model instance from the given\n// data.  This will convert from the source string into an instance of \n// the OpenAPI data model.\nconst openApiDoc: Document = Library.readDocumentFromJSONString(openApiData);\n\n// Here you can analyze or manipulate the model.\nopenApiDoc.getInfo().setVersion(\"1.7\");\nopenApiDoc.getInfo().setDescription(\"Made some changes to the OpenAPI document!\");\n\n// Validate that your changes are OK.\nconst problems = Library.validate(openApiDoc, null);\n\n// And now write the node back out as a JSON string\nlet modifiedOpenApiData: string = Library.writeDocumentToJSONString(openApiDoc);\n```\n\n_Browser (UMD):_\n\n```JavaScript\nvar openApiData = ...; // Get your OpenAPI data somehow (can be string or JS object)\n\nvar openApiDoc = ApitomyDM.Library.readDocumentFromJSONString(openApiData);\n\nopenApiDoc.getInfo().setVersion(\"1.1\");\nopenApiDoc.getInfo().setDescription(\"Made some changes to the OpenAPI document!\");\n\nvar problems = ApitomyDM.Library.validate(openApiDoc, null);\n\nvar modifiedOpenApiData = ApitomyDM.Library.writeDocumentToJSONString(openApiDoc);\n```\n\n## API\n\n### Library Util Class\n\nThe library comes with a util class that makes certain common tasks easier.\nThese tasks include:\n\n* Creating a document (data model)\n* Reading a document from a string or JS object\n* Writing a document to a string or JS object\n* Validating a model\n* Creating a node path\n* Visiting a model\n\n#### Create Document\n\n`Library.createDocument(ModelType): Document`\n\nUse this method to create an empty OpenAPI or AsyncAPI document (data model).  You\nmust pass one of the values of the ModelType enum to indicate what sort of\ndocument you want (OpenAPI 2, OpenAPI 3, AsyncAPI 2, etc).\n\n#### Read Document\n\n`Library.readDocument(any): Document`\n`Library.readDocumentFromJSONString(string): Document`\n\nThese two methods allow you to parse a document either from a JS object or from a \nstring and turn it into a Document.  The correct type of document will automatically\nbe figured out based on the content passed (by interrogating the `openapi` or `asyncapi`\nproperties).\n\n#### Write Node\n\n`Library.writeNode(Node): any`\n`Library.writeDocument(Document): any`\n`Library.writeDocumentToJSONString(Document): string`\n\nUse these method to convert from a data model instance back to a JS object or\nstring.  You can pass any node from the data model tree into the `writeNode` method\nand the appropriate JS object will be returned.  If you pass in the root document node, then the\nfull OpenAPI/AsyncAPI JS object will be returned.  If, for example, you pass in only the\n`document.info` child node, then a JS object representing only that portion of the\ndata model will be returned.  The `writeDocument` and `writeDocumentToJSONString` methods must be\nsent a full Document, and will return a stringified object.\n\n### Resolve External References\n\n`Library.addReferenceResolver(resolver: IReferenceResolver): void`\n\nThe OpenAPI specification allows references across documents (in various places)\nusing the `$ref` property.  The library itself cannot resolve external references,\nbut rather supports a customizable reference resolution layer.  Use this layer by\nproviding a custom implementation of the `IReferenceResolver` interface and \ninstalling it via the `Library::addReferenceResolver(resolver: IReferenceResolver)`\nmethod.  Multiple reference resolvers can be installed - the first resolver that\ncan successfully resolve a reference will win.  The library has one default resolver\nthat is capable of resolving internal references - for example `#!/components/schemas/Widget`.\n\n#### Validate (deprecated)\n\n`Library::validate(Node, IValidationSeverityRegistry): ValidationProblem[]`\n\nUse this method to validate a document (or subsection of the document).  The\nlibrary includes all validation rules defined by the OpenAPI and AsyncAPI specifications.\nYou can use this method to apply the appropriate rules to any section of the\ndata model.  The return result is an array of validation problems, or an empty\narray if the document is fully valid.\n\n#### Create a Node Path\n\n`Library::createNodePath(Node): NodePath`\n\nFor more information about node paths, see the \"Node Paths\" section below.\n\n\n### The Data Model\n\nThis library has data model classes representing each of the objects defined\nby the OpenAPI and AsyncAPI specifications.  Overall, an instance of a data model is simply\na tree of nodes corresponding to the appropriate specification.  Each node in the\nmodel is unique depending on its specification definition, in addition to \nsharing a common set of functionality:\n\n* _Parent_: Every node has a reference to its parent node.\n* _Root_: Every node has a reference to its root node.\n* _Node Attributes_:  Every node has a set of transient attributes which\n  are not serialized when converting back to a JS object.\n* _Model ID_: Each node has a unique ID generating when the node is created.\n* _Model Type_: Exists only on the root node - identifies the model type.\n\n\n### Node Paths\nAs mentioned, the OpenAPI library's data model is essentially a tree of nodes\nof specific types, as defined by the specification.  An additional feature\nof the library is the ability to identify any node in the model by its \"node\npath\".  A node path is a bit like a simple XPath for an XML document.  You\ncan use a node path to quickly resolve a node.  Node paths are even (sort of)\nhuman readable!\n\nFor example, you could quickly get a specific node in the standard OpenAPI\nPet Store example document with the following code:\n\n```Typescript\nlet document: Document = ...;\nlet path: NodePath = new NodePath(\"/paths[/pet/{petId}]/get/responses[200]\");\nlet resolvedNode: Node = path.resolve(document);\n```\n\nAdditionally, you can easily create a node path from a given node in the \ndata model by using the `createNodePath(Node)` method in the \n`Library` class:\n\n```Typescript\nlet document: Document = ...;\nlet node: Node = document.getPaths().getItem(\"/pet/{petId}\").getGet().getResponses().getItem(\"200\");\nlet path: NodePath = Library.createNodePath(node);\n```\n\n\n### Visiting the Data Model\n\nIn addition to basic reading and writing of a data model, this library also\nincludes an implementation of the visitor pattern (useful for more advanced\nanalysis or transformation of the data model).\n\nTo use this feature, you must create a Typescript class that implements the \n`Visitor` interface.  You can then either call `accept` on any node in \nthe model (which will visit just that one node) or else traverse the entire \nmodel (either up or down).  Some examples are below.\n\n#### Visit a Single Node\n\n```Typescript\nlet document: Document = getOrCreateDocument();\nlet visitor: Visitor = new MyCustomVisitor();\n// Visit ONLY the \"Info\" node.\nLibrary.visitNode(document.getInfo(), visitor);\n```\n\n#### Visit the Entire Document\n\n```Typescript\nlet document: Document = getOrCreateDocument();\nlet visitor: Visitor = new MyCustomVisitor();\nLibrary.visitTree(document, visitor, TraverserDirection.down);\n```\n\n#### Visit a Node And Its Parents\n\n```Typescript\nlet document: Document = getOrCreateDocument();\nlet visitor: IVisitor = new MyCustomVisitor();\n// Visit the Info node and then the Document (root) node\nLibrary.visitTree(document.getInfo(), visitor, OasTraverserDirection.up);\n```\n","readmeFilename":"README.md"}