mitre / jsonix

Powerful XML<->JSON JavaScript mapping library.
Other
10 stars 2 forks source link

namespacePrefixes not available in the Context constructor #43

Open nik-west opened 3 months ago

nik-west commented 3 months ago

I want to replace the old and not supported library with this fork.

The issue I am facing is that previously there was a namespacePrefixes, used to map namespace to prefix, as an optional parameter to the constructor, when Context is created. Is there some way to use this functionality with @mitre/jsonix?

Previously - https://github.com/highsource/jsonix/wiki/Configuring-Namespace-Prefixes Now - https://github.com/mitre/jsonix/blob/master/nodejs/scripts/types/main.d.ts

export class Context {
  /**
   * Creates an instance of Context.
   *
   * @param {any[]} s (description)
   */
  constructor(s: any[]);
}

Any help will be appreciated Thanks!

mbaer3000 commented 3 months ago

Hi there! A question to the Mitre people: Is this project still alive? @bhogan-mitre @jhopper-mitre @sbowman-mitre

mbaer3000 commented 3 months ago

@nik-west From looking at the code it appears to me that merely the typing is a bit off, the functionality should in fact still be there. Will investigate further.

Amndeep7 commented 1 month ago

Hi @mbaer3000 sorry for not seeing this issue. This project is still alive in at least a maintenance mode. W/r to your request, if you are able to submit a PR, please tag me and I will review it and see if we can get it merged in and released.

nik-west commented 1 month ago

Hi @Amndeep7, we already opened a PR . It's a one line in scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Context.js, for initializing p before using it(it's another problem that we faced during testing). If you can review it, it will be great and we will either submit another fix for better typing, or directly push in the current one. Thanks!

Amndeep7 commented 1 month ago

@nik-west I'm having @Hookwitz take a look at this in the next few days. If you could submit a separate PR, that'd be great.

Hookwitz commented 1 month ago

@nik-west , I've approved the PR and merged it in.

In reviewing the code, it does appear the construction should be able to accept mappings and options according to https://github.com/mitre/jsonix/blob/master/nodejs/scripts/jsonix.js#L5693C26-L5693C34 (hopefully that link works) To type this, there should be an optional options that is either strictly defined as namespacePrefixs: Record<String, unknown> and/or supportXsiType: Boolean (these are the only two options that I can see from the clause blocks within the initialize function).

I was not the original author of the main type declaration file, but would welcome a PR with the suggested options parameter to work with the rest of the library.

Off the top of my head it may look something like this:

type Mappings = Record<string, unknown>

interface Options {
    namespacePrefix?: Record<string, string>;
    supportXsiType?: boolean;
}

....

constructor(mappings: Mappings[], options?: Options);