BKN 知识网络 · 关系类 API (0.1.0)

Download OpenAPI specification:

Relation types use relation_type:{kn_id}/{relation_type_id}. Reads and lists require view_detail; data reads require query_data; updates and deletes use modify and delete. Lists and searches are filtered before total and pagination. See ../knowledge-network-authorization.md.

Resource IDs use lowercase letters, digits, underscores, and hyphens, start with a letter or digit, and contain at most 128 characters. Resource names contain at most 128 Unicode characters.

With strict_mode=true, indirect relation mappings read the backing Vega schema under the source contract's query_data operation; they do not introduce an implicit view_detail requirement. Main-branch publication reuses the effective delegator selected by Proxy preflight. Missing bindings return 400; a current-user denial returns 403; controlled lookup failures return 502, and timeout/unavailable dependencies return 503 without exposing the downstream response body.

Refused declarations and references

A save the declaration rules refuse answers 400 BknBackend.RelationType.InvalidParameter.Declarations. As before, error_details holds the English text (several issues are joined with ; ). metadata.issues holds the same refusal as records, so that a caller words it in its own language and finds the definition and the property:

{
  "error_code": "BknBackend.RelationType.InvalidParameter.Declarations",
  "error_details": "relation type aliases: alias \"order\" is the same as its own name",
  "metadata": {"issues": [{
    "rule": "alias_equals_own_name",
    "relation_type_id": "order",
    "params": {"alias": "order"},
    "message": "relation type aliases: alias \"order\" is the same as its own name"
  }]}
}

Each issue has rule (the stable code below), the ID of the definition it concerns (object_type_id, or relation_type_id), property for a rule of one data property, params (the values the message is built from), involved (every definition a rule that spans definitions concerns, as {kind, id}; the first is the definition that refers first and the one named by the ID field) and message (the English text). A rule within one definition lists the first problem it finds. A rule that spans definitions (replaced_by, fallback_for, deprecated endpoints) lists every problem that involves a definition of the save. An alias that names another definition (alias_conflict) reports only the first conflict.

A delete refused because definitions still refer to it answers 409 BknBackend.RelationType.StillReferenced. error_details.references lists the English sentences, as before. metadata.references holds one record per reference: kind and id name what is referred to, referrer_kind and referrer_id who refers to it, via the declaration (replaced_by or fallback_for), and message the English sentence.

Rules of this definition kind:

  • Relation declarations: reverse_name_invalid (reverse_name, reason), importance_invalid (importance, allowed), verification_invalid (verification, allowed), cardinality_invalid (cardinality, allowed), cardinality_cross_join (cardinality), characteristics_ends_differ (source, target), symmetric_cardinality (cardinality), symmetric_reverse_name, symmetric_required, list_value_invalid (field, value, allowed), list_value_duplicated (field, value); field is the declaration field, required or characteristics.
  • Fallback paths on the relation itself: fallback_for_invalid (fallback_for), fallback_for_not_secondary (fallback_for), fallback_for_self (fallback_for), fallback_cross_join (relation_type), fallback_characteristics (relation_type).
  • Fallback paths across relation types: fallback_target_missing, fallback_target_not_primary, fallback_target_deprecated (each with fallback_for), fallback_ends_differ (fallback_for, source, target, primary_source, primary_target), fallback_primary_cardinality (fallback_for, cardinality), fallback_already_taken (fallback_for, other_fallback).
  • Relation properties: relation_properties_not_indirect (endpoint_type), relation_properties_too_many (count, max), relation_property_invalid (reason, the English text of the property check, not a stable code), relation_property_joins_ends (mapped_field), relation_property_unique; and the property rules of an object type (semantics, constraints, aliases), which name the property.
  • Lifecycle: lifecycle_fields_without_deprecation, lifecycle_reason_missing, lifecycle_replaced_by_invalid, lifecycle_replaced_by_self, lifecycle_status_invalid, replaced_by_missing, replaced_by_deprecated (see the object type API for their params), and endpoint_deprecated (object_type): an endpoint object type is deprecated while the relation is not.
  • Aliases: the alias rules of the object type API.

List relation types

Authorizations:
OAuth2
path Parameters
kn_id
required
string

Business knowledge network ID

query Parameters
name_pattern
string

Fuzzy-match by relation type name. Empty by default.

sort
string
Enum: "update_time" "name"

Sort field. Defaults to update_time.

direction
string
Enum: "asc" "desc"

Sort direction. Supported values are asc and desc. Defaults to desc.

offset
integer <int64>

Offset of the first returned item. Must be greater than or equal to 0. Defaults to 0.

limit
integer <int64>

Maximum number of returned items per page. Supported paginated values are 1 to 1000; -1 disables pagination. Defaults to 10.

tag
string

Exact-match by tag. Empty by default.

source_object_type_id
Array of strings

Source object type ID. Multiple values are supported; a relation type matches when its source is any of them.

target_object_type_id
Array of strings

Target object type ID. Multiple values are supported; a relation type matches when its target is any of them.

bound_object_type_id
Array of strings

Bound object type ID. Finds relation types whose source or target equals this object type. Multiple values are supported.

branch
string
Default: "main"

Branch. Defaults to main.

Responses

Response samples

Content type
application/json
{
  • "entries": [
    ],
  • "total_count": 0
}

Create or search relation types

Authorizations:
OAuth2
path Parameters
kn_id
required
string

Business knowledge network ID

query Parameters
branch
string
Default: "main"

Branch. Defaults to main.

import_mode
string
Default: "normal"
Enum: "normal" "overwrite" "ignore"

Import mode. normal returns an error for a concept with the same name; overwrite replaces it; ignore skips it. Defaults to normal.

confirm_clear_declarations
boolean
Default: false

With overwrite, a file that does not carry the BKN spec 3.0 declarations of an existing relation type, such as a 2.x package or an old JSON export, would clear them. Without this parameter the request is refused with 409 BknBackend.RelationType.DeclarationsWouldBeCleared, whose details list the cleared declarations (relation_type_id, fields); pass true to clear them.

strict_mode
boolean
Default: true

Whether to validate dependency existence. Defaults to true. When unset, falls back to the deprecated validate_dependency.

header Parameters
x-http-method-override
string
Enum: "POST" "GET"

Override request header. Omitted or POST creates relation types; GET searches them. Any other value is refused with 400.

Request Body schema: application/json
required
required
Array of objects (ReqRelationType)

Relation type details

Responses

Request samples

Content type
application/json
Example
{
  • "entries": [
    ]
}

Response samples

Content type
application/json
Example
{
  • "entries": [
    ],
  • "total_count": 2,
  • "next_cursor": "cursor-relation-types-1"
}

Update a relation type

Authorizations:
OAuth2
path Parameters
kn_id
required
string

Business knowledge network ID

rt_id
required
string

Relation type ID

query Parameters
branch
string

Branch. Uses main when omitted.

strict_mode
boolean
Default: true

Whether to strictly validate dependencies. When true, validates dependencies such as related object types and data views. When false, skips this validation.

Request Body schema: application/json
required
name
required
string <= 128 characters

Name

tags
Array of strings

Tags used for business identification

comment
string

Comment

icon
string

Icon

color
string

Color

branch
string

Branch ID

source_object_type_id
string <= 128 characters ^[a-z0-9][a-z0-9_-]{0,127}$

Source object type ID

target_object_type_id
string <= 128 characters ^[a-z0-9][a-z0-9_-]{0,127}$

Target object type ID

type
string
Enum: "direct" "indirect" "filtered_cross_join"

Relation type

Array of DirectMappingRules (objects) or IndirectMappingRule (object) or FilteredCrossJoinMappingRule (object)

Associated matching rule. For direct, this is a Mapping array; for filtered_cross_join, this is a FilteredCrossJoinMappingRule.

reverse_name
string

BKN spec 3.0. The name of the relation read from the target to the source, with the rules of name. Empty is none.

aliases
Array of strings

BKN spec 3.0. Other names of the relation type. Empty is none.

cardinality
string
Enum: "one_to_one" "one_to_many" "many_to_one" "many_to_many"

BKN spec 3.0. How many counterparts an instance of each end has, from source to target. Empty is not declared; a filtered_cross_join relation can only be many_to_many.

object (RelationConstraints)

BKN spec 3.0. The Relation Constraints section of the relation type.

object (Lifecycle)

BKN spec 3.0. Whether the definition is still in use. Without it the definition is active. status deprecated needs a reason; replaced_by names an active definition of the same kind.

importance
string
Enum: "primary" "secondary"

BKN spec 3.0. primary (the default, returned as empty) or secondary.

fallback_for
string

BKN spec 3.0. On a secondary relation, the ID of the primary relation it stands in for when a source instance has no primary counterpart. Empty is none.

verification
string
Enum: "confirmed" "unconfirmed"

BKN spec 3.0. confirmed when the relation joins on real identifiers, unconfirmed when it joins by inferred rules. Empty is not declared.

Responses

Request samples

Content type
application/json
{
  • "name": "string",
  • "tags": [
    ],
  • "comment": "string",
  • "icon": "string",
  • "color": "string",
  • "branch": "string",
  • "source_object_type_id": "string",
  • "target_object_type_id": "string",
  • "type": "direct",
  • "mapping_rules": [
    ],
  • "reverse_name": "string",
  • "aliases": [
    ],
  • "cardinality": "one_to_one",
  • "constraints": {
    },
  • "lifecycle": {
    },
  • "importance": "primary",
  • "fallback_for": "string",
  • "verification": "confirmed"
}

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}

Get relation type details

Authorizations:
OAuth2
path Parameters
rt_ids
required
Array of strings

Relation type ID

kn_id
required
string

Business knowledge network ID

query Parameters
branch
string
Default: "main"

Branch. Defaults to main.

Responses

Response samples

Content type
application/json
{
  • "entries": [
    ]
}

Delete relation types

Authorizations:
OAuth2
path Parameters
kn_id
required
string

Business knowledge network ID

rt_ids
required
Array of strings

Relation type ID

query Parameters
branch
string
Default: "main"

Branch. Defaults to main.

Responses

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}

Explore concept paths from a source

Explore concept paths from a source

Authorizations:
OAuth2
path Parameters
kn_id
required
any
query Parameters
branch
string
Default: "main"

Branch. Defaults to main.

header Parameters
x-http-method-override
required
string
Value: "GET"

Must be GET. The request is sent as POST so the query can be carried in the body.

Request Body schema: application/json
required
concept_groups
Array of strings

Concept group ID array

source_object_type_id
required
string

Source object type ID

path_length
required
integer

Path length, 1 to 3.

direction
required
string
Enum: "forward" "backward" "bidirectional"

Direction: forward, backward, or bidirectional.

Responses

Request samples

Content type
application/json
{
  • "source_object_type_id": "comment",
  • "direction": "backward",
  • "path_length": 1
}

Response samples

Content type
application/json
{
  • "entries": [
    ]
}

Validate relation types

Validates relation type dependency existence only and does not write data. It verifies dependencies such as source and target object types and indirect data views.

Response: HTTP 200 uses valid and detail for ordinary model validation. Strict dependency failures return the documented 400/403/502/503 error envelope, whose error_details includes a safe dependency_kind.

Internal API: POST /api/bkn-backend/in/v1/.../relation-types/validation. The caller is resolved from headers and OAuth is not required.

Authorizations:
OAuth2
path Parameters
kn_id
required
string

Business knowledge network ID

query Parameters
branch
string

Branch. Uses main when omitted.

strict_mode
boolean
Default: true

Whether to strictly validate dependencies. Defaults to true.

import_mode
string
Default: "normal"
Enum: "normal" "ignore" "overwrite"

Same as the create relation type API. Defines validation semantics for existing relation type ID conflicts; name conflicts follow create behavior.

confirm_clear_declarations
boolean
Default: false

With overwrite, a file that does not carry the BKN spec 3.0 declarations of an existing relation type, such as a 2.x package or an old JSON export, would clear them. Without this parameter the request is refused with 409 BknBackend.RelationType.DeclarationsWouldBeCleared, whose details list the cleared declarations (relation_type_id, fields); pass true to clear them.

Request Body schema: application/json
required
entries
Array of objects

Relation type list to validate. Its structure is the same as the create API.

Responses

Request samples

Content type
application/json
{
  • "entries": [
    ]
}

Response samples

Content type
application/json
{
  • "valid": true,
  • "detail": "string"
}