@contractspec/lib.contracts-transformers 1.44.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.
- package/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +3 -0
- package/dist/common/types.d.ts +159 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/common/utils.d.ts +52 -0
- package/dist/common/utils.d.ts.map +1 -0
- package/dist/common/utils.js +103 -0
- package/dist/common/utils.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/openapi/differ.d.ts +42 -0
- package/dist/openapi/differ.d.ts.map +1 -0
- package/dist/openapi/differ.js +222 -0
- package/dist/openapi/differ.js.map +1 -0
- package/dist/openapi/exporter/data-views.d.ts +38 -0
- package/dist/openapi/exporter/data-views.d.ts.map +1 -0
- package/dist/openapi/exporter/data-views.js +47 -0
- package/dist/openapi/exporter/data-views.js.map +1 -0
- package/dist/openapi/exporter/events.d.ts +28 -0
- package/dist/openapi/exporter/events.d.ts.map +1 -0
- package/dist/openapi/exporter/events.js +39 -0
- package/dist/openapi/exporter/events.js.map +1 -0
- package/dist/openapi/exporter/features.d.ts +37 -0
- package/dist/openapi/exporter/features.d.ts.map +1 -0
- package/dist/openapi/exporter/features.js +46 -0
- package/dist/openapi/exporter/features.js.map +1 -0
- package/dist/openapi/exporter/forms.d.ts +30 -0
- package/dist/openapi/exporter/forms.d.ts.map +1 -0
- package/dist/openapi/exporter/forms.js +49 -0
- package/dist/openapi/exporter/forms.js.map +1 -0
- package/dist/openapi/exporter/index.js +8 -0
- package/dist/openapi/exporter/operations.d.ts +65 -0
- package/dist/openapi/exporter/operations.d.ts.map +1 -0
- package/dist/openapi/exporter/operations.js +142 -0
- package/dist/openapi/exporter/operations.js.map +1 -0
- package/dist/openapi/exporter/presentations.d.ts +32 -0
- package/dist/openapi/exporter/presentations.d.ts.map +1 -0
- package/dist/openapi/exporter/presentations.js +60 -0
- package/dist/openapi/exporter/presentations.js.map +1 -0
- package/dist/openapi/exporter/registries.d.ts +23 -0
- package/dist/openapi/exporter/registries.d.ts.map +1 -0
- package/dist/openapi/exporter/registries.js +29 -0
- package/dist/openapi/exporter/registries.js.map +1 -0
- package/dist/openapi/exporter/workflows.d.ts +36 -0
- package/dist/openapi/exporter/workflows.d.ts.map +1 -0
- package/dist/openapi/exporter/workflows.js +54 -0
- package/dist/openapi/exporter/workflows.js.map +1 -0
- package/dist/openapi/exporter.d.ts +48 -0
- package/dist/openapi/exporter.d.ts.map +1 -0
- package/dist/openapi/exporter.js +122 -0
- package/dist/openapi/exporter.js.map +1 -0
- package/dist/openapi/importer/analyzer.js +28 -0
- package/dist/openapi/importer/analyzer.js.map +1 -0
- package/dist/openapi/importer/events.js +40 -0
- package/dist/openapi/importer/events.js.map +1 -0
- package/dist/openapi/importer/generator.js +105 -0
- package/dist/openapi/importer/generator.js.map +1 -0
- package/dist/openapi/importer/grouping.js +73 -0
- package/dist/openapi/importer/grouping.js.map +1 -0
- package/dist/openapi/importer/index.d.ts +17 -0
- package/dist/openapi/importer/index.d.ts.map +1 -0
- package/dist/openapi/importer/index.js +175 -0
- package/dist/openapi/importer/index.js.map +1 -0
- package/dist/openapi/importer/models.js +22 -0
- package/dist/openapi/importer/models.js.map +1 -0
- package/dist/openapi/importer/schemas.js +60 -0
- package/dist/openapi/importer/schemas.js.map +1 -0
- package/dist/openapi/index.d.ts +16 -0
- package/dist/openapi/index.js +18 -0
- package/dist/openapi/parser/document.d.ts +20 -0
- package/dist/openapi/parser/document.d.ts.map +1 -0
- package/dist/openapi/parser/document.js +95 -0
- package/dist/openapi/parser/document.js.map +1 -0
- package/dist/openapi/parser/index.js +5 -0
- package/dist/openapi/parser/operation.js +59 -0
- package/dist/openapi/parser/operation.js.map +1 -0
- package/dist/openapi/parser/parameters.js +37 -0
- package/dist/openapi/parser/parameters.js.map +1 -0
- package/dist/openapi/parser/resolvers.js +63 -0
- package/dist/openapi/parser/resolvers.js.map +1 -0
- package/dist/openapi/parser/utils.d.ts +19 -0
- package/dist/openapi/parser/utils.d.ts.map +1 -0
- package/dist/openapi/parser/utils.js +48 -0
- package/dist/openapi/parser/utils.js.map +1 -0
- package/dist/openapi/parser.js +6 -0
- package/dist/openapi/schema-converter.d.ts +71 -0
- package/dist/openapi/schema-converter.d.ts.map +1 -0
- package/dist/openapi/schema-converter.js +161 -0
- package/dist/openapi/schema-converter.js.map +1 -0
- package/dist/openapi/schema-generators/index.js +462 -0
- package/dist/openapi/schema-generators/index.js.map +1 -0
- package/dist/openapi/types.d.ts +277 -0
- package/dist/openapi/types.d.ts.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { OpenApiSchema } from "./types.js";
|
|
2
|
+
import { ContractsrcConfig, SchemaFormat } from "@contractspec/lib.contracts";
|
|
3
|
+
|
|
4
|
+
//#region src/openapi/schema-converter.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript type representation for code generation.
|
|
8
|
+
*/
|
|
9
|
+
interface TypescriptType {
|
|
10
|
+
/** The type expression (e.g., "string", "number", "MyModel") */
|
|
11
|
+
type: string;
|
|
12
|
+
/** Whether the type is optional */
|
|
13
|
+
optional: boolean;
|
|
14
|
+
/** Whether the type is an array */
|
|
15
|
+
array: boolean;
|
|
16
|
+
/** Whether this is a primitive type */
|
|
17
|
+
primitive: boolean;
|
|
18
|
+
/** Description for documentation */
|
|
19
|
+
description?: string;
|
|
20
|
+
/** Whether this type is a reference to another schema (needs import) vs inline */
|
|
21
|
+
isReference?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SchemaModel field representation for code generation.
|
|
25
|
+
*/
|
|
26
|
+
interface SchemaField {
|
|
27
|
+
/** Field name */
|
|
28
|
+
name: string;
|
|
29
|
+
/** Field type */
|
|
30
|
+
type: TypescriptType;
|
|
31
|
+
/** Scalar type enum value (for FieldType) */
|
|
32
|
+
scalarType?: string;
|
|
33
|
+
/** Enum values if this is an enum type */
|
|
34
|
+
enumValues?: string[];
|
|
35
|
+
/** Nested model if this is an object type */
|
|
36
|
+
nestedModel?: GeneratedModel;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generated model representation.
|
|
40
|
+
*/
|
|
41
|
+
interface GeneratedModel {
|
|
42
|
+
/** Model name (PascalCase) */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Model description */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** Fields */
|
|
47
|
+
fields: SchemaField[];
|
|
48
|
+
/** Generated TypeScript code */
|
|
49
|
+
code: string;
|
|
50
|
+
/** Required imports */
|
|
51
|
+
imports?: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Convert a JSON Schema to a TypeScript type representation.
|
|
55
|
+
*/
|
|
56
|
+
declare function jsonSchemaToType(schema: OpenApiSchema, name?: string): TypescriptType;
|
|
57
|
+
/**
|
|
58
|
+
* Get the ScalarTypeEnum value for a JSON Schema type.
|
|
59
|
+
*/
|
|
60
|
+
declare function getScalarType(schema: OpenApiSchema): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Generate code for a schema model using the specified format.
|
|
63
|
+
*/
|
|
64
|
+
declare function generateSchemaModelCode(schema: OpenApiSchema, modelName: string, schemaFormat?: SchemaFormat, config?: ContractsrcConfig): GeneratedModel;
|
|
65
|
+
/**
|
|
66
|
+
* Generate import statements for a SchemaModel.
|
|
67
|
+
*/
|
|
68
|
+
declare function generateImports(fields: SchemaField[], options: ContractsrcConfig, sameDirectory?: boolean): string;
|
|
69
|
+
//#endregion
|
|
70
|
+
export { GeneratedModel, SchemaField, TypescriptType, generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToType };
|
|
71
|
+
//# sourceMappingURL=schema-converter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-converter.d.ts","names":[],"sources":["../../src/openapi/schema-converter.ts"],"sourcesContent":[],"mappings":";;;;;AAkEA;AA+BA;AAiHA;AA2BgB,UA7MC,cAAA,CA6MsB;EAC7B;EAEM,IAAA,EAAA,MAAA;EACL;EACR,QAAA,EAAA,OAAA;EAAc;EAkBD,KAAA,EAAA,OAAA;;;;;;;;;;;UAlNC,WAAA;;;;QAIT;;;;;;gBAMQ;;;;;UAMC,cAAA;;;;;;UAMP;;;;;;;;;iBAyBM,gBAAA,SACN,+BAEP;;;;iBA8Ga,aAAA,SAAsB;;;;iBA2BtB,uBAAA,SACN,iDAEM,uBACL,oBACR;;;;iBAkBa,eAAA,SACN,wBACC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { toPascalCase } from "../common/utils.js";
|
|
2
|
+
import { createSchemaGenerator } from "./schema-generators/index.js";
|
|
3
|
+
|
|
4
|
+
//#region src/openapi/schema-converter.ts
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema to SchemaModel conversion utilities.
|
|
7
|
+
* Converts OpenAPI JSON Schema to ContractSpec SchemaModel definitions.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Map JSON Schema types to ContractSpec ScalarTypeEnum values.
|
|
11
|
+
*/
|
|
12
|
+
const JSON_SCHEMA_TO_SCALAR = {
|
|
13
|
+
string: "ScalarTypeEnum.String_unsecure",
|
|
14
|
+
integer: "ScalarTypeEnum.Int_unsecure",
|
|
15
|
+
number: "ScalarTypeEnum.Float_unsecure",
|
|
16
|
+
boolean: "ScalarTypeEnum.Boolean",
|
|
17
|
+
"string:date": "ScalarTypeEnum.Date",
|
|
18
|
+
"string:date-time": "ScalarTypeEnum.DateTime",
|
|
19
|
+
"string:email": "ScalarTypeEnum.EmailAddress",
|
|
20
|
+
"string:uri": "ScalarTypeEnum.URL",
|
|
21
|
+
"string:uuid": "ScalarTypeEnum.ID"
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Check if a schema is a reference object.
|
|
25
|
+
*/
|
|
26
|
+
function isReference(schema) {
|
|
27
|
+
return typeof schema === "object" && schema !== null && "$ref" in schema;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract type name from a $ref.
|
|
31
|
+
*/
|
|
32
|
+
function typeNameFromRef(ref) {
|
|
33
|
+
const parts = ref.split("/");
|
|
34
|
+
return parts[parts.length - 1] ?? "Unknown";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Convert a JSON Schema to a TypeScript type representation.
|
|
38
|
+
*/
|
|
39
|
+
function jsonSchemaToType(schema, name) {
|
|
40
|
+
if (isReference(schema)) return {
|
|
41
|
+
type: toPascalCase(typeNameFromRef(schema.$ref)),
|
|
42
|
+
optional: false,
|
|
43
|
+
array: false,
|
|
44
|
+
primitive: false,
|
|
45
|
+
isReference: true
|
|
46
|
+
};
|
|
47
|
+
const schemaObj = schema;
|
|
48
|
+
const type = schemaObj["type"];
|
|
49
|
+
const format = schemaObj["format"];
|
|
50
|
+
const nullable = schemaObj["nullable"];
|
|
51
|
+
const originalTypeName = schemaObj["_originalTypeName"];
|
|
52
|
+
if (originalTypeName) return {
|
|
53
|
+
type: toPascalCase(originalTypeName),
|
|
54
|
+
optional: nullable ?? false,
|
|
55
|
+
array: false,
|
|
56
|
+
primitive: false,
|
|
57
|
+
isReference: true
|
|
58
|
+
};
|
|
59
|
+
if (type === "array") {
|
|
60
|
+
const items = schemaObj["items"];
|
|
61
|
+
if (items) return {
|
|
62
|
+
...jsonSchemaToType(items, name),
|
|
63
|
+
array: true,
|
|
64
|
+
optional: nullable ?? false
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
type: "unknown",
|
|
68
|
+
optional: nullable ?? false,
|
|
69
|
+
array: true,
|
|
70
|
+
primitive: false,
|
|
71
|
+
isReference: true
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (type === "object" || schemaObj["properties"]) return {
|
|
75
|
+
type: name ? toPascalCase(name) : "Record<string, unknown>",
|
|
76
|
+
optional: nullable ?? false,
|
|
77
|
+
array: false,
|
|
78
|
+
primitive: false,
|
|
79
|
+
isReference: true
|
|
80
|
+
};
|
|
81
|
+
if (schemaObj["enum"]) return {
|
|
82
|
+
type: name ? toPascalCase(name) : "string",
|
|
83
|
+
optional: nullable ?? false,
|
|
84
|
+
array: false,
|
|
85
|
+
primitive: false,
|
|
86
|
+
isReference: true
|
|
87
|
+
};
|
|
88
|
+
const scalarKey = format ? `${type}:${format}` : type;
|
|
89
|
+
if (scalarKey === "string") return {
|
|
90
|
+
type: "string",
|
|
91
|
+
optional: nullable ?? false,
|
|
92
|
+
array: false,
|
|
93
|
+
primitive: true
|
|
94
|
+
};
|
|
95
|
+
if (scalarKey === "integer" || type === "number") return {
|
|
96
|
+
type: "number",
|
|
97
|
+
optional: nullable ?? false,
|
|
98
|
+
array: false,
|
|
99
|
+
primitive: true
|
|
100
|
+
};
|
|
101
|
+
if (scalarKey === "boolean") return {
|
|
102
|
+
type: "boolean",
|
|
103
|
+
optional: nullable ?? false,
|
|
104
|
+
array: false,
|
|
105
|
+
primitive: true
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
type: "unknown",
|
|
109
|
+
optional: nullable ?? false,
|
|
110
|
+
array: false,
|
|
111
|
+
primitive: false,
|
|
112
|
+
isReference: true
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get the ScalarTypeEnum value for a JSON Schema type.
|
|
117
|
+
*/
|
|
118
|
+
function getScalarType(schema) {
|
|
119
|
+
if (isReference(schema)) return;
|
|
120
|
+
const schemaObj = schema;
|
|
121
|
+
const type = schemaObj["type"];
|
|
122
|
+
const format = schemaObj["format"];
|
|
123
|
+
if (!type) return void 0;
|
|
124
|
+
if (type === "array") {
|
|
125
|
+
const items = schemaObj["items"];
|
|
126
|
+
if (items) return getScalarType(items);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
return JSON_SCHEMA_TO_SCALAR[format ? `${type}:${format}` : type] ?? JSON_SCHEMA_TO_SCALAR[type] ?? void 0;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Generate code for a schema model using the specified format.
|
|
133
|
+
*/
|
|
134
|
+
function generateSchemaModelCode(schema, modelName, schemaFormat = "contractspec", config) {
|
|
135
|
+
const result = createSchemaGenerator(schemaFormat, config).generateModel(schema, modelName, { description: schema["description"] });
|
|
136
|
+
return {
|
|
137
|
+
name: result.name,
|
|
138
|
+
description: schema["description"],
|
|
139
|
+
fields: [],
|
|
140
|
+
code: result.code,
|
|
141
|
+
imports: result.imports
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Generate import statements for a SchemaModel.
|
|
146
|
+
*/
|
|
147
|
+
function generateImports(fields, options, sameDirectory = true) {
|
|
148
|
+
const imports = /* @__PURE__ */ new Set();
|
|
149
|
+
const modelsDir = sameDirectory ? "." : `../${options.conventions.models}`;
|
|
150
|
+
imports.add("import { defineSchemaModel, ScalarTypeEnum, EnumType } from '@contractspec/lib.schema';");
|
|
151
|
+
for (const field of fields) if (field.type.isReference && !field.type.primitive && !field.enumValues && !field.scalarType && !field.nestedModel) {
|
|
152
|
+
const modelName = field.type.type;
|
|
153
|
+
const kebabName = modelName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
154
|
+
imports.add(`import { ${modelName} } from '${modelsDir}/${kebabName}';`);
|
|
155
|
+
}
|
|
156
|
+
return Array.from(imports).join("\n");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
export { generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToType };
|
|
161
|
+
//# sourceMappingURL=schema-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-converter.js","names":["JSON_SCHEMA_TO_SCALAR: Record<string, string>"],"sources":["../../src/openapi/schema-converter.ts"],"sourcesContent":["/**\n * JSON Schema to SchemaModel conversion utilities.\n * Converts OpenAPI JSON Schema to ContractSpec SchemaModel definitions.\n */\n\nimport { createSchemaGenerator } from './schema-generators';\nimport type {\n SchemaFormat,\n ContractsrcConfig,\n} from '@contractspec/lib.contracts';\nimport type { OpenApiSchema } from './types';\nimport { toPascalCase } from '../common/utils';\n\n/**\n * Map JSON Schema types to ContractSpec ScalarTypeEnum values.\n */\nconst JSON_SCHEMA_TO_SCALAR: Record<string, string> = {\n string: 'ScalarTypeEnum.String_unsecure',\n integer: 'ScalarTypeEnum.Int_unsecure',\n number: 'ScalarTypeEnum.Float_unsecure',\n boolean: 'ScalarTypeEnum.Boolean',\n // Special formats\n 'string:date': 'ScalarTypeEnum.Date',\n 'string:date-time': 'ScalarTypeEnum.DateTime',\n 'string:email': 'ScalarTypeEnum.EmailAddress',\n 'string:uri': 'ScalarTypeEnum.URL',\n 'string:uuid': 'ScalarTypeEnum.ID',\n};\n\n/**\n * TypeScript type representation for code generation.\n */\nexport interface TypescriptType {\n /** The type expression (e.g., \"string\", \"number\", \"MyModel\") */\n type: string;\n /** Whether the type is optional */\n optional: boolean;\n /** Whether the type is an array */\n array: boolean;\n /** Whether this is a primitive type */\n primitive: boolean;\n /** Description for documentation */\n description?: string;\n /** Whether this type is a reference to another schema (needs import) vs inline */\n isReference?: boolean;\n}\n\n/**\n * SchemaModel field representation for code generation.\n */\nexport interface SchemaField {\n /** Field name */\n name: string;\n /** Field type */\n type: TypescriptType;\n /** Scalar type enum value (for FieldType) */\n scalarType?: string;\n /** Enum values if this is an enum type */\n enumValues?: string[];\n /** Nested model if this is an object type */\n nestedModel?: GeneratedModel;\n}\n\n/**\n * Generated model representation.\n */\nexport interface GeneratedModel {\n /** Model name (PascalCase) */\n name: string;\n /** Model description */\n description?: string;\n /** Fields */\n fields: SchemaField[];\n /** Generated TypeScript code */\n code: string;\n /** Required imports */\n imports?: string[];\n}\n\n/**\n * Check if a schema is a reference object.\n */\nfunction isReference(schema: OpenApiSchema): schema is { $ref: string } {\n return typeof schema === 'object' && schema !== null && '$ref' in schema;\n}\n\n/**\n * Extract type name from a $ref.\n */\nfunction typeNameFromRef(ref: string): string {\n const parts = ref.split('/');\n return parts[parts.length - 1] ?? 'Unknown';\n}\n\n/**\n * Convert a JSON Schema to a TypeScript type representation.\n */\nexport function jsonSchemaToType(\n schema: OpenApiSchema,\n name?: string\n): TypescriptType {\n if (isReference(schema)) {\n return {\n type: toPascalCase(typeNameFromRef(schema.$ref)),\n optional: false,\n array: false,\n primitive: false,\n isReference: true,\n };\n }\n\n const schemaObj = schema as Record<string, unknown>;\n const type = schemaObj['type'] as string | undefined;\n const format = schemaObj['format'] as string | undefined;\n const nullable = schemaObj['nullable'] as boolean | undefined;\n\n // Check if this schema was dereferenced from a $ref - use the original type name\n const originalTypeName = schemaObj['_originalTypeName'] as string | undefined;\n if (originalTypeName) {\n return {\n type: toPascalCase(originalTypeName),\n optional: nullable ?? false,\n array: false,\n primitive: false,\n isReference: true,\n };\n }\n\n // Handle arrays\n if (type === 'array') {\n const items = schemaObj['items'] as OpenApiSchema | undefined;\n if (items) {\n const itemType = jsonSchemaToType(items, name);\n return {\n ...itemType,\n array: true,\n optional: nullable ?? false,\n };\n }\n return {\n type: 'unknown',\n optional: nullable ?? false,\n array: true,\n primitive: false,\n isReference: true,\n };\n }\n\n // Handle objects\n if (type === 'object' || schemaObj['properties']) {\n return {\n type: name ? toPascalCase(name) : 'Record<string, unknown>',\n optional: nullable ?? false,\n array: false,\n primitive: false,\n isReference: true,\n };\n }\n\n // Handle enums\n if (schemaObj['enum']) {\n return {\n type: name ? toPascalCase(name) : 'string',\n optional: nullable ?? false,\n array: false,\n primitive: false,\n isReference: true,\n };\n }\n\n // Handle primitives\n const scalarKey = format ? `${type}:${format}` : type;\n if (scalarKey === 'string') {\n return {\n type: 'string',\n optional: nullable ?? false,\n array: false,\n primitive: true,\n };\n }\n if (scalarKey === 'integer' || type === 'number') {\n return {\n type: 'number',\n optional: nullable ?? false,\n array: false,\n primitive: true,\n };\n }\n if (scalarKey === 'boolean') {\n return {\n type: 'boolean',\n optional: nullable ?? false,\n array: false,\n primitive: true,\n };\n }\n\n // Default to unknown\n return {\n type: 'unknown',\n optional: nullable ?? false,\n array: false,\n primitive: false,\n isReference: true,\n };\n}\n\n/**\n * Get the ScalarTypeEnum value for a JSON Schema type.\n */\nexport function getScalarType(schema: OpenApiSchema): string | undefined {\n if (isReference(schema)) {\n return undefined;\n }\n\n const schemaObj = schema as Record<string, unknown>;\n const type = schemaObj['type'] as string | undefined;\n const format = schemaObj['format'] as string | undefined;\n\n if (!type) return undefined;\n\n // For arrays, get the scalar type of the items\n if (type === 'array') {\n const items = schemaObj['items'] as OpenApiSchema | undefined;\n if (items) {\n return getScalarType(items);\n }\n return undefined;\n }\n\n const key = format ? `${type}:${format}` : type;\n return JSON_SCHEMA_TO_SCALAR[key] ?? JSON_SCHEMA_TO_SCALAR[type] ?? undefined;\n}\n\n/**\n * Generate code for a schema model using the specified format.\n */\nexport function generateSchemaModelCode(\n schema: OpenApiSchema,\n modelName: string,\n schemaFormat: SchemaFormat = 'contractspec',\n config?: ContractsrcConfig\n): GeneratedModel {\n const generator = createSchemaGenerator(schemaFormat, config);\n const result = generator.generateModel(schema, modelName, {\n description: (schema as Record<string, unknown>)['description'] as string,\n });\n\n return {\n name: result.name,\n description: (schema as Record<string, unknown>)['description'] as string,\n fields: [], // fields are processed internally by generators now\n code: result.code,\n imports: result.imports,\n };\n}\n\n/**\n * Generate import statements for a SchemaModel.\n */\nexport function generateImports(\n fields: SchemaField[],\n options: ContractsrcConfig,\n sameDirectory = true\n): string {\n const imports = new Set<string>();\n const modelsDir = sameDirectory ? '.' : `../${options.conventions.models}`;\n\n imports.add(\n \"import { defineSchemaModel, ScalarTypeEnum, EnumType } from '@contractspec/lib.schema';\"\n );\n\n for (const field of fields) {\n // Only import fields that are actual references to other schemas (not inline types)\n if (\n field.type.isReference &&\n !field.type.primitive &&\n !field.enumValues &&\n !field.scalarType &&\n !field.nestedModel\n ) {\n // This is a reference to another schema model\n const modelName = field.type.type;\n const kebabName = modelName\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .toLowerCase();\n imports.add(`import { ${modelName} } from '${modelsDir}/${kebabName}';`);\n }\n }\n\n return Array.from(imports).join('\\n');\n}\n"],"mappings":"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"}
|