@cerios/xml-poto-codegen
Advanced tools
+16
-4
@@ -18,2 +18,4 @@ /** | ||
| enumStyle?: EnumStyle; | ||
| /** Whether to emit @XmlRoot for root elements. When false, @XmlElement is used instead. Overrides the global setting. */ | ||
| useXmlRoot?: boolean; | ||
| } | ||
@@ -30,2 +32,4 @@ /** | ||
| enumStyle?: EnumStyle; | ||
| /** Whether to emit @XmlRoot for root elements. When false, @XmlElement is used instead. Defaults to true. */ | ||
| useXmlRoot?: boolean; | ||
| } | ||
@@ -257,2 +261,4 @@ | ||
| rootNillable?: boolean; | ||
| /** Namespace form (qualified/unqualified) */ | ||
| form?: "qualified" | "unqualified"; | ||
| } | ||
@@ -368,2 +374,8 @@ type PropertyKind = "element" | "attribute" | "text" | "array" | "dynamic"; | ||
| interface ClassGeneratorOptions { | ||
| xsdPath: string; | ||
| enumStyle?: EnumStyle; | ||
| useXmlRoot?: boolean; | ||
| elementFormDefault?: "qualified" | "unqualified"; | ||
| } | ||
| interface GeneratedFile { | ||
@@ -384,6 +396,5 @@ /** Filename (without directory) */ | ||
| private enumStyle; | ||
| constructor(options: { | ||
| xsdPath: string; | ||
| enumStyle?: EnumStyle; | ||
| }); | ||
| private useXmlRoot; | ||
| private elementFormDefault?; | ||
| constructor(options: ClassGeneratorOptions); | ||
| /** | ||
@@ -457,2 +468,3 @@ * Generate files in 'per-type' mode: one file per class/enum + barrel index. | ||
| parseString(xsdContent: string, baseDir?: string): XsdSchema; | ||
| private resolveExternalSchemas; | ||
| private findSchemaRootKey; | ||
@@ -459,0 +471,0 @@ private detectXsdPrefix; |
+16
-4
@@ -18,2 +18,4 @@ /** | ||
| enumStyle?: EnumStyle; | ||
| /** Whether to emit @XmlRoot for root elements. When false, @XmlElement is used instead. Overrides the global setting. */ | ||
| useXmlRoot?: boolean; | ||
| } | ||
@@ -30,2 +32,4 @@ /** | ||
| enumStyle?: EnumStyle; | ||
| /** Whether to emit @XmlRoot for root elements. When false, @XmlElement is used instead. Defaults to true. */ | ||
| useXmlRoot?: boolean; | ||
| } | ||
@@ -257,2 +261,4 @@ | ||
| rootNillable?: boolean; | ||
| /** Namespace form (qualified/unqualified) */ | ||
| form?: "qualified" | "unqualified"; | ||
| } | ||
@@ -368,2 +374,8 @@ type PropertyKind = "element" | "attribute" | "text" | "array" | "dynamic"; | ||
| interface ClassGeneratorOptions { | ||
| xsdPath: string; | ||
| enumStyle?: EnumStyle; | ||
| useXmlRoot?: boolean; | ||
| elementFormDefault?: "qualified" | "unqualified"; | ||
| } | ||
| interface GeneratedFile { | ||
@@ -384,6 +396,5 @@ /** Filename (without directory) */ | ||
| private enumStyle; | ||
| constructor(options: { | ||
| xsdPath: string; | ||
| enumStyle?: EnumStyle; | ||
| }); | ||
| private useXmlRoot; | ||
| private elementFormDefault?; | ||
| constructor(options: ClassGeneratorOptions); | ||
| /** | ||
@@ -457,2 +468,3 @@ * Generate files in 'per-type' mode: one file per class/enum + barrel index. | ||
| parseString(xsdContent: string, baseDir?: string): XsdSchema; | ||
| private resolveExternalSchemas; | ||
| private findSchemaRootKey; | ||
@@ -459,0 +471,0 @@ private detectXsdPrefix; |
+49
-21
@@ -76,2 +76,5 @@ "use strict"; | ||
| } | ||
| if (cfg.useXmlRoot !== void 0 && typeof cfg.useXmlRoot !== "boolean") { | ||
| throw new Error("useXmlRoot must be a boolean."); | ||
| } | ||
| return config; | ||
@@ -96,2 +99,5 @@ } | ||
| } | ||
| if (src.useXmlRoot !== void 0 && typeof src.useXmlRoot !== "boolean") { | ||
| throw new Error(`sources[${index}].useXmlRoot must be a boolean.`); | ||
| } | ||
| } | ||
@@ -222,2 +228,8 @@ function isValidOutputStyle(value) { | ||
| } | ||
| if (type.rootNillable) { | ||
| opts.isNullable = true; | ||
| } | ||
| if (type.form) { | ||
| opts.form = `'${type.form}'`; | ||
| } | ||
| return buildDecorator("XmlElement", opts); | ||
@@ -305,2 +317,3 @@ } | ||
| if (prop.isNullable) opts.isNullable = true; | ||
| if (prop.form) opts.form = `'${prop.form}'`; | ||
| if (prop.namespace) opts.namespace = buildNamespaceObj(prop.namespace); | ||
@@ -335,5 +348,7 @@ if (prop.dataType) opts.dataType = `'${prop.dataType}'`; | ||
| this.importPath = "@cerios/xml-poto"; | ||
| var _a; | ||
| var _a, _b; | ||
| this.xsdPath = options.xsdPath; | ||
| this.enumStyle = (_a = options.enumStyle) != null ? _a : "union"; | ||
| this.useXmlRoot = (_b = options.useXmlRoot) != null ? _b : true; | ||
| this.elementFormDefault = options.elementFormDefault; | ||
| } | ||
@@ -515,2 +530,7 @@ /** | ||
| applyRootElements(types, rootElements) { | ||
| if (!this.useXmlRoot) { | ||
| return types.map( | ||
| (type) => type.isRootElement ? { ...type, isRootElement: false, form: this.elementFormDefault } : type | ||
| ); | ||
| } | ||
| if (rootElements.length === 0) { | ||
@@ -614,3 +634,9 @@ return types; | ||
| parseString(xsdContent, baseDir) { | ||
| const parsed = this.parser.parse(xsdContent); | ||
| const normalized = xsdContent.replace(/<\?xml[^?]*\?>/i, "").replace(/<!--[\s\S]*?-->/g, "").trim(); | ||
| if (!/^<(?:[a-zA-Z_][\w.-]*:)?schema[\s/>]/i.test(normalized)) { | ||
| throw new Error( | ||
| "The provided content does not appear to be a valid XSD schema. Expected a root <xs:schema>, <xsd:schema>, or <schema> element." | ||
| ); | ||
| } | ||
| const parsed = this.parser.parse(normalized); | ||
| const rootKey = this.findSchemaRootKey(parsed); | ||
@@ -624,22 +650,25 @@ if (!rootKey) { | ||
| if (baseDir) { | ||
| for (const inc of schema.includes) { | ||
| if (inc.schemaLocation) { | ||
| const incPath = import_node_path3.default.resolve(baseDir, inc.schemaLocation); | ||
| if (import_node_fs3.default.existsSync(incPath)) { | ||
| const included = this.parseFile(incPath); | ||
| this.mergeSchema(schema, included); | ||
| } | ||
| this.resolveExternalSchemas(schema, baseDir); | ||
| } | ||
| return schema; | ||
| } | ||
| resolveExternalSchemas(schema, baseDir) { | ||
| for (const inc of schema.includes) { | ||
| if (inc.schemaLocation) { | ||
| const incPath = import_node_path3.default.resolve(baseDir, inc.schemaLocation); | ||
| if (import_node_fs3.default.existsSync(incPath)) { | ||
| this.mergeSchema(schema, this.parseFile(incPath)); | ||
| } | ||
| } | ||
| for (const imp of schema.imports) { | ||
| if (imp.schemaLocation) { | ||
| const impPath = import_node_path3.default.resolve(baseDir, imp.schemaLocation); | ||
| if (import_node_fs3.default.existsSync(impPath)) { | ||
| const imported = this.parseFile(impPath); | ||
| this.mergeSchema(schema, imported); | ||
| if (imp.namespace && imported.targetNamespace) { | ||
| for (const [prefix, uri] of imported.namespaces) { | ||
| if (uri === imported.targetNamespace && prefix !== "" && !schema.namespaces.has(prefix)) { | ||
| schema.namespaces.set(prefix, uri); | ||
| } | ||
| } | ||
| for (const imp of schema.imports) { | ||
| if (imp.schemaLocation) { | ||
| const impPath = import_node_path3.default.resolve(baseDir, imp.schemaLocation); | ||
| if (import_node_fs3.default.existsSync(impPath)) { | ||
| const imported = this.parseFile(impPath); | ||
| this.mergeSchema(schema, imported); | ||
| if (imp.namespace && imported.targetNamespace) { | ||
| for (const [prefix, uri] of imported.namespaces) { | ||
| if (uri === imported.targetNamespace && prefix !== "" && !schema.namespaces.has(prefix)) { | ||
| schema.namespaces.set(prefix, uri); | ||
| } | ||
@@ -651,3 +680,2 @@ } | ||
| } | ||
| return schema; | ||
| } | ||
@@ -654,0 +682,0 @@ findSchemaRootKey(parsed) { |
+49
-21
@@ -23,2 +23,5 @@ // src/config/config-loader.ts | ||
| } | ||
| if (cfg.useXmlRoot !== void 0 && typeof cfg.useXmlRoot !== "boolean") { | ||
| throw new Error("useXmlRoot must be a boolean."); | ||
| } | ||
| return config; | ||
@@ -43,2 +46,5 @@ } | ||
| } | ||
| if (src.useXmlRoot !== void 0 && typeof src.useXmlRoot !== "boolean") { | ||
| throw new Error(`sources[${index}].useXmlRoot must be a boolean.`); | ||
| } | ||
| } | ||
@@ -169,2 +175,8 @@ function isValidOutputStyle(value) { | ||
| } | ||
| if (type.rootNillable) { | ||
| opts.isNullable = true; | ||
| } | ||
| if (type.form) { | ||
| opts.form = `'${type.form}'`; | ||
| } | ||
| return buildDecorator("XmlElement", opts); | ||
@@ -252,2 +264,3 @@ } | ||
| if (prop.isNullable) opts.isNullable = true; | ||
| if (prop.form) opts.form = `'${prop.form}'`; | ||
| if (prop.namespace) opts.namespace = buildNamespaceObj(prop.namespace); | ||
@@ -282,5 +295,7 @@ if (prop.dataType) opts.dataType = `'${prop.dataType}'`; | ||
| this.importPath = "@cerios/xml-poto"; | ||
| var _a; | ||
| var _a, _b; | ||
| this.xsdPath = options.xsdPath; | ||
| this.enumStyle = (_a = options.enumStyle) != null ? _a : "union"; | ||
| this.useXmlRoot = (_b = options.useXmlRoot) != null ? _b : true; | ||
| this.elementFormDefault = options.elementFormDefault; | ||
| } | ||
@@ -462,2 +477,7 @@ /** | ||
| applyRootElements(types, rootElements) { | ||
| if (!this.useXmlRoot) { | ||
| return types.map( | ||
| (type) => type.isRootElement ? { ...type, isRootElement: false, form: this.elementFormDefault } : type | ||
| ); | ||
| } | ||
| if (rootElements.length === 0) { | ||
@@ -561,3 +581,9 @@ return types; | ||
| parseString(xsdContent, baseDir) { | ||
| const parsed = this.parser.parse(xsdContent); | ||
| const normalized = xsdContent.replace(/<\?xml[^?]*\?>/i, "").replace(/<!--[\s\S]*?-->/g, "").trim(); | ||
| if (!/^<(?:[a-zA-Z_][\w.-]*:)?schema[\s/>]/i.test(normalized)) { | ||
| throw new Error( | ||
| "The provided content does not appear to be a valid XSD schema. Expected a root <xs:schema>, <xsd:schema>, or <schema> element." | ||
| ); | ||
| } | ||
| const parsed = this.parser.parse(normalized); | ||
| const rootKey = this.findSchemaRootKey(parsed); | ||
@@ -571,22 +597,25 @@ if (!rootKey) { | ||
| if (baseDir) { | ||
| for (const inc of schema.includes) { | ||
| if (inc.schemaLocation) { | ||
| const incPath = path3.resolve(baseDir, inc.schemaLocation); | ||
| if (fs3.existsSync(incPath)) { | ||
| const included = this.parseFile(incPath); | ||
| this.mergeSchema(schema, included); | ||
| } | ||
| this.resolveExternalSchemas(schema, baseDir); | ||
| } | ||
| return schema; | ||
| } | ||
| resolveExternalSchemas(schema, baseDir) { | ||
| for (const inc of schema.includes) { | ||
| if (inc.schemaLocation) { | ||
| const incPath = path3.resolve(baseDir, inc.schemaLocation); | ||
| if (fs3.existsSync(incPath)) { | ||
| this.mergeSchema(schema, this.parseFile(incPath)); | ||
| } | ||
| } | ||
| for (const imp of schema.imports) { | ||
| if (imp.schemaLocation) { | ||
| const impPath = path3.resolve(baseDir, imp.schemaLocation); | ||
| if (fs3.existsSync(impPath)) { | ||
| const imported = this.parseFile(impPath); | ||
| this.mergeSchema(schema, imported); | ||
| if (imp.namespace && imported.targetNamespace) { | ||
| for (const [prefix, uri] of imported.namespaces) { | ||
| if (uri === imported.targetNamespace && prefix !== "" && !schema.namespaces.has(prefix)) { | ||
| schema.namespaces.set(prefix, uri); | ||
| } | ||
| } | ||
| for (const imp of schema.imports) { | ||
| if (imp.schemaLocation) { | ||
| const impPath = path3.resolve(baseDir, imp.schemaLocation); | ||
| if (fs3.existsSync(impPath)) { | ||
| const imported = this.parseFile(impPath); | ||
| this.mergeSchema(schema, imported); | ||
| if (imp.namespace && imported.targetNamespace) { | ||
| for (const [prefix, uri] of imported.namespaces) { | ||
| if (uri === imported.targetNamespace && prefix !== "" && !schema.namespaces.has(prefix)) { | ||
| schema.namespaces.set(prefix, uri); | ||
| } | ||
@@ -598,3 +627,2 @@ } | ||
| } | ||
| return schema; | ||
| } | ||
@@ -601,0 +629,0 @@ findSchemaRootKey(parsed) { |
+3
-3
| { | ||
| "name": "@cerios/xml-poto-codegen", | ||
| "version": "0.1.1", | ||
| "version": "1.0.0", | ||
| "description": "Generate TypeScript classes with xml-poto decorators from XSD schemas. CLI tool with config-based multi-XSD support.", | ||
@@ -63,3 +63,3 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@cerios/xml-poto": "2.1.3", | ||
| "@cerios/xml-poto": "2.2.0", | ||
| "@types/node": "^25.4.0", | ||
@@ -74,4 +74,4 @@ "oxfmt": "^0.38.0", | ||
| "peerDependencies": { | ||
| "@cerios/xml-poto": "^2.1.2" | ||
| "@cerios/xml-poto": "^2.2.0" | ||
| } | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
892519
1.89%8318
1.59%0
-100%