@conduit-client/model 3.9.0 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ import { SourcePositionMap } from '../swagger/source-position-map';
10
10
  import { SwaggerAPI } from '../swagger/SwaggerAPI';
11
11
  import { AmfEndPoint } from '../amf/endpoints/amf-endpoint';
12
12
  import { API, Server } from '../../api';
13
+ import type SwaggerParser from '@apidevtools/swagger-parser';
13
14
  export type ParserKind = 'amf' | 'swagger';
14
15
  type ClassOfConstructor<T> = T extends new () => infer R ? R : never;
15
16
  /**
@@ -37,6 +38,7 @@ type TestSwaggerOAS<T extends Record<string, new () => amf.AnyShape>, E extends
37
38
  document: OpenAPIV3.Document;
38
39
  sourceUrl: URL;
39
40
  positionMap: SourcePositionMap;
41
+ $refs: SwaggerParser.$Refs;
40
42
  } & {
41
43
  [P in keyof T]: OpenAPIV3.SchemaObject;
42
44
  } & {
@@ -6,6 +6,7 @@ import type { API, EndPoint, Server } from '../../api';
6
6
  import type { ReadOnlyTypeRegistry, TypeRegistry } from '../../types';
7
7
  import type { OpenAPIV3 } from 'openapi-types';
8
8
  import type { NamedFeatureFlagsService } from '@conduit-client/service-feature-flags/v1';
9
+ import type SwaggerParser from '@apidevtools/swagger-parser';
9
10
  export declare const V1_VERSION = "1.0.0";
10
11
  export declare const ANONYMOUS_TYPE_NAME = "<anonymous>";
11
12
  export declare class SwaggerAPI implements API {
@@ -14,6 +15,7 @@ export declare class SwaggerAPI implements API {
14
15
  private services;
15
16
  private fileParserLogger;
16
17
  private positionMap;
18
+ private $refs;
17
19
  typeRegistry?: TypeRegistry<SwaggerType>;
18
20
  _endpoints?: EndPoint[];
19
21
  _servers?: Server[];
@@ -25,13 +27,27 @@ export declare class SwaggerAPI implements API {
25
27
  private parsedNamespace?;
26
28
  private defaultedNamespace;
27
29
  serviceOverrides?: ResolvedServiceOverrides;
28
- constructor(document: OpenAPIV3.Document, sourceUrl: URL, services: NamedLoggerService & NamedFeatureFlagsService, fileParserLogger: FileParserLogger, positionMap: SourcePositionMap);
30
+ constructor(document: OpenAPIV3.Document, sourceUrl: URL, services: NamedLoggerService & NamedFeatureFlagsService, fileParserLogger: FileParserLogger, positionMap: SourcePositionMap, $refs: SwaggerParser.$Refs);
29
31
  /**
30
32
  * Get the source position for a given JSON path in the OpenAPI document.
31
33
  * @param jsonPath - The JSON path (e.g., "paths//users/get" or "components/schemas/User")
32
34
  * @returns The position if found, undefined otherwise
33
35
  */
34
36
  getPosition(jsonPath: string): Position | undefined;
37
+ /**
38
+ * Find the position of a $ref declaration by its target value.
39
+ * @param refValue - The $ref target string (e.g., "./schemas/User.yaml#/TypeThatDoesNotExist")
40
+ * @returns The position where the $ref is declared, if found
41
+ */
42
+ getRefPosition(refValue: string): Position | undefined;
43
+ /**
44
+ * Resolve a $ref target path with respect to the directory of the source.
45
+ * This is particularly necessary for relative paths since this.$refs.get() resolves
46
+ * paths relative to the root file and not the ref source file.
47
+ * @param refPath - The $ref target path (e.g., "./schemas/User.yaml#/User")
48
+ * @returns The path from where the $ref is declared (e.g, "file:///path/to/source/./schemas/User.yaml#/User")
49
+ */
50
+ resolveRefTargetPath(refTarget: string): any;
35
51
  private build;
36
52
  private buildEndpoints;
37
53
  private buildServers;
@@ -1,4 +1,5 @@
1
1
  import { type LoggerService, type FileParserLogger } from '@conduit-client/utils';
2
+ import type { Position } from '../source-position-map';
2
3
  import type { OpenAPIV3 } from 'openapi-types';
3
4
  import type { BaseAuraOperation, AuraOperationWithRequestBody, BaseOperation, HttpMethod, Request, Response, CacheStrategy, ConfigSchemaType, OperationType, ErrorStrategy, Binding, BaseHttpOperation, HttpOperationWithRequestBody, BaseGraphQLOperation } from '../../../api/endpoint';
4
5
  import type { SwaggerType, SwaggerTypeFactory } from '../types';
@@ -29,10 +30,7 @@ export declare abstract class SwaggerBaseOperation implements BaseOperation {
29
30
  protected operationSchemaBuilder: OperationSchemaBuilder;
30
31
  defaults: API['defaults'];
31
32
  serviceOverrides: ResolvedOperationServices;
32
- position: {
33
- line: number;
34
- column: number;
35
- };
33
+ position: Position;
36
34
  basePath: string;
37
35
  abstract readonly type: 'aura' | 'http';
38
36
  constructor(operation: OpenAPIV3.OperationObject, methodStr: string, swaggerTypeFactory: SwaggerTypeFactory, typeRegistry: TypeRegistry<SwaggerType>, logger: LoggerService, fileParserLogger: FileParserLogger, endpoint: SwaggerEndPoint, server: Server);
@@ -1,3 +1,4 @@
1
+ import SwaggerParser from '@apidevtools/swagger-parser';
1
2
  import { SwaggerAPI } from './SwaggerAPI';
2
3
  import { SourcePositionMap } from './source-position-map';
3
4
  import type { OpenAPIV3 } from 'openapi-types';
@@ -6,6 +7,7 @@ import type { NamedFeatureFlagsService } from '@conduit-client/service-feature-f
6
7
  export interface ParsedSwaggerDocument {
7
8
  document: OpenAPIV3.Document;
8
9
  positionMap: SourcePositionMap;
10
+ $refs: SwaggerParser.$Refs;
9
11
  }
10
12
  /**
11
13
  * Parse and validate an OpenAPI document using swagger-parser
@@ -4,18 +4,27 @@
4
4
  export interface Position {
5
5
  line: number;
6
6
  column: number;
7
+ filePath: string;
7
8
  }
8
9
  /**
9
- * Maps JSON paths to their source positions in the YAML file.
10
+ * Maps JSON paths to their source positions in YAML files.
10
11
  * Used to provide accurate line/column information for validation errors.
12
+ * Supports both single-file and multi-file scenarios.
11
13
  */
12
14
  export declare class SourcePositionMap {
13
15
  private positions;
16
+ private fileUrls;
17
+ private refTargets;
14
18
  /**
15
19
  * Get the position for a given JSON path
16
20
  * @param jsonPath - The JSON path (e.g., "paths//users/get" or "components/schemas/User")
17
21
  */
18
22
  get(jsonPath: string): Position | undefined;
23
+ /**
24
+ * Get the position for a given $ref path
25
+ * @param refPath - The $ref path (e.g., "./schemas/User.yaml#/User")
26
+ */
27
+ getRef(refPath: string): Position | undefined;
19
28
  /**
20
29
  * Set the position for a given JSON path
21
30
  */
@@ -28,12 +37,40 @@ export declare class SourcePositionMap {
28
37
  * Get all stored paths
29
38
  */
30
39
  keys(): IterableIterator<string>;
40
+ /**
41
+ * Get all entries as [jsonPath, position] pairs
42
+ */
43
+ entries(): IterableIterator<[string, Position]>;
44
+ /**
45
+ * Get the number of files tracked in this map
46
+ */
47
+ get fileCount(): number;
48
+ /**
49
+ * Track a $ref target value and its position
50
+ */
51
+ setRefTarget(refValue: string, position: Position): void;
52
+ /**
53
+ * Find the position of a $ref that targets a file containing the given path,
54
+ * or an internal ref containing the given token.
55
+ */
56
+ findRefPosition(targetPath: string, token?: string): {
57
+ position: Position;
58
+ refValue: string;
59
+ } | undefined;
60
+ /**
61
+ * Merge positions from another map, setting filePath on each position.
62
+ * Used to aggregate positions from multiple files (e.g., external $refs).
63
+ * @param other - The source position map to merge from
64
+ * @param fileUrl - The file URL to associate with these positions
65
+ */
66
+ merge(other: SourcePositionMap, fileUrl: string): void;
31
67
  }
32
68
  /**
33
69
  * Builds a SourcePositionMap from YAML content by parsing it with the yaml package
34
70
  * which preserves source position information.
35
71
  *
36
72
  * @param yamlContent - The raw YAML content as a string
73
+ * @param fileUrl - The URL of the file being parsed
37
74
  * @returns A SourcePositionMap containing positions for operations and schemas
38
75
  */
39
- export declare function buildSourcePositionMap(yamlContent: string): SourcePositionMap;
76
+ export declare function buildSourcePositionMap(yamlContent: string, fileUrl: string): SourcePositionMap;
@@ -6,7 +6,8 @@ export type OpenAPISchema = OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject;
6
6
  * Works with any OpenAPI object type that could be a reference
7
7
  */
8
8
  export declare function isReferenceObject<T>(obj: T | OpenAPIV3.ReferenceObject): obj is OpenAPIV3.ReferenceObject;
9
- export declare function isSchemaObject(schema: OpenAPISchema): schema is OpenAPIV3.SchemaObject;
9
+ export declare function isSchemaObject(obj: unknown): obj is OpenAPIV3.SchemaObject;
10
+ export declare function isOpenAPISchema(obj: unknown): obj is OpenAPISchema;
10
11
  export declare function isArraySchema(schema: OpenAPIV3.SchemaObject): boolean;
11
12
  export declare function isObjectSchema(schema: OpenAPIV3.SchemaObject): boolean;
12
13
  export declare function isScalarSchema(schema: OpenAPIV3.SchemaObject): boolean;
@@ -23,7 +24,10 @@ export declare function hasDiscriminator(schema: OpenAPIV3.SchemaObject): boolea
23
24
  export declare function mapScalarType(schema: OpenAPIV3.SchemaObject): ScalarType['type'];
24
25
  /**
25
26
  * Extracts the type name from a $ref string
26
- * e.g., "#/components/schemas/User" -> "User"
27
+ * Handles both internal refs and external file refs:
28
+ * - "#/components/schemas/User" -> "User"
29
+ * - "./schemas/User.yaml#/User" -> "User"
30
+ * - "../../path/to/File.yaml#TypeName" -> "TypeName"
27
31
  */
28
32
  export declare function getRefTypeName(ref: string): string;
29
33
  /**
@@ -35,3 +39,13 @@ export declare function coerceValueByType(value: unknown, type: ScalarType['type
35
39
  * Throws an error if non-scalar values (objects/arrays) are found.
36
40
  */
37
41
  export declare function getEnumValues(schema: OpenAPIV3.SchemaObject, schemaName?: string): Array<string | number | boolean | null>;
42
+ export declare function isReferencePath(obj: OpenAPIV3.PathItemObject): obj is OpenAPIV3.PathItemObject & {
43
+ $ref: string;
44
+ };
45
+ /**
46
+ * Extracts root-level schemas from a file.
47
+ * External schema files may define schemas at the root level (not under components/schemas).
48
+ * This function identifies such schemas by excluding known OpenAPI document properties
49
+ * and checking for schema-specific properties.
50
+ */
51
+ export declare function extractRootLevelSchemas(file: OpenAPIV3.Document): Record<string, OpenAPISchema>;
@@ -1,3 +1,4 @@
1
+ import type { Position } from '../source-position-map';
1
2
  import type { SwaggerTypeFactory } from './factory';
2
3
  import type { OpenAPIV3 } from 'openapi-types';
3
4
  import type { BaseType, Type, TypeExtensions, TypeRegistry } from '../../../types';
@@ -15,10 +16,7 @@ export declare abstract class SwaggerBaseType<T extends Type['type'], S extends
15
16
  resolved: boolean;
16
17
  abstract type: T;
17
18
  parsedExtensions: TypeExtensions;
18
- schemaPosition: {
19
- line: number;
20
- column: number;
21
- };
19
+ schemaPosition: Position;
22
20
  constructor(api: SwaggerAPI, schema: S, schemaName: string | undefined, typeRegistry: TypeRegistry<SwaggerType>, factory: SwaggerTypeFactory, logger: LoggerService, fileParserLogger: FileParserLogger, jsonPath?: string);
23
21
  resolve(): void;
24
22
  typeResolve(): void;