Skip to content

Commit

Permalink
fix: issues in nodeset2xml export
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Feb 6, 2022
1 parent a75368c commit e0786c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
4 changes: 0 additions & 4 deletions packages/node-opcua-address-space/src/namespace_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,7 @@ export class NamespaceImpl implements NamespacePrivate {
parentObject !== null && typeof parentObject === "object" && parentObject instanceof BaseNodeImpl,
"expecting a valid parent object"
);

assert(Object.prototype.hasOwnProperty.call(options, "browseName"));
assert(!Object.prototype.hasOwnProperty.call(options, "inputArguments") || Array.isArray(options.inputArguments));
assert(!Object.prototype.hasOwnProperty.call(options, "outputArguments") || Array.isArray(options.outputArguments));

options.componentOf = parentObject;

const method = this._addMethod(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ function _dumpUADataTypeDefinition(xw: XmlWriter, uaDataType: UADataType) {

if (uaDataType.isEnumeration()) {
xw.startElement("Definition");
xw.writeAttribute("Name", uaDataType.browseName.name!);
xw.writeAttribute("Name", b(xw, uaDataType.browseName));
_dumpEnumDefinition(xw, uaDataType.getEnumDefinition());
xw.endElement();
return;
Expand All @@ -802,7 +802,7 @@ function _dumpUADataTypeDefinition(xw: XmlWriter, uaDataType: UADataType) {
const definition = uaDataType.getStructureDefinition();
const baseDefinition = uaDataTypeBase ? uaDataTypeBase.getStructureDefinition() : null;
xw.startElement("Definition");
xw.writeAttribute("Name", b(xw,uaDataType.browseName));
xw.writeAttribute("Name", b(xw, uaDataType.browseName));
if (definition.structureType === StructureType.Union) {
xw.writeAttribute("IsUnion", "true");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe("testing NodeSet XML file loading", function (this: any) {
<Reference ReferenceType="HasSubtype" IsForward="false">i=29</Reference>
<Reference ReferenceType="HasProperty">ns=1;i=6450</Reference>
</References>
<Definition Name="DeviceHealthEnumeration">
<Definition Name="1:DeviceHealthEnumeration">
<Field Name="NORMAL" Value="0">
<Description>This device functions normally.</Description>
</Field>
Expand Down
21 changes: 9 additions & 12 deletions packages/node-opcua-modeler/source/generate_markdown_doc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable max-statements */
import { BaseNode, Namespace, UADataType, UAObjectType, UAReferenceType, UAVariableType } from "node-opcua-address-space";
import { coerceUInt32 } from "node-opcua-basic-types";
import { DataTypeDefinition, EnumDefinition, StructureDefinition, StructureField } from "node-opcua-types";
import { DataType } from "node-opcua-variant";
import { object } from "underscore";

import { displayNodeElement } from "./displayNodeElement";
import { TableHelper } from "./tableHelper";
import { dumpClassHierachry, graphVizToPlantUml, opcuaToDot } from "./to_graphivz";
Expand Down Expand Up @@ -46,15 +45,15 @@ function dataTypeToMarkdown(dataType: UADataType): string {
const addressSpace = dataType.addressSpace;

const writer = new Writer();
const definition: DataTypeDefinition = dataType.getDefinition();

writer.writeLine("\nisAbstract: " + (dataType.isAbstract ? "Yes" : "No"));
if (dataType.subtypeOfObj) {
writer.writeLine("\nSubtype of " + dataType.subtypeOfObj?.browseName.toString());
}
writer.writeLine("");

if (definition instanceof EnumDefinition) {
if (dataType.isEnumeration()) {
const definition = dataType.getEnumDefinition();
writer.writeLine("\nBasic Type: " + (DataType as any)[DataType.UInt32]);
writer.writeLine("");

Expand All @@ -63,7 +62,8 @@ function dataTypeToMarkdown(dataType: UADataType): string {
table.push([f.name, coerceUInt32(f.value[1]), f.description.text || ""]);
}
writer.writeLine(table.toMarkdownTable());
} else if (definition instanceof StructureDefinition) {
} else if (dataType.isStructure()) {
const definition = dataType.getStructureDefinition();
writer.writeLine("\nBasic Type: " + (DataType as any)[dataType.basicDataType]);

const table = new TableHelper(["Name", "data type", "value rank", "maxStringLength", "Dimensions", "Description"]);
Expand All @@ -76,7 +76,7 @@ function dataTypeToMarkdown(dataType: UADataType): string {
f.valueRank ? f.valueRank : "",
f.maxStringLength ? f.maxStringLength : "",
f.arrayDimensions ? f.arrayDimensions : "",
(f.description.text || "").replace(/\n/g, "<br>"),
(f.description.text || "").replace(/\n/g, "<br>")
]);
}
writer.writeLine(table.toMarkdownTable());
Expand All @@ -98,7 +98,7 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
writer.writeLine("# Namespace " + namespaceUri);
writer.writeLine("");
// -------------- writeReferences
const namespacePriv = (namespace as unknown) as NamespacePriv2;
const namespacePriv = namespace as unknown as NamespacePriv2;
writer.writeLine("");
writer.writeLine("## References ");
writer.writeLine("");
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
writer.writeLine("\n\n### " + objectType.browseName.name!.toString());
writer.writeLine(d(objectType));

writer.writeLine(graphVizToPlantUml(dumpClassHierachry(objectType, {showBaseType: true, depth: 2})));
writer.writeLine(graphVizToPlantUml(dumpClassHierachry(objectType, { showBaseType: true, depth: 2 })));

writer.writeLine(graphVizToPlantUml(opcuaToDot(objectType)));

Expand All @@ -153,11 +153,10 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
writer.writeLine(d(variableType));
writer.writeLine("");

writer.writeLine(graphVizToPlantUml(dumpClassHierachry(variableType, {showBaseType: true, depth: 2})));
writer.writeLine(graphVizToPlantUml(dumpClassHierachry(variableType, { showBaseType: true, depth: 2 })));

writer.writeLine(graphVizToPlantUml(opcuaToDot(variableType)));


// enumerate components
writer.writeLine(displayNodeElement(variableType, { format: "markdown" }));
for (const reference of variableType.allReferences()) {
Expand All @@ -168,5 +167,3 @@ export async function buildDocumentation(namespace: Namespace, writer: IWriter):
}
}
}


0 comments on commit e0786c7

Please sign in to comment.