Browse Source

refactor: replaces OAComponentType with OAComponentsSegment

e22m4u 6 days ago
parent
commit
707aaf8f3f

+ 3 - 3
README.md

@@ -70,9 +70,9 @@ builder.defineOperation({
 Сборка документа.
 Сборка документа.
 
 
 ```js
 ```js
-const document = builder.build();
+const document = builder.buildJson();
 
 
-console.log(JSON.stringify(document, null, 2));
+console.log(document);
 // {
 // {
 //   "openapi": "3.1.0",
 //   "openapi": "3.1.0",
 //   "info": {
 //   "info": {
@@ -123,7 +123,7 @@ builder.defineSchemaComponent({
 Регистрация компонента параметра.
 Регистрация компонента параметра.
 
 
 ```js
 ```js
-import {OADataType, OAOperationMethod} from '@e22m4u/js-openapi';
+import {OADataType, OAParameterLocation} from '@e22m4u/js-openapi';
 
 
 builder.defineParameterComponent({
 builder.defineParameterComponent({
   name: 'idParam', // <= имя нового компонента
   name: 'idParam', // <= имя нового компонента

+ 1 - 1
build-cjs.js

@@ -6,7 +6,7 @@ await esbuild.build({
   outfile: 'dist/cjs/index.cjs',
   outfile: 'dist/cjs/index.cjs',
   format: 'cjs',
   format: 'cjs',
   platform: 'node',
   platform: 'node',
-  target: ['node12'],
+  target: ['node18'],
   bundle: true,
   bundle: true,
   keepNames: true,
   keepNames: true,
   external: [
   external: [

+ 99 - 110
dist/cjs/index.cjs

@@ -22,7 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
 var index_exports = {};
 var index_exports = {};
 __export(index_exports, {
 __export(index_exports, {
   OAApiKeyLocation: () => OAApiKeyLocation,
   OAApiKeyLocation: () => OAApiKeyLocation,
-  OAComponentType: () => OAComponentType,
+  OAComponentsSegment: () => OAComponentsSegment,
   OADataFormat: () => OADataFormat,
   OADataFormat: () => OADataFormat,
   OADataType: () => OADataType,
   OADataType: () => OADataType,
   OADocumentBuilder: () => OADocumentBuilder,
   OADocumentBuilder: () => OADocumentBuilder,
@@ -32,7 +32,6 @@ __export(index_exports, {
   OAParameterLocation: () => OAParameterLocation,
   OAParameterLocation: () => OAParameterLocation,
   OAParameterStyle: () => OAParameterStyle,
   OAParameterStyle: () => OAParameterStyle,
   OASecuritySchemeType: () => OASecuritySchemeType,
   OASecuritySchemeType: () => OASecuritySchemeType,
-  OA_COMPONENT_TYPE_TO_KEY_MAP: () => OA_COMPONENT_TYPE_TO_KEY_MAP,
   OPENAPI_VERSION: () => OPENAPI_VERSION,
   OPENAPI_VERSION: () => OPENAPI_VERSION,
   oaCallbackRef: () => oaCallbackRef,
   oaCallbackRef: () => oaCallbackRef,
   oaExampleRef: () => oaExampleRef,
   oaExampleRef: () => oaExampleRef,
@@ -49,66 +48,51 @@ module.exports = __toCommonJS(index_exports);
 
 
 // src/constants.js
 // src/constants.js
 var OPENAPI_VERSION = "3.1.0";
 var OPENAPI_VERSION = "3.1.0";
+var OAComponentsSegment = {
+  SCHEMAS: "schemas",
+  RESPONSES: "responses",
+  PARAMETERS: "parameters",
+  EXAMPLES: "examples",
+  REQUEST_BODIES: "requestBodies",
+  HEADERS: "headers",
+  SECURITY_SCHEMES: "securitySchemes",
+  LINKS: "links",
+  CALLBACKS: "callbacks",
+  PATH_ITEMS: "pathItems"
+};
 
 
 // src/utils/oa-ref.js
 // src/utils/oa-ref.js
 var import_js_format = require("@e22m4u/js-format");
 var import_js_format = require("@e22m4u/js-format");
-var OAComponentType = {
-  SCHEMA: "schema",
-  RESPONSE: "response",
-  PARAMETER: "parameter",
-  EXAMPLE: "example",
-  REQUEST_BODY: "requestBody",
-  HEADER: "header",
-  SECURITY_SCHEME: "securityScheme",
-  LINK: "link",
-  CALLBACK: "callback",
-  PATH_ITEM: "pathItem"
-};
-var OA_COMPONENT_TYPE_TO_KEY_MAP = {
-  [OAComponentType.SCHEMA]: "schemas",
-  [OAComponentType.RESPONSE]: "responses",
-  [OAComponentType.PARAMETER]: "parameters",
-  [OAComponentType.EXAMPLE]: "examples",
-  [OAComponentType.REQUEST_BODY]: "requestBodies",
-  [OAComponentType.HEADER]: "headers",
-  [OAComponentType.SECURITY_SCHEME]: "securitySchemes",
-  [OAComponentType.LINK]: "links",
-  [OAComponentType.CALLBACK]: "callbacks",
-  [OAComponentType.PATH_ITEM]: "pathItems"
-};
-function oaRef(name, type) {
+function oaRef(name, segment) {
   if (!name || typeof name !== "string") {
   if (!name || typeof name !== "string") {
     throw new import_js_format.InvalidArgumentError(
     throw new import_js_format.InvalidArgumentError(
       'Parameter "name" must be a non-empty String, but %v was given.',
       'Parameter "name" must be a non-empty String, but %v was given.',
       name
       name
     );
     );
   }
   }
-  if (!type || typeof type !== "string") {
+  if (!Object.values(OAComponentsSegment).includes(segment)) {
     throw new import_js_format.InvalidArgumentError(
     throw new import_js_format.InvalidArgumentError(
-      'Parameter "type" must be a non-empty String, but %v was given.',
-      type
+      'Parameter "segment" must be one of values: %l, but %v was given.',
+      Object.values(OAComponentsSegment),
+      segment
     );
     );
   }
   }
-  const key = OA_COMPONENT_TYPE_TO_KEY_MAP[type];
-  if (!key) {
-    throw new import_js_format.InvalidArgumentError("Component type %v is not supported.", type);
-  }
-  return { $ref: `#/components/${key}/${name}` };
+  return { $ref: `#/components/${segment}/${name}` };
 }
 }
 __name(oaRef, "oaRef");
 __name(oaRef, "oaRef");
-var oaSchemaRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.SCHEMA), "oaSchemaRef");
-var oaResponseRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.RESPONSE), "oaResponseRef");
-var oaParameterRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.PARAMETER), "oaParameterRef");
-var oaExampleRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.EXAMPLE), "oaExampleRef");
-var oaRequestBodyRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.REQUEST_BODY), "oaRequestBodyRef");
-var oaSecuritySchemeRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.SECURITY_SCHEME), "oaSecuritySchemeRef");
-var oaLinkRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.LINK), "oaLinkRef");
-var oaCallbackRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.CALLBACK), "oaCallbackRef");
-var oaPathItemRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentType.PATH_ITEM), "oaPathItemRef");
+var oaSchemaRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.SCHEMAS), "oaSchemaRef");
+var oaResponseRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.RESPONSES), "oaResponseRef");
+var oaParameterRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.PARAMETERS), "oaParameterRef");
+var oaExampleRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.EXAMPLES), "oaExampleRef");
+var oaRequestBodyRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.REQUEST_BODIES), "oaRequestBodyRef");
+var oaSecuritySchemeRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.SECURITY_SCHEMES), "oaSecuritySchemeRef");
+var oaLinkRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.LINKS), "oaLinkRef");
+var oaCallbackRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.CALLBACKS), "oaCallbackRef");
+var oaPathItemRef = /* @__PURE__ */ __name((name) => oaRef(name, OAComponentsSegment.PATH_ITEMS), "oaPathItemRef");
 
 
 // src/utils/join-path.js
 // src/utils/join-path.js
 function joinPath(...segments) {
 function joinPath(...segments) {
-  const path = segments.filter(Boolean).map((seg) => seg.replace(/(^\/|\/$)/g, "")).filter(Boolean).join("/");
+  const path = segments.filter((seg) => seg != void 0).map((seg) => String(seg).replace(/(^\/|\/$)/g, "")).filter(Boolean).join("/");
   return "/" + path;
   return "/" + path;
 }
 }
 __name(joinPath, "joinPath");
 __name(joinPath, "joinPath");
@@ -301,7 +285,10 @@ function validateShallowOADocumentObject(documentObject) {
 __name(validateShallowOADocumentObject, "validateShallowOADocumentObject");
 __name(validateShallowOADocumentObject, "validateShallowOADocumentObject");
 
 
 // src/oa-document-builder.js
 // src/oa-document-builder.js
-var _OADocumentBuilder = class _OADocumentBuilder extends import_js_service.Service {
+var OADocumentBuilder = class extends import_js_service.Service {
+  static {
+    __name(this, "OADocumentBuilder");
+  }
   /**
   /**
    * Document.
    * Document.
    *
    *
@@ -361,35 +348,28 @@ var _OADocumentBuilder = class _OADocumentBuilder extends import_js_service.Serv
   /**
   /**
    * Define component.
    * Define component.
    *
    *
-   * @param {string} targetKey
-   * @param {string} componentKey
-   * @param {string} definitionLabel
+   * @param {string} segmentName
+   * @param {string} propertyName
    * @param {object} definition
    * @param {object} definition
    * @returns {this}
    * @returns {this}
    */
    */
-  _defineComponent(targetKey, componentKey, definitionLabel, definition) {
-    if (!targetKey || typeof targetKey !== "string") {
+  _defineComponent(segmentName, propertyName, definition) {
+    if (!Object.values(OAComponentsSegment).includes(segmentName)) {
       throw new import_js_format3.InvalidArgumentError(
       throw new import_js_format3.InvalidArgumentError(
-        'Property "targetKey" must be a non-empty String, but %v was given.',
-        targetKey
+        'Property "segmentName" must be one of values: %l, but %v was given.',
+        Object.values(OAComponentsSegment),
+        segmentName
       );
       );
     }
     }
-    if (!componentKey || typeof componentKey !== "string") {
+    if (!propertyName || typeof propertyName !== "string") {
       throw new import_js_format3.InvalidArgumentError(
       throw new import_js_format3.InvalidArgumentError(
-        'Property "componentKey" must be a non-empty String, but %v was given.',
-        componentKey
-      );
-    }
-    if (!definitionLabel || typeof definitionLabel !== "string") {
-      throw new import_js_format3.InvalidArgumentError(
-        'Property "definitionLabel" must be a non-empty String, but %v was given.',
-        definitionLabel
+        'Property "propertyName" must be a non-empty String, but %v was given.',
+        propertyName
       );
       );
     }
     }
     if (!definition || typeof definition !== "object" || Array.isArray(definition)) {
     if (!definition || typeof definition !== "object" || Array.isArray(definition)) {
       throw new import_js_format3.InvalidArgumentError(
       throw new import_js_format3.InvalidArgumentError(
-        "%s Definition must be an Object, but %v was given.",
-        definitionLabel,
+        "Component definition must be an Object, but %v was given.",
         definition
         definition
       );
       );
     }
     }
@@ -399,140 +379,150 @@ var _OADocumentBuilder = class _OADocumentBuilder extends import_js_service.Serv
         definition.name
         definition.name
       );
       );
     }
     }
-    const component = definition[componentKey];
+    const component = definition[propertyName];
     if (!component || typeof component !== "object" || Array.isArray(component)) {
     if (!component || typeof component !== "object" || Array.isArray(component)) {
       throw new import_js_format3.InvalidArgumentError(
       throw new import_js_format3.InvalidArgumentError(
         "Property %v must be an Object, but %v was given.",
         "Property %v must be an Object, but %v was given.",
-        componentKey,
+        propertyName,
         component
         component
       );
       );
     }
     }
     if (!this._document.components) {
     if (!this._document.components) {
       this._document.components = {};
       this._document.components = {};
     }
     }
-    if (!this._document.components[targetKey]) {
-      this._document.components[targetKey] = {};
+    if (!this._document.components[segmentName]) {
+      this._document.components[segmentName] = {};
     }
     }
-    this._document.components[targetKey][definition.name] = component;
+    this._document.components[segmentName][definition.name] = structuredClone(component);
     return this;
     return this;
   }
   }
   /**
   /**
    * Define schema component.
    * Define schema component.
    *
    *
-   * @param {import('./oa-document-builder.js').OASchemaComponentDefinition} schemaDef
+   * @param {object} schemaDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineSchemaComponent(schemaDef) {
   defineSchemaComponent(schemaDef) {
-    return this._defineComponent("schemas", "schema", "Schema", schemaDef);
+    return this._defineComponent(
+      OAComponentsSegment.SCHEMAS,
+      "schema",
+      schemaDef
+    );
   }
   }
   /**
   /**
    * Define response component.
    * Define response component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAResponseComponentDefinition} responseDef
+   * @param {object} responseDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineResponseComponent(responseDef) {
   defineResponseComponent(responseDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "responses",
+      OAComponentsSegment.RESPONSES,
       "response",
       "response",
-      "Response",
       responseDef
       responseDef
     );
     );
   }
   }
   /**
   /**
    * Define parameter component.
    * Define parameter component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAParameterComponentDefinition} parameterDef
+   * @param {object} parameterDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineParameterComponent(parameterDef) {
   defineParameterComponent(parameterDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "parameters",
+      OAComponentsSegment.PARAMETERS,
       "parameter",
       "parameter",
-      "Parameter",
       parameterDef
       parameterDef
     );
     );
   }
   }
   /**
   /**
    * Define example component.
    * Define example component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAExampleComponentDefinition} exampleDef
+   * @param {object} exampleDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineExampleComponent(exampleDef) {
   defineExampleComponent(exampleDef) {
-    return this._defineComponent("examples", "example", "Example", exampleDef);
+    return this._defineComponent(
+      OAComponentsSegment.EXAMPLES,
+      "example",
+      exampleDef
+    );
   }
   }
   /**
   /**
    * Define request body component.
    * Define request body component.
    *
    *
-   * @param {import('./oa-document-builder.js').OARequestBodyComponentDefinition} requestBodyDef
+   * @param {object} requestBodyDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineRequestBodyComponent(requestBodyDef) {
   defineRequestBodyComponent(requestBodyDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "requestBodies",
+      OAComponentsSegment.REQUEST_BODIES,
       "requestBody",
       "requestBody",
-      "Request body",
       requestBodyDef
       requestBodyDef
     );
     );
   }
   }
   /**
   /**
    * Define header component.
    * Define header component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAHeaderComponentDefinition} headerDef
+   * @param {object} headerDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineHeaderComponent(headerDef) {
   defineHeaderComponent(headerDef) {
-    return this._defineComponent("headers", "header", "Header", headerDef);
+    return this._defineComponent(
+      OAComponentsSegment.HEADERS,
+      "header",
+      headerDef
+    );
   }
   }
   /**
   /**
    * Define security scheme component.
    * Define security scheme component.
    *
    *
-   * @param {import('./oa-document-builder.js').OASecuritySchemeComponentDefinition} securitySchemeDef
+   * @param {object} securitySchemeDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineSecuritySchemeComponent(securitySchemeDef) {
   defineSecuritySchemeComponent(securitySchemeDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "securitySchemes",
+      OAComponentsSegment.SECURITY_SCHEMES,
       "securityScheme",
       "securityScheme",
-      "Security Scheme",
       securitySchemeDef
       securitySchemeDef
     );
     );
   }
   }
   /**
   /**
    * Define link component.
    * Define link component.
    *
    *
-   * @param {import('./oa-document-builder.js').OALinkComponentDefinition} linkDef
+   * @param {object} linkDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineLinkComponent(linkDef) {
   defineLinkComponent(linkDef) {
-    return this._defineComponent("links", "link", "Link", linkDef);
+    return this._defineComponent(
+      OAComponentsSegment.LINKS,
+      "link",
+      linkDef
+    );
   }
   }
   /**
   /**
    * Define callback component.
    * Define callback component.
    *
    *
-   * @param {import('./oa-document-builder.js').OACallbackComponentDefinition} callbackDef
+   * @param {object} callbackDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineCallbackComponent(callbackDef) {
   defineCallbackComponent(callbackDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "callbacks",
+      OAComponentsSegment.CALLBACKS,
       "callback",
       "callback",
-      "Callback",
       callbackDef
       callbackDef
     );
     );
   }
   }
   /**
   /**
    * Define path item component.
    * Define path item component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAPathItemComponentDefinition} pathItemDef
+   * @param {object} pathItemDef
    * @returns {this}
    * @returns {this}
    */
    */
   definePathItemComponent(pathItemDef) {
   definePathItemComponent(pathItemDef) {
     return this._defineComponent(
     return this._defineComponent(
-      "pathItems",
+      OAComponentsSegment.PATH_ITEMS,
       "pathItem",
       "pathItem",
-      "Path Item",
       pathItemDef
       pathItemDef
     );
     );
   }
   }
@@ -603,12 +593,22 @@ var _OADocumentBuilder = class _OADocumentBuilder extends import_js_service.Serv
   build() {
   build() {
     return structuredClone(this._document);
     return structuredClone(this._document);
   }
   }
+  /**
+   * Build JSON.
+   *
+   * @param {string|number} [space]
+   * @returns {string}
+   */
+  buildJson(space = 0) {
+    return JSON.stringify(this._document, null, space);
+  }
 };
 };
-__name(_OADocumentBuilder, "OADocumentBuilder");
-var OADocumentBuilder = _OADocumentBuilder;
 
 
 // src/oa-document-scope.js
 // src/oa-document-scope.js
-var _OADocumentScope = class _OADocumentScope {
+var OADocumentScope = class _OADocumentScope {
+  static {
+    __name(this, "OADocumentScope");
+  }
   /**
   /**
    * @param {object} rootBuilder
    * @param {object} rootBuilder
    * @param {object} [options]
    * @param {object} [options]
@@ -754,21 +754,11 @@ var _OADocumentScope = class _OADocumentScope {
       tags: [...this.tags, ...options.tags || []]
       tags: [...this.tags, ...options.tags || []]
     });
     });
   }
   }
-  /**
-   * Build.
-   *
-   * @returns {object}
-   */
-  build() {
-    return this.rootBuilder.build();
-  }
 };
 };
-__name(_OADocumentScope, "OADocumentScope");
-var OADocumentScope = _OADocumentScope;
 // Annotate the CommonJS export names for ESM import in node:
 // Annotate the CommonJS export names for ESM import in node:
 0 && (module.exports = {
 0 && (module.exports = {
   OAApiKeyLocation,
   OAApiKeyLocation,
-  OAComponentType,
+  OAComponentsSegment,
   OADataFormat,
   OADataFormat,
   OADataType,
   OADataType,
   OADocumentBuilder,
   OADocumentBuilder,
@@ -778,7 +768,6 @@ var OADocumentScope = _OADocumentScope;
   OAParameterLocation,
   OAParameterLocation,
   OAParameterStyle,
   OAParameterStyle,
   OASecuritySchemeType,
   OASecuritySchemeType,
-  OA_COMPONENT_TYPE_TO_KEY_MAP,
   OPENAPI_VERSION,
   OPENAPI_VERSION,
   oaCallbackRef,
   oaCallbackRef,
   oaExampleRef,
   oaExampleRef,

+ 2 - 2
package.json

@@ -24,12 +24,12 @@
     "require": "./dist/cjs/index.cjs"
     "require": "./dist/cjs/index.cjs"
   },
   },
   "engines": {
   "engines": {
-    "node": ">=12"
+    "node": ">=18"
   },
   },
   "scripts": {
   "scripts": {
     "lint": "tsc && eslint ./src",
     "lint": "tsc && eslint ./src",
     "lint:fix": "tsc && eslint ./src --fix",
     "lint:fix": "tsc && eslint ./src --fix",
-    "format": "prettier --write \"./src/**/*.js\"",
+    "format": "prettier --write \"./src/**/*.{js,ts}\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha --bail",
     "test": "npm run lint && c8 --reporter=text-summary mocha --bail",
     "test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
     "test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
     "build:cjs": "rimraf ./dist/cjs && node build-cjs.js",
     "build:cjs": "rimraf ./dist/cjs && node build-cjs.js",

+ 22 - 0
src/constants.d.ts

@@ -2,3 +2,25 @@
  * OpenAPI version.
  * OpenAPI version.
  */
  */
 export declare const OPENAPI_VERSION: '3.1.0';
 export declare const OPENAPI_VERSION: '3.1.0';
+
+/**
+ * Components segment.
+ *
+ * "#/components/{segment}/{name}"
+ *                  ^^^
+ */
+export declare const OAComponentsSegment: {
+  SCHEMAS: 'schemas';
+  RESPONSES: 'responses';
+  PARAMETERS: 'parameters';
+  EXAMPLES: 'examples';
+  REQUEST_BODIES: 'requestBodies';
+  HEADERS: 'headers';
+  SECURITY_SCHEMES: 'securitySchemes';
+  LINKS: 'links';
+  CALLBACKS: 'callbacks';
+  PATH_ITEMS: 'pathItems';
+};
+
+export type OAComponentsSegment =
+  (typeof OAComponentsSegment)[keyof typeof OAComponentsSegment];

+ 19 - 0
src/constants.js

@@ -2,3 +2,22 @@
  * OpenAPI version.
  * OpenAPI version.
  */
  */
 export const OPENAPI_VERSION = '3.1.0';
 export const OPENAPI_VERSION = '3.1.0';
+
+/**
+ * Components segment.
+ *
+ * "#/components/{segment}/{name}"
+ *                  ^^^
+ */
+export const OAComponentsSegment = {
+  SCHEMAS: 'schemas',
+  RESPONSES: 'responses',
+  PARAMETERS: 'parameters',
+  EXAMPLES: 'examples',
+  REQUEST_BODIES: 'requestBodies',
+  HEADERS: 'headers',
+  SECURITY_SCHEMES: 'securitySchemes',
+  LINKS: 'links',
+  CALLBACKS: 'callbacks',
+  PATH_ITEMS: 'pathItems',
+};

+ 1 - 1
src/document-specification.d.ts

@@ -516,7 +516,7 @@ export type OASchemaPropertiesObject = {
  */
  */
 export type OAWebhooksObject = {
 export type OAWebhooksObject = {
   [name: string]: OAPathItemObject | OAReferenceObject | undefined;
   [name: string]: OAPathItemObject | OAReferenceObject | undefined;
-}
+};
 
 
 /**
 /**
  * Callbacks Object.
  * Callbacks Object.

+ 1 - 1
src/index.d.ts

@@ -3,4 +3,4 @@ export * from './oa-document-scope.js';
 export * from './oa-document-builder.js';
 export * from './oa-document-builder.js';
 export * from './document-specification.js';
 export * from './document-specification.js';
 
 
-export * from './utils/oa-ref.js';
+export * from './utils/oa-ref.js';

+ 7 - 0
src/oa-document-builder.d.ts

@@ -235,4 +235,11 @@ export declare class OADocumentBuilder extends Service {
    * Build.
    * Build.
    */
    */
   build(): OADocumentObject;
   build(): OADocumentObject;
+
+  /**
+   * Build JSON.
+   *
+   * @param space
+   */
+  buildJson(space?: string | number): string;
 }
 }

+ 67 - 54
src/oa-document-builder.js

@@ -1,8 +1,8 @@
-import {OPENAPI_VERSION} from './constants.js';
 import {OADocumentScope} from './oa-document-scope.js';
 import {OADocumentScope} from './oa-document-scope.js';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 import {OAOperationMethod} from './document-specification.js';
 import {OAOperationMethod} from './document-specification.js';
 import {isServiceContainer, Service} from '@e22m4u/js-service';
 import {isServiceContainer, Service} from '@e22m4u/js-service';
+import {OAComponentsSegment, OPENAPI_VERSION} from './constants.js';
 import {validateShallowOADocumentObject} from './document-validators.js';
 import {validateShallowOADocumentObject} from './document-validators.js';
 
 
 /**
 /**
@@ -94,35 +94,27 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define component.
    * Define component.
    *
    *
-   * @param {string} targetKey
-   * @param {string} componentKey
-   * @param {string} definitionLabel
+   * @param {string} segmentName
+   * @param {string} propertyName
    * @param {object} definition
    * @param {object} definition
    * @returns {this}
    * @returns {this}
    */
    */
-  _defineComponent(targetKey, componentKey, definitionLabel, definition) {
-    // targetKey
-    if (!targetKey || typeof targetKey !== 'string') {
+  _defineComponent(segmentName, propertyName, definition) {
+    // segmentName
+    if (!Object.values(OAComponentsSegment).includes(segmentName)) {
       throw new InvalidArgumentError(
       throw new InvalidArgumentError(
-        'Property "targetKey" must be a non-empty String, ' +
+        'Property "segmentName" must be one of values: %l, ' +
           'but %v was given.',
           'but %v was given.',
-        targetKey,
+        Object.values(OAComponentsSegment),
+        segmentName,
       );
       );
     }
     }
-    // componentKey
-    if (!componentKey || typeof componentKey !== 'string') {
+    // propertyName
+    if (!propertyName || typeof propertyName !== 'string') {
       throw new InvalidArgumentError(
       throw new InvalidArgumentError(
-        'Property "componentKey" must be a non-empty String, ' +
+        'Property "propertyName" must be a non-empty String, ' +
           'but %v was given.',
           'but %v was given.',
-        componentKey,
-      );
-    }
-    // definitionLabel
-    if (!definitionLabel || typeof definitionLabel !== 'string') {
-      throw new InvalidArgumentError(
-        'Property "definitionLabel" must be a non-empty String, ' +
-          'but %v was given.',
-        definitionLabel,
+        propertyName,
       );
       );
     }
     }
     // definition
     // definition
@@ -132,8 +124,7 @@ export class OADocumentBuilder extends Service {
       Array.isArray(definition)
       Array.isArray(definition)
     ) {
     ) {
       throw new InvalidArgumentError(
       throw new InvalidArgumentError(
-        '%s Definition must be an Object, but %v was given.',
-        definitionLabel,
+        'Component definition must be an Object, but %v was given.',
         definition,
         definition,
       );
       );
     }
     }
@@ -145,7 +136,7 @@ export class OADocumentBuilder extends Service {
       );
       );
     }
     }
     // definition[componentKey]
     // definition[componentKey]
-    const component = definition[componentKey];
+    const component = definition[propertyName];
     if (
     if (
       !component ||
       !component ||
       typeof component !== 'object' ||
       typeof component !== 'object' ||
@@ -153,41 +144,45 @@ export class OADocumentBuilder extends Service {
     ) {
     ) {
       throw new InvalidArgumentError(
       throw new InvalidArgumentError(
         'Property %v must be an Object, but %v was given.',
         'Property %v must be an Object, but %v was given.',
-        componentKey,
+        propertyName,
         component,
         component,
       );
       );
     }
     }
     if (!this._document.components) {
     if (!this._document.components) {
       this._document.components = {};
       this._document.components = {};
     }
     }
-    if (!this._document.components[targetKey]) {
-      this._document.components[targetKey] = {};
+    if (!this._document.components[segmentName]) {
+      this._document.components[segmentName] = {};
     }
     }
-    this._document.components[targetKey][definition.name] = component;
+    this._document.components[segmentName][definition.name] =
+      structuredClone(component);
     return this;
     return this;
   }
   }
 
 
   /**
   /**
    * Define schema component.
    * Define schema component.
    *
    *
-   * @param {import('./oa-document-builder.js').OASchemaComponentDefinition} schemaDef
+   * @param {object} schemaDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineSchemaComponent(schemaDef) {
   defineSchemaComponent(schemaDef) {
-    return this._defineComponent('schemas', 'schema', 'Schema', schemaDef);
+    return this._defineComponent(
+      OAComponentsSegment.SCHEMAS,
+      'schema',
+      schemaDef,
+    );
   }
   }
 
 
   /**
   /**
    * Define response component.
    * Define response component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAResponseComponentDefinition} responseDef
+   * @param {object} responseDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineResponseComponent(responseDef) {
   defineResponseComponent(responseDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'responses',
+      OAComponentsSegment.RESPONSES,
       'response',
       'response',
-      'Response',
       responseDef,
       responseDef,
     );
     );
   }
   }
@@ -195,14 +190,13 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define parameter component.
    * Define parameter component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAParameterComponentDefinition} parameterDef
+   * @param {object} parameterDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineParameterComponent(parameterDef) {
   defineParameterComponent(parameterDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'parameters',
+      OAComponentsSegment.PARAMETERS,
       'parameter',
       'parameter',
-      'Parameter',
       parameterDef,
       parameterDef,
     );
     );
   }
   }
@@ -210,24 +204,27 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define example component.
    * Define example component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAExampleComponentDefinition} exampleDef
+   * @param {object} exampleDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineExampleComponent(exampleDef) {
   defineExampleComponent(exampleDef) {
-    return this._defineComponent('examples', 'example', 'Example', exampleDef);
+    return this._defineComponent(
+      OAComponentsSegment.EXAMPLES,
+      'example',
+      exampleDef,
+    );
   }
   }
 
 
   /**
   /**
    * Define request body component.
    * Define request body component.
    *
    *
-   * @param {import('./oa-document-builder.js').OARequestBodyComponentDefinition} requestBodyDef
+   * @param {object} requestBodyDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineRequestBodyComponent(requestBodyDef) {
   defineRequestBodyComponent(requestBodyDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'requestBodies',
+      OAComponentsSegment.REQUEST_BODIES,
       'requestBody',
       'requestBody',
-      'Request body',
       requestBodyDef,
       requestBodyDef,
     );
     );
   }
   }
@@ -235,24 +232,27 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define header component.
    * Define header component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAHeaderComponentDefinition} headerDef
+   * @param {object} headerDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineHeaderComponent(headerDef) {
   defineHeaderComponent(headerDef) {
-    return this._defineComponent('headers', 'header', 'Header', headerDef);
+    return this._defineComponent(
+      OAComponentsSegment.HEADERS,
+      'header',
+      headerDef,
+    );
   }
   }
 
 
   /**
   /**
    * Define security scheme component.
    * Define security scheme component.
    *
    *
-   * @param {import('./oa-document-builder.js').OASecuritySchemeComponentDefinition} securitySchemeDef
+   * @param {object} securitySchemeDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineSecuritySchemeComponent(securitySchemeDef) {
   defineSecuritySchemeComponent(securitySchemeDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'securitySchemes',
+      OAComponentsSegment.SECURITY_SCHEMES,
       'securityScheme',
       'securityScheme',
-      'Security Scheme',
       securitySchemeDef,
       securitySchemeDef,
     );
     );
   }
   }
@@ -260,24 +260,28 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define link component.
    * Define link component.
    *
    *
-   * @param {import('./oa-document-builder.js').OALinkComponentDefinition} linkDef
+   * @param {object} linkDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineLinkComponent(linkDef) {
   defineLinkComponent(linkDef) {
-    return this._defineComponent('links', 'link', 'Link', linkDef);
+    /* prettier-ignore */
+    return this._defineComponent(
+      OAComponentsSegment.LINKS,
+      'link',
+      linkDef,
+    );
   }
   }
 
 
   /**
   /**
    * Define callback component.
    * Define callback component.
    *
    *
-   * @param {import('./oa-document-builder.js').OACallbackComponentDefinition} callbackDef
+   * @param {object} callbackDef
    * @returns {this}
    * @returns {this}
    */
    */
   defineCallbackComponent(callbackDef) {
   defineCallbackComponent(callbackDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'callbacks',
+      OAComponentsSegment.CALLBACKS,
       'callback',
       'callback',
-      'Callback',
       callbackDef,
       callbackDef,
     );
     );
   }
   }
@@ -285,14 +289,13 @@ export class OADocumentBuilder extends Service {
   /**
   /**
    * Define path item component.
    * Define path item component.
    *
    *
-   * @param {import('./oa-document-builder.js').OAPathItemComponentDefinition} pathItemDef
+   * @param {object} pathItemDef
    * @returns {this}
    * @returns {this}
    */
    */
   definePathItemComponent(pathItemDef) {
   definePathItemComponent(pathItemDef) {
     return this._defineComponent(
     return this._defineComponent(
-      'pathItems',
+      OAComponentsSegment.PATH_ITEMS,
       'pathItem',
       'pathItem',
-      'Path Item',
       pathItemDef,
       pathItemDef,
     );
     );
   }
   }
@@ -378,4 +381,14 @@ export class OADocumentBuilder extends Service {
   build() {
   build() {
     return structuredClone(this._document);
     return structuredClone(this._document);
   }
   }
+
+  /**
+   * Build JSON.
+   *
+   * @param {string|number} [space]
+   * @returns {string}
+   */
+  buildJson(space = 0) {
+    return JSON.stringify(this._document, null, space);
+  }
 }
 }

+ 0 - 7
src/oa-document-scope.d.ts

@@ -1,5 +1,3 @@
-import {OADocumentObject} from './document-specification.js';
-
 import {
 import {
   OADocumentBuilder,
   OADocumentBuilder,
   OAOperationDefinition,
   OAOperationDefinition,
@@ -36,9 +34,4 @@ export declare class OADocumentScope {
    * @param options
    * @param options
    */
    */
   createScope(options?: OADocumentScopeOptions): OADocumentScope;
   createScope(options?: OADocumentScopeOptions): OADocumentScope;
-
-  /**
-   * Build.
-   */
-  build(): OADocumentObject;
 }
 }

+ 0 - 9
src/oa-document-scope.js

@@ -178,13 +178,4 @@ export class OADocumentScope {
       tags: [...this.tags, ...(options.tags || [])],
       tags: [...this.tags, ...(options.tags || [])],
     });
     });
   }
   }
-
-  /**
-   * Build.
-   *
-   * @returns {object}
-   */
-  build() {
-    return this.rootBuilder.build();
-  }
 }
 }

+ 1 - 1
src/utils/index.d.ts

@@ -1,2 +1,2 @@
 export * from './oa-ref.js';
 export * from './oa-ref.js';
-export * from './join-path.js';
+export * from './join-path.js';

+ 1 - 1
src/utils/join-path.d.ts

@@ -3,4 +3,4 @@
  *
  *
  * @param segments
  * @param segments
  */
  */
-export declare function joinPath(...segments: string[]): string;
+export declare function joinPath(...segments: (string | number)[]): string;

+ 2 - 2
src/utils/join-path.js

@@ -6,8 +6,8 @@
  */
  */
 export function joinPath(...segments) {
 export function joinPath(...segments) {
   const path = segments
   const path = segments
-    .filter(Boolean)
-    .map(seg => seg.replace(/(^\/|\/$)/g, ''))
+    .filter(seg => seg != undefined)
+    .map(seg => String(seg).replace(/(^\/|\/$)/g, ''))
     .filter(Boolean)
     .filter(Boolean)
     .join('/');
     .join('/');
   return '/' + path;
   return '/' + path;

+ 5 - 0
src/utils/join-path.spec.js

@@ -61,4 +61,9 @@ describe('joinPath', function () {
     const result = joinPath('api/v1', 'users');
     const result = joinPath('api/v1', 'users');
     expect(result).to.be.eq('/api/v1/users');
     expect(result).to.be.eq('/api/v1/users');
   });
   });
+
+  it('should convert number arguments to string segments', function () {
+    const result = joinPath(-10, 0, 10);
+    expect(result).to.be.eq('/-10/0/10');
+  });
 });
 });

+ 4 - 22
src/utils/oa-ref.d.ts

@@ -1,40 +1,22 @@
+import {OAComponentsSegment} from '../constants.js';
 import {OAReferenceObject} from '../document-specification.js';
 import {OAReferenceObject} from '../document-specification.js';
 
 
-/**
- * Component type.
- */
-export declare const OAComponentType: {
-  SCHEMA: 'schema';
-  RESPONSE: 'response';
-  PARAMETER: 'parameter';
-  EXAMPLE: 'example';
-  REQUEST_BODY: 'requestBody';
-  HEADER: 'header';
-  SECURITY_SCHEME: 'securityScheme';
-  LINK: 'link';
-  CALLBACK: 'callback';
-  PATH_ITEM: 'pathItem';
-};
-
-export type OAComponentType =
-  (typeof OAComponentType)[keyof typeof OAComponentType];
-
 /**
 /**
  * Create the Reference Object.
  * Create the Reference Object.
  *
  *
  * Example:
  * Example:
  *
  *
  * ```js
  * ```js
- * oaRef('User', OAComponentType.SCHEMA);
+ * oaRef('User', OAComponentsSegment.SCHEMAS);
  * // {"$ref": "#/components/schemas/User"}
  * // {"$ref": "#/components/schemas/User"}
  * ```
  * ```
  *
  *
  * @param name
  * @param name
- * @param type
+ * @param segment
  */
  */
 export declare function oaRef(
 export declare function oaRef(
   name: string,
   name: string,
-  type: OAComponentType,
+  segment: OAComponentsSegment,
 ): OAReferenceObject;
 ): OAReferenceObject;
 
 
 /* aliases */
 /* aliases */

+ 20 - 52
src/utils/oa-ref.js

@@ -1,80 +1,48 @@
+import {OAComponentsSegment} from '../constants.js';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 import {InvalidArgumentError} from '@e22m4u/js-format';
 
 
-/**
- * Component type.
- */
-export const OAComponentType = {
-  SCHEMA: 'schema',
-  RESPONSE: 'response',
-  PARAMETER: 'parameter',
-  EXAMPLE: 'example',
-  REQUEST_BODY: 'requestBody',
-  HEADER: 'header',
-  SECURITY_SCHEME: 'securityScheme',
-  LINK: 'link',
-  CALLBACK: 'callback',
-  PATH_ITEM: 'pathItem',
-};
-
-/**
- * Component type to key map.
- */
-export const OA_COMPONENT_TYPE_TO_KEY_MAP = {
-  [OAComponentType.SCHEMA]: 'schemas',
-  [OAComponentType.RESPONSE]: 'responses',
-  [OAComponentType.PARAMETER]: 'parameters',
-  [OAComponentType.EXAMPLE]: 'examples',
-  [OAComponentType.REQUEST_BODY]: 'requestBodies',
-  [OAComponentType.HEADER]: 'headers',
-  [OAComponentType.SECURITY_SCHEME]: 'securitySchemes',
-  [OAComponentType.LINK]: 'links',
-  [OAComponentType.CALLBACK]: 'callbacks',
-  [OAComponentType.PATH_ITEM]: 'pathItems',
-};
-
 /**
 /**
  * Create the Reference Object.
  * Create the Reference Object.
  *
  *
  * Example:
  * Example:
  *
  *
  * ```js
  * ```js
- * oaRef('User', OAComponentType.SCHEMA);
+ * oaRef('User', OAComponentsSegment.SCHEMAS);
  * // {"$ref": "#/components/schemas/User"}
  * // {"$ref": "#/components/schemas/User"}
  * ```
  * ```
  *
  *
  * @param {string} name
  * @param {string} name
- * @param {string} type
+ * @param {string} segment
  * @returns {object}
  * @returns {object}
  */
  */
-export function oaRef(name, type) {
+export function oaRef(name, segment) {
   if (!name || typeof name !== 'string') {
   if (!name || typeof name !== 'string') {
     throw new InvalidArgumentError(
     throw new InvalidArgumentError(
       'Parameter "name" must be a non-empty String, but %v was given.',
       'Parameter "name" must be a non-empty String, but %v was given.',
       name,
       name,
     );
     );
   }
   }
-  if (!type || typeof type !== 'string') {
+  if (!Object.values(OAComponentsSegment).includes(segment)) {
     throw new InvalidArgumentError(
     throw new InvalidArgumentError(
-      'Parameter "type" must be a non-empty String, but %v was given.',
-      type,
+      'Parameter "segment" must be one of values: %l, but %v was given.',
+      Object.values(OAComponentsSegment),
+      segment,
     );
     );
   }
   }
-  const key = OA_COMPONENT_TYPE_TO_KEY_MAP[type];
-  if (!key) {
-    throw new InvalidArgumentError('Component type %v is not supported.', type);
-  }
-  return {$ref: `#/components/${key}/${name}`};
+  return {$ref: `#/components/${segment}/${name}`};
 }
 }
 
 
 /* aliases */
 /* aliases */
-export const oaSchemaRef = name => oaRef(name, OAComponentType.SCHEMA);
-export const oaResponseRef = name => oaRef(name, OAComponentType.RESPONSE);
-export const oaParameterRef = name => oaRef(name, OAComponentType.PARAMETER);
-export const oaExampleRef = name => oaRef(name, OAComponentType.EXAMPLE);
+export const oaSchemaRef = name => oaRef(name, OAComponentsSegment.SCHEMAS);
+export const oaResponseRef = name => oaRef(name, OAComponentsSegment.RESPONSES);
+export const oaParameterRef = name =>
+  oaRef(name, OAComponentsSegment.PARAMETERS);
+export const oaExampleRef = name => oaRef(name, OAComponentsSegment.EXAMPLES);
 export const oaRequestBodyRef = name =>
 export const oaRequestBodyRef = name =>
-  oaRef(name, OAComponentType.REQUEST_BODY);
+  oaRef(name, OAComponentsSegment.REQUEST_BODIES);
 export const oaSecuritySchemeRef = name =>
 export const oaSecuritySchemeRef = name =>
-  oaRef(name, OAComponentType.SECURITY_SCHEME);
-export const oaLinkRef = name => oaRef(name, OAComponentType.LINK);
-export const oaCallbackRef = name => oaRef(name, OAComponentType.CALLBACK);
-export const oaPathItemRef = name => oaRef(name, OAComponentType.PATH_ITEM);
+  oaRef(name, OAComponentsSegment.SECURITY_SCHEMES);
+export const oaLinkRef = name => oaRef(name, OAComponentsSegment.LINKS);
+export const oaCallbackRef = name => oaRef(name, OAComponentsSegment.CALLBACKS);
+export const oaPathItemRef = name =>
+  oaRef(name, OAComponentsSegment.PATH_ITEMS);

+ 16 - 19
src/utils/oa-ref.spec.js

@@ -1,5 +1,6 @@
 import {expect} from 'chai';
 import {expect} from 'chai';
 import {format} from '@e22m4u/js-format';
 import {format} from '@e22m4u/js-format';
+import {OAComponentsSegment} from '../constants.js';
 
 
 import {
 import {
   oaRef,
   oaRef,
@@ -10,15 +11,13 @@ import {
   oaPathItemRef,
   oaPathItemRef,
   oaCallbackRef,
   oaCallbackRef,
   oaParameterRef,
   oaParameterRef,
-  OAComponentType,
   oaRequestBodyRef,
   oaRequestBodyRef,
   oaSecuritySchemeRef,
   oaSecuritySchemeRef,
-  OA_COMPONENT_TYPE_TO_KEY_MAP,
 } from './oa-ref.js';
 } from './oa-ref.js';
 
 
 describe('oaRef', function () {
 describe('oaRef', function () {
   it('should require the "name" parameter to be a non-empty String', function () {
   it('should require the "name" parameter to be a non-empty String', function () {
-    const throwable = v => () => oaRef(v, OAComponentType.SCHEMA);
+    const throwable = v => () => oaRef(v, OAComponentsSegment.SCHEMAS);
     const error = s =>
     const error = s =>
       format(
       format(
         'Parameter "name" must be a non-empty String, but %s was given.',
         'Parameter "name" must be a non-empty String, but %s was given.',
@@ -36,13 +35,16 @@ describe('oaRef', function () {
     throwable('str')();
     throwable('str')();
   });
   });
 
 
-  it('should require the "type" parameter to be a non-empty String', function () {
+  it('should require the "segment" parameter to be a components segment', function () {
     const throwable = v => () => oaRef('Model', v);
     const throwable = v => () => oaRef('Model', v);
+    const segments = Object.values(OAComponentsSegment);
     const error = s =>
     const error = s =>
       format(
       format(
-        'Parameter "type" must be a non-empty String, but %s was given.',
+        'Parameter "segment" must be one of values: %l, but %s was given.',
+        segments,
         s,
         s,
       );
       );
+    expect(throwable('str')).to.throw(error('"str"'));
     expect(throwable('')).to.throw(error('""'));
     expect(throwable('')).to.throw(error('""'));
     expect(throwable(10)).to.throw(error('10'));
     expect(throwable(10)).to.throw(error('10'));
     expect(throwable(0)).to.throw(error('0'));
     expect(throwable(0)).to.throw(error('0'));
@@ -52,31 +54,26 @@ describe('oaRef', function () {
     expect(throwable({})).to.throw(error('Object'));
     expect(throwable({})).to.throw(error('Object'));
     expect(throwable(undefined)).to.throw(error('undefined'));
     expect(throwable(undefined)).to.throw(error('undefined'));
     expect(throwable(null)).to.throw(error('null'));
     expect(throwable(null)).to.throw(error('null'));
-    throwable(OAComponentType.SCHEMA)();
+    segments.forEach(segment => throwable(segment)());
   });
   });
 
 
-  it('should throw an error if a given type is not supported', function () {
-    const throwable = () => oaRef('name', 'unknown');
-    expect(throwable).to.throw('Component type "unknown" is not supported.');
-  });
-
-  it('should set the "name" argument to the component path', function () {
-    expect(oaRef('Model', OAComponentType.SCHEMA)).to.be.eql({
+  it('should set the "name" argument to the reference path', function () {
+    expect(oaRef('Model', OAComponentsSegment.SCHEMAS)).to.be.eql({
       $ref: '#/components/schemas/Model',
       $ref: '#/components/schemas/Model',
     });
     });
   });
   });
 
 
-  it('should set the correct segment by a given component type', function () {
-    Object.keys(OA_COMPONENT_TYPE_TO_KEY_MAP).forEach(type => {
-      const key = OA_COMPONENT_TYPE_TO_KEY_MAP[type];
-      expect(oaRef('name', type)).to.be.eql({
-        $ref: `#/components/${key}/name`,
+  it('should set the "segment" argument to the reference path', function () {
+    const segments = Object.values(OAComponentsSegment);
+    segments.forEach(segment => {
+      expect(oaRef('name', segment)).to.be.eql({
+        $ref: `#/components/${segment}/name`,
       });
       });
     });
     });
   });
   });
 
 
   describe('aliases', function () {
   describe('aliases', function () {
-    it('should use the correct type', function () {
+    it('should use the correct segment', function () {
       const aliasesToResultMap = [
       const aliasesToResultMap = [
         [oaSchemaRef, {$ref: '#/components/schemas/name'}],
         [oaSchemaRef, {$ref: '#/components/schemas/name'}],
         [oaResponseRef, {$ref: '#/components/responses/name'}],
         [oaResponseRef, {$ref: '#/components/responses/name'}],