Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ The FDC3 API specification consists of interfaces. It is expected that each Des

Other interfaces defined in the spec are not critical to define as concrete types. Rather, the Desktop Agent should expect to have objects of the interface shape passed into or out of their library.

### Implementation language

FDC3 and the Desktop Agent API it defines are intended to be independent of particular programming languages and platforms and hence the original definitions, produced in TypeScript, may be translated into other languages. However, this also places limitations on the API definitions as they need to be widely implementable in other languages.

Specifically, the use of ['unions'](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types) of primitive values in API type and metadata objects, or function parameters SHOULD be avoided as they often cannot be replicated in other languages. Unions of more complex types (such as specific [Context](ref/Context) Types) may be used where a suitable interface is available or can be created to allow the required polymorphism in languages other than TypeScript.

### API Access

The FDC3 API can be made available to an application through a number of different methods. In the case of web applications, a Desktop Agent MUST provide the FDC3 API via a global accessible as `window.fdc3`. Implementors MAY additionally make the API available through modules, imports, or other means.
Expand Down
35 changes: 34 additions & 1 deletion docs/context/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface Context {

or in JSON Schema as:

```JSON
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://fdc3.finos.org/schemas/next/context/context.schema.json",
Expand Down Expand Up @@ -104,6 +104,39 @@ It may be as simple as adding an optional `$version` property to types, but it c

This Standard defines a number of conventions for the fields of context types that all context objects SHOULD adhere to in order to reduce or prevent competing conventions from being established in both standardized types and proprietary types created by app developers.

#### Avoid union types / composition of primitive types

Both Typescript and JSON Schema allow for a type of polymorphism in types and interfaces that is hard to represent in other languages: allowing the type of a variable to be a ['union'](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types) of other, unrelated types. E.g.: in typescript
Comment thread
kriswest marked this conversation as resolved.
Outdated

```ts
type Example = SomeOtherType | YetAnotherType;
```

Similar constructs are allowed in JSON Schema by [combining or composing schemas](https://json-schema.org/understanding-json-schema/reference/combining) using the `anyOf` or `oneOf` keywords to specify that a value can take the form defined in one-or-more or one-of-several sub-schemas.

```json
"recipients": {
"title": "Email Recipients",
"description": "One or more recipients for the email.",
"oneOf": [
{
"$ref": "contact.schema.json#"
},
{
"$ref": "contactList.schema.json#"
}
]
}
```

However, other languages can be less less-flexible. In most languages, polymorphism of object types is possible via the implementation and/or extension of an interface (for example all context types are derived from the [Context](ref/Context) schema, which can be modelled as an interface). However, this approach is not possible if one of the types in the union is a primitive, meaning it's not a class and can't be modified to implement an interface, e.g.:
Comment thread
kriswest marked this conversation as resolved.
Outdated

```ts
type Example2 = SomeOtherType | number;
```

Hence, to ensure that FDC3 context objects are implementable in other languages context schemas MUST NOT use `anyOf`/`oneOf` compositions of primitive types in JSON schema (and, hence, unions of primitive types in TypeScript) and SHOULD avoid compositions of Object types unless a concept that can be defined as an interface (such as [Context](ref/Context)) is available.

#### Identifiers

An `id` field with type `object` is defined in the base [fdc3.context](ref/Context) type, from which all other context objects are derived, and SHOULD be used to encapsulate identifiers. Specific context types may define subfields for specific identifiers as needed.
Expand Down
3 changes: 3 additions & 0 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module.exports={
themes: ['@docusaurus/theme-mermaid'],
"plugins": [],
"themeConfig": {
"prism": {
"additionalLanguages": ["json","csharp"]
},
"algolia": {
"appId": "YW91L9TW76",
"apiKey": "ab431bb4107069ef51780d8947cd8e0a",
Expand Down