{"name":"@swagger-api/apidom-ns-api-design-systems","version":"0.77.0","author":{"name":"Vladimir Gorej"},"license":"Apache-2.0","_id":"@swagger-api/apidom-ns-api-design-systems@0.77.0","maintainers":[{"name":"swagger-api","email":"apiteam@swagger.io"}],"homepage":"https://github.com/swagger-api/apidom#readme","bugs":{"url":"https://github.com/swagger-api/apidom/issues"},"dist":{"shasum":"2ec9e4488320b72a3abc7d660aeed0102d144541","tarball":"http://registry-npm.ywwl.com/@swagger-api/apidom-ns-api-design-systems/download/@swagger-api/apidom-ns-api-design-systems-0.77.0.tgz","fileCount":112,"integrity":"sha512-FaadpkDoClkomlOv4yT7Wc+Q+kb0uN7iBoo7j8+vnI2ID13I3FDaeqUcADsGdIgNT3JxaK/esJVIln+65TTdwA==","signatures":[{"sig":"MEQCHyEe0JJZCH+G/m2yZ3OpTSX4/og8VEFcSdbzcAuZrooCIQCCx10xtgh93tqvcUmFyHBz6QRHxCRja3v5pki0/17ETA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1267332,"size":220994,"noattachment":false,"key":"/@swagger-api/apidom-ns-api-design-systems/-/@swagger-api/apidom-ns-api-design-systems-0.77.0.tgz"},"main":"./cjs/index.cjs","type":"module","types":"./types/dist.d.ts","unpkg":"./dist/apidom-ns-api-design-systems.browser.min.js","exports":{"types":"./types/dist.d.ts","import":"./es/index.mjs","require":"./cjs/index.cjs"},"gitHead":"cd8a9d7d2ea8bb8c335c23cd4632830a79c426c9","scripts":{"lint":"eslint ./","test":"cross-env NODE_ENV=test BABEL_ENV=cjs mocha","build":"npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser","clean":"rimraf ./es ./cjs ./dist ./types","prepack":"copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .","build:es":"cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'","lint:fix":"eslint ./ --fix","postpack":"rimraf NOTICE LICENSES","build:cjs":"cross-env BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'","build:umd:browser":"cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress","test:update-snapshots":"cross-env UPDATE_SNAPSHOT=1 BABEL_ENV=cjs mocha","typescript:check-types":"tsc --noEmit","typescript:declaration":"tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js"},"_npmUser":{"name":"swagger-api","email":"apiteam@swagger.io"},"repository":{"url":"git+https://github.com/swagger-api/apidom.git","type":"git"},"_npmVersion":"lerna/7.3.0/node@v20.8.0+x64 (linux)","description":"API Design Systems 2021-05-07 namespace for ApiDOM.","directories":{},"sideEffects":["./es/refractor/registration.mjs","./cjs/refractor/registration.cjs"],"_nodeVersion":"20.8.0","dependencies":{"ramda":"~0.29.0","stampit":"^4.3.2","@types/ramda":"~0.29.3","ramda-adjunct":"^4.1.1","@babel/runtime-corejs3":"^7.20.7","@swagger-api/apidom-core":"^0.77.0","@swagger-api/apidom-error":"^0.77.0","@swagger-api/apidom-ns-openapi-3-1":"^0.77.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/apidom-ns-api-design-systems_0.77.0_1696345374204_0.005580532290266227","host":"s3://npm-registry-packages"},"readme":"# @swagger-api/apidom-ns-api-design-systems\n\n`@swagger-api/apidom-ns-api-design-systems` contains ApiDOM namespace specific to [API Design System Specification](https://apidesign.systems/specification/).\n\n## Installation\n\nYou can install this package via [npm CLI](https://docs.npmjs.com/cli) by running the following command:\n\n```sh\n $ npm install @swagger-api/apidom-ns-api-design-systems\n```\n\n## API Design Systems 2021-05-07 namespace\n\nAPI Design Systems 2021-05-07 namespace consists of [number of elements](https://github.com/swagger-api/apidom/tree/main/packages/apidom-ns-api-design-systems/src/elements) implemented on top\nof [primitive ones](https://github.com/refractproject/minim/tree/master/lib/primitives).\n\n```js\nimport { createNamespace } from '@swagger-api/apidom-core';\nimport apiDesignSystemsNamespace from '@swagger-api/apidom-ns-api-design-systems';\n\nconst namespace = createNamespace(apiDesignSystemsNamespace);\n\nconst objectElement = new namespace.elements.Object();\nconst mainElement = new namespace.elements.Main();\n```\n\nWhen namespace instance is created in this way, it will extend the base namespace\nwith the namespace provided as an argument.\n\nElements from the namespace can also be used directly by importing them.\n\n```js\nimport { MainElement, InfoElement } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst infoElement = new InfoElement();\nconst mainElement = new MainElement();\n```\n\n## Predicates\n\nThis package exposes [predicates](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-api-design-systems/src/predicates.ts)\nfor all higher order elements that are part of this namespace.\n\n```js\nimport { isMainElement, MainElement } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst mainElement = new MainElement();\n\nisMainElement(mainElement); // => true\n```\n\n## Traversal\n\nTraversing ApiDOM in this namespace is possible by using `visit` function from `apidom` package.\nThis package comes with its own [keyMap](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-api-design-systems/src/traversal/visitor.ts) and  and [nodeTypeGetter](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-api-design-systems/src/traversal/visitor.ts).\nTo learn more about these `visit` configuration options please refer to [@swagger-api/apidom-ast documentation](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ast/README.md#visit).\n\n```js\nimport { visit } from '@swagger-api/apidom-core';\nimport { MainElement, keyMap, getNodeType } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst element = new MainElement();\n\nconst visitor = {\n  MainElement(mainElement) {\n    console.dir(mainElement);\n  },\n};\n\nvisit(element, visitor, { keyMap, nodeTypeGetter: getNodeType });\n```\n\n## Refractors\n\nRefractor is a special layer inside the namespace that can transform either JavaScript structures\nor generic ApiDOM structures into structures built from elements of this namespace.\n\n**Refracting JavaScript structures**:\n\n```js\nimport { InfoElement } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst object = {\n    title: 'my title',\n    description: 'my description',\n};\n\nInfoElement.refract(object); // => InfoElement({ title, description })\n```\n\n**Refracting generic ApiDOM structures**:\n\n```js\nimport { ObjectElement } from '@swagger-api/apidom-core';\nimport { InfoElement } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst objectElement = new ObjectElement({\n    title: 'my title',\n    description: 'my description',\n});\n\nInfoElement.refract(objectElement); // => InfoElement({ title = 'my title', description = 'my description' })\n```\n\n### Refractor plugins\n\nRefractors can accept plugins as a second argument of refract static method.\n\n```js\nimport { ObjectElement } from '@swagger-api/apidom-core';\nimport { InfoElement } from '@swagger-api/apidom-ns-api-design-systems';\n\nconst objectElement = new ObjectElement({\n    title: 'my title',\n    description: 'my description',\n});\n\nconst plugin = ({ predicates, namespace }) => ({\n  name: 'plugin',\n  pre() {\n      console.dir('runs before traversal');\n  },\n  visitor: {\n    InfoElement(infoElement) {\n      infoElement.title = 'new title';\n    },\n  },\n  post() {\n      console.dir('runs after traversal');\n  },\n});\n\nInfoElement.refract(objectElement, { plugins: [plugin] }); // => InfoElement({ title = 'new title', description = 'my description' })\n```\n\nYou can define as many plugins as needed to enhance the resulting namespaced ApiDOM structure.\nIf multiple plugins with the same visitor method are defined, they run in parallel (just like in Babel).\n\n#### OpenAPI 3.1 Standard Identifier plugins\n\nThis namespace comes with two refractor plugins specific to OpenAPI 3.1 specification and decorates significant\nOpenAPI 3.1 elements with [Standard Identifiers](https://apidesign.systems/standards/).\n\n```js\nimport { parse } from '@swagger-api/apidom-parser-adapter-json';\nimport {\n  refractPluginOpenApi3_1StandardIdentifierSelectors,\n  refractPluginOpenApi3_1StandardIdentifierAccessors,\n} from '@swagger-api/apidom-ns-api-design-systems';\nimport { OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';\n\nconst jsonDefinition = `\n{\n  \"openapi\": \"3.1.0\",\n  \"paths\": {\n    \"/path1\": {\n      \"get\": {},\n      \"put\": {\n        \"parameters\": [\n          {\n            \"name\": \"X-Header\",\n            \"in\": \"header\",\n            \"description\": \"parameter3 description\",\n            \"required\": false,\n            \"deprecated\": false,\n            \"allowEmptyValue\": true\n          }\n        ],\n        \"requestBody\": {\n          \"content\": {\n            \"application/json\": {\n              \"schema\": {\n                \"type\": \"object\"\n              }\n            }\n          },\n          \"required\": true\n        },\n        \"responses\": {\n          \"201\": {\n            \"content\": {\n              \"application/json\": {}\n            }\n          }\n        }\n      },\n      \"parameters\": [\n        {\n          \"name\": \"X-Header2\",\n          \"in\": \"header\",\n          \"description\": \"parameter1 description\",\n          \"allowEmptyValue\": true\n        }\n      ]\n    }\n  }\n}\n`;\nconst apiDOM = await parse(jsonDefinition, { sourceMap: true });\nconst openApiElement = OpenApi3_1Element.refract(apiDOM.result, {\n  plugins: [\n    refractPluginOpenApi3_1StandardIdentifierSelectors(),\n    refractPluginOpenApi3_1StandardIdentifierAccessors(),\n  ],\n});\n// => OperationElement now contains [['http', 'transaction']] under `ads-s-standard-identifier` key\n// => OperationElement now contains followign structure under `ads-a-standard-identifier` key\n// [\n//   {\n//     subject: ['http', 'request', 'method'],\n//     value: 'get',\n//   },\n// ]\n//\n// other elements are decorated by different metadata as well\n```\n\n## Validation\n\nThis package supports validation API Design Systems definition against OpenAPI 3.1 definition.\nValidator is in POC phase and there is limited support for `Scenario` objects. Validation\nproduces list of `Annotation` elements.\n\n**API Design Systems definition**:\n\n```yaml\nversion: \"2021-05-07\"\ninfo:\n  title: SmartBear API Guidelines\n  description: |\n    A machine and human readable version of the SmartBear API Style Guide aimed at promoting living API Style Governance across various tools and teams, leading to improved API quality.\n    See the [SmartBear Standards and Guidelines](https://github.com/SmartBear/api-standards-and-guidelines) repo for a traditional view of the static guidelines.\nprinciples:\n  - iri: urn:apidesign.systems:principle:robustness\n    level: must\n  - iri: urn:apidesign.systems:principle:rmm:level2\n    level: must\n  - iri: urn:apidesign.systems:principle:rmm:level3\n    level: should\nstandards:\n  - iri: urn:ietf:rfc:6648\n    level: must\n  - iri: urn:ietf:rfc:7807\n    level: must\n  - iri: urn:ietf:rfc:7231\n    level: should\n  - iri: urn:ietf:rfc:6585\n    level: may\n  - iri: urn:ietf:rfc:5788\n    level: may\n  - iri: urn:ietf:draft:http-semantics\n    level: may\nscenarios:\n  - description: SB-API-010 - Only apply standard HTTP methods\n    when: [http, transaction]\n    then:\n      - subject: [http, request, method]\n        level: may\n        values:\n          - get\n          - post\n          - put\n          - patch\n          - delete\n```\n\n**OpenAPI 3.1 definition**:\n\n```json\n{\n  \"openapi\": \"3.1.0\",\n  \"paths\": {\n    \"/path1\": {\n      \"get\": {},\n      \"put\": {},\n      \"trace\": {},\n      \"options\": {}\n    }\n  }\n}\n```\n\n**Validation**:\n\n```js\nimport { parse as parseJSON } from '@swagger-api/apidom-parser-adapter-json';\nimport { parse as parseYAML } from '@swagger-api/apidom-parser-adapter-yaml-1-2';\nimport { OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';\nimport {\n  refractPluginOpenApi3_1StandardIdentifierSelectors,\n  refractPluginOpenApi3_1StandardIdentifierAccessors,\n  MainElement,\n  validateOpenAPI3_1,\n} from '@swagger-api/apidom-ns-api-design-systems';\n\nconst apiDesignSystemsParseResult = await parseYAML(apiDesignSystemsDefinition);\nconst openAPIParseResult = await parseJSON(openAPIDefinition, { sourceMap: true });\nconst mainElement = MainElement.refract(apiDesignSystemsParseResult.result);\nconst  openapiElement = OpenApi3_1Element.refract(openAPIParseResult.result, {\n  plugins: [\n    refractPluginOpenApi3_1StandardIdentifierSelectors(),\n    refractPluginOpenApi3_1StandardIdentifierAccessors(),\n  ],\n});\nconst annotations = validateOpenAPI3_1(mainElement, openapiElement);\n// [\n//   Annotation('\"trace\" not allowed for subject [\"http\",\"request\",\"method\"] on line 6, column 6', class=error),\n//   Annotation('\"options\" not allowed for subject [\"http\",\"request\",\"method\"] on line 7, column 6', class=error),\n// ]\n```\n\n## Implementation progress\n\nOnly fully implemented specification objects should be checked here.\n\n- [x] [Main](https://apidesign.systems/specification/#main)\n- [x] [Info](https://apidesign.systems/specification/#info-object)\n- [x] [Principle](https://apidesign.systems/specification/#principle)\n- [x] [Standard](https://apidesign.systems/specification/#standard)\n- [x] [Scenario](https://apidesign.systems/specification/#scenario)\n- [x] [Requirement](https://apidesign.systems/specification/#requirement)\n- [x] [Standard Identifier](https://apidesign.systems/specification/#standard-identifier-arraystring)\n- [x] [Requirement Level](https://apidesign.systems/specification/#requirement-level-enum)\n","publish_time":1696345374568,"_cnpm_publish_time":1696345374568,"dist-tags":{"latest":"1.14.0","v1.11-maintenance":"1.11.6"}}