Skip to content

compact does not recognize string default when @type is not provided #466

Open
@jaxoncreed

Description

@jaxoncreed

In the following example:

  const inputData: JsonLd = [
    {
      "@id": "http://a.example/Employee7",
      "http://xmlns.com/foaf/0.1/givenName": [
        {
          "@value": "Robert",
        },
        {
          "@value": "Taylor",
        },
      ],
      "http://xmlns.com/foaf/0.1/familyName": [
        {
          "@value": "Johnson",
        },
      ],
      "http://xmlns.com/foaf/0.1/mbox": [
        {
          "@id": "mailto:rtj@example.com",
        },
      ],
    },
  ];
  const inputContext: ContextDefinition = {
    givenName: {
      "@id": "http://xmlns.com/foaf/0.1/givenName",
      "@type": "http://www.w3.org/2001/XMLSchema#string",
      "@container": "@set",
    },
    familyName: {
      "@id": "http://xmlns.com/foaf/0.1/familyName",
      "@type": "http://www.w3.org/2001/XMLSchema#string",
    },
    phone: { "@id": "http://xmlns.com/foaf/0.1/phone", "@container": "@set" },
    mbox: { "@id": "http://xmlns.com/foaf/0.1/mbox" },
  };
  const compactJsonLd = await compact(inputData, inputContext);
  console.log(compactJsonLd);

  // Logs:
  // {
  //     '@id': 'http://a.example/Employee7',
  //     'http://xmlns.com/foaf/0.1/familyName': 'Johnson',
  //     'http://xmlns.com/foaf/0.1/givenName': [ 'Robert', 'Taylor' ],
  //     mbox: { '@id': 'mailto:rtj@example.com' }
  //   }

Notice that "familyName" and "givenName" are not transformed. This is probably because these fields both of the @type http://www.w3.org/2001/XMLSchema#string. Setting the @type in the input data does not cause this problem. But, you shouldn't be required to provide a @type for strings as http://www.w3.org/2001/XMLSchema#string should be assumed if no type has been provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      close