Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joachimvh opened this issue Feb 11, 2022 · 6 comments
Open

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

joachimvh opened this issue Feb 11, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@joachimvh
Copy link
Member

joachimvh commented Feb 11, 2022

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
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member

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

@joachimvh
Copy link
Member Author

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
Copy link
Member

rubensworks commented Feb 11, 2022

@rubensworks
Copy link
Member

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants