Git Product home page Git Product logo

backendmetadatagenerator's Introduction

BackendMetadataGenerator

Generate some information about properties from C# class. This information will help to fix response from SOAP server (cast to numbers, booleans, etc.) by xml2js.

USAGE

  1. Place C# proxy class files (with *.cs extension) near executable file (BackendMetadataGenerator.exe)
  2. Run the program
  3. Get <MethodName>.json file and <MethodName>.udf.json

File with .udf.json extension is a udf datapoint almost ready to consume by AppAdmin (MSF)

The json file contains xpath of response key and value is an object, which contains:

  • xpath (string) - part of response path (maybe useful when using validator option)
  • isArray (boolean) - indicates that item is array
  • parse (string) - javascript type (hint for casting), can be ("number", "boolean", etc.)

EXAMPLE

var metadata = require("./method.json");
xml2js.parseString(data.response, {
    explicitArray: false,
    ignoreAttrs: false,
    mergeAttrs: true,
    emptyTag: null,
    tagNameProcessors: [xml2js.processors.stripPrefix],
    attrNameProcessors: [xml2js.processors.stripPrefix],
    validator: function(xpath, currentValue, node) {
    	var info = metadata[xpath];
    	// parse node somehow using info
        return node;
    }
}, function(err, result) {});

parseNode function can be look like:

function parseNode(info, xpath, currentValue, node) {
    node = replaceNil(node);
    if (info && node !== null) {
        var parse = info.parse;
        switch (parse) {
            case "number": return +node;
            case "boolean": return (node === "true" ? true : (node === "false" ? false : node));
            case "date": 
            default: break;
        }
        if (info.isArray && !Array.isArray(node)) {
            node = nodeToArray(node, xpath);
        }
    }
    return node;
}

TODO

  • Convert to lib
  • Create single entry point and use as lib
  • Document methods

backendmetadatagenerator's People

Contributors

unlight avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.