LinkedSoftwareDependencies / Components-Generator.js

⚙️ Generate Components.js component files from TypeScript
13 stars 7 forks source link

Conflict between @range {json} and default parameters #87

Open joachimvh opened 2 years ago

joachimvh commented 2 years ago

Using version 3.0.0-beta.7

/**
   * @param parameters - Parameters that should be parsed from the CLI. @range {json}
   *                     Format details can be found at https://yargs.js.org/docs/#api-reference-optionskey-opt
   * @param options - Additional options to configure yargs. @range {json}
   */
  public constructor(parameters: Record<string, Options> = {}, options: CliOptions = {})

Generates the following JSON-LD (same for both parameters):

          "@id": "scs:dist/init/cli/YargsCliExtractor.jsonld#YargsCliExtractor_parameters",
          "range": {
            "@type": "ParameterRangeUnion",
            "parameterRangeElements": [
              "rdf:JSON",
              {
                "@type": "ParameterRangeUndefined"
              }
            ]
          },
          "comment": "Parameters that should be parsed from the CLI."

Should just be rdf:JSON instead of the union.

rubensworks commented 2 years ago

I think this is correct though. Since you provide a default value, this param is optional for TS. Therefore, the generator also sees it as optional, hence the union with undefined.

joachimvh commented 2 years ago

The problem is that this causes Components.js not to parse the config as any JSON object anymore. It complains about the fields in the JSON to be undefined URIs.

rubensworks commented 2 years ago

Ah, then it may be a bug during context generation. Could you check if your context contains @type: @json for your param?

joachimvh commented 2 years ago

It does not:

      "YargsCliExtractor": {
        "@id": "scs:dist/init/cli/YargsCliExtractor.jsonld#YargsCliExtractor",
        "@prefix": true,
        "@context": {
          "parameters": {
            "@id": "scs:dist/init/cli/YargsCliExtractor.jsonld#YargsCliExtractor_parameters"
          },
          "options": {
            "@id": "scs:dist/init/cli/YargsCliExtractor.jsonld#YargsCliExtractor_options"
          }
        }
      },
rubensworks commented 2 years ago

Aha! So there's probably going something wrong here: https://github.com/LinkedSoftwareDependencies/Components-Generator.js/blob/feature/strict-type-checking/lib/serialize/ComponentConstructor.ts#L642-L655

rubensworks commented 2 years ago

No, scratch that, this is the correct place: https://github.com/LinkedSoftwareDependencies/Components-Generator.js/blob/feature/strict-type-checking/lib/serialize/ContextConstructor.ts#L72-L81

But the earlier link already shows a possible fix :-)