Skip to main content

Import an OData service

The OData importer (odata) reads an OData service's metadata into the Catalog. Entity types and complex types become types, enums become enums, each entity set becomes a set of operations, and every function and action becomes an operation of its own. You can then search, version, diff, lint and convert it like any other catalog item.

When to use it​

Use the OData importer for any service that publishes OData metadata: OData v4 and 4.01, and the older v2 and v3 services that SAP Gateway and many Microsoft products still expose. Bring in the metadata as a CSDL XML or CSDL JSON file, or point Apiome at the running service.

At a glance​

StepWhereDetails
Import a CSDL file or a service's $metadataImport to catalog → File Upload or URL Import, or apiome import odataImport it
Discover a running service from its service rootURL Import with the service root, or apiome import odata --discoverDiscover a live service
Check the metadata against the OASIS schemas, references and keysAutomatic on every import; problems show in lintHow the metadata is checked
Compare two versions with the OData model-versioning rulesTick two versions on the catalog item's Versions tabBreaking changes between versions
Convert to an OpenAPI projectConvert to OpenAPI on the catalog itemPer-format conversion packs
Export back to ODataExport on the catalog itemOData (CSDL) from any source

An item imported from OData exports back to OData with its entity sets, keys, types, functions and actions unchanged.

Import it​

Import the metadata like any other catalog format: in the import wizard (Import to catalog, then File Upload or URL Import), over the REST API (see Import a specification), or from the CLI with apiome import odata <file>.

What you haveHow it is read
CSDL XML: a $metadata document or .edmx file, OData v4, v3 or v2Read by the CSDL XML reader. v2 and v3 associations become v4-style navigation properties.
CSDL JSON: the OData v4 JSON metadata format (.json, "$Version": "4.0" or "4.01")Read into the same model as CSDL XML, so both forms of one service import alike.

Functions and actions​

Every function and action the metadata declares is imported as an operation, with its parameters and return type. They are grouped under one service named after the entity container (for example ShopService), beside the entity sets.

What the metadata declaresWhat the import keeps
A function (<Function>, or "$Kind": "Function" in CSDL JSON)A GET operation. Its parameters are query parameters, required when declared Nullable="false". A composable function is recorded as composable.
An action (<Action>)A POST operation. Its parameters are listed as the request body, since an action takes them in the body. An action with no return type answers 204.
A bound operation (IsBound="true")Called through an entity set of its binding type: /Products/Shop.Cheapest for a collection, /Products({key})/Shop.Discount for one entity. The binding parameter is the path, not a request parameter.
A function import or action import in the entity containerThe route of the unbound operation it names (/Search) and the entity set its result belongs to. An unbound operation nothing imports is kept, with no route.
A v2 or v3 <FunctionImport>An operation at /{Name}, called with its m:HttpMethod (POST when a v3 import is side-effecting, otherwise GET). Every parameter is a query parameter.

Overloads. OData lets one name have several signatures. Each overload is kept separately, named by its kind, its fully-qualified name and its parameter types in order — for example Function Shop.Search(Edm.String,Edm.Int32) — so two overloads never merge, and an overload keeps its identity from one version to the next as long as its signature does.

CSDL XML and CSDL JSON give the same operations: an unstated Nullable means nullable in XML (except on a collection, where it is about the items) and not nullable in JSON, and both are read that way.

Discover a live service​

You can import a running OData service from its service root (for example https://services.example.com/odata/trippin/) or its $metadata URL, in the import wizard or from the CLI. Either way the $metadata URL is <service root>/$metadata, and a query string such as SAP's ?sap-client=100 is kept.

In the import wizard​

  1. On the Catalog, click “Import to catalog” and choose URL Import.
  2. Enter the service root as the Document URL and click “Fetch and detect”.

The service root answers with its service document, the list of its entity sets, which has no model to import. The wizard recognizes it (v4 or v3 JSON, v2 or v3 verbose JSON, or v2 or v3 Atom XML), fetches the service's $metadata instead, and continues with that document. The catalog item records the $metadata URL as its source. The fetch runs in your browser, so the service must allow requests from Apiome (CORS); if it does not, import the metadata from the CLI or upload a saved copy.

From the CLI​

Give the service root (or its $metadata URL) to --discover:

apiome import odata --discover https://services.example.com/odata/trippin/
apiome import odata --discover "https://sap.example.com/sap/opu/odata/sap/ZBP_SRV/?sap-client=100"

The CLI derives the $metadata URL (<service root>/$metadata, query string kept), reports it (Discovered OData $metadata at …) and imports that document exactly as it would a --url import: it is parsed, checked, cataloged and linted. --discover must be the only input.

ProblemWhat you see
The URL is not http/https or has no hostThe CLI stops with a usage error.
$metadata cannot be fetched (404, 401, network)The CLI stops with the fetch error; check the service root and your access.

In the wizard, a $metadata that cannot be fetched shows Couldn't read that source with the error (for example Fetch failed with HTTP 404.); click “Try again” once the service is reachable.

The CLI's test fixtures include one service of each kind the importer reads most: an OData v4 service (bookshop-odata-v4.edmx) and an SAP Gateway-style v2 service (sales-odata-v2.xml), in apiome-cli/tests/fixtures/. They are a quick way to try an import:

apiome import odata apiome-cli/tests/fixtures/sales-odata-v2.xml

How the metadata is checked​

Every OData document is checked three ways. None of the checks refuses an import: a document with problems still imports, its problems are recorded on the catalog item, and lint reports them.

CheckVersionsWhat it catchesLint rule
OASIS CSDL JSON schemav4A member of the wrong shape, such as a $Nullable that is not true or falseodata.csdl-schema (warning)
OASIS CSDL XML schemav4 CSDL XMLXML the JSON form never sees: a misspelled attribute (Nulable), an element CSDL does not define, a missing required attributeodata.csdl-xsd (warning)
References and keysv4, v3, v2A name that points at nothing, and an entity type with no usable keyodata.unresolved-reference and odata.entity-key (errors)

OASIS schemas​

The two OASIS schemas describe CSDL's shape:

  • CSDL JSON is checked against the CSDL JSON schema as uploaded.
  • CSDL XML is checked against the OASIS EDMX and EDM XML schemas. It is also converted to its CSDL JSON form, following the OASIS mapping, and that form is checked against the JSON schema and kept with the catalog item. For example, an XML property with no Nullable becomes "$Nullable": true, because the JSON form defaults to false.

v2 and v3 metadata has no OASIS schema, so it is not checked this way. The schemas are part of Apiome: checking never fetches anything, even when a document names a schema location.

References and keys​

A document can be the right shape and still name things that do not exist. Apiome follows every name a document uses:

  • Types: property, parameter, return and term types, base types, and the entity type of each entity set and singleton. Names written with a schema alias (self.Product) resolve like namespace-qualified ones.
  • Relationships: each navigation property's target type, partner and referential constraint; each navigation property binding's path and target; in v2 and v3, each association's ends and each association set's association, roles and entity sets.
  • Operations: the action or function each import names, and the entity set it returns into.

Every entity type must also have a usable key: a non-abstract type declares one or inherits one from its base type (a derived type must not declare its own), and each key property must exist and be a single, non-nullable primitive, enumeration or type-definition value. A floating-point, stream or spatial property cannot be part of a key.

A name in a namespace the document only references (<edmx:Reference>) and did not bring in is not checked, because the import cannot see it.

Both rules are errors, so a document that breaks them fails a style guide's publish gate. Clients generated from such metadata cannot bind the missing names or address the keyless entities.

Where the problems are recorded​

Each problem carries the path of the place it is about, written like a CSDL JSON pointer (/Namespace/Type/Member):

FieldWhat it holds
odata_csdl_validtrue when a v4 document matches the OASIS CSDL JSON schema
odata_csdl_violationsUp to 50 JSON schema problems, each a path and a message, such as /Shop/Item/ID/$Nullable: 'yes' is not of type 'boolean'
odata_csdl_violation_countHow many JSON schema problems there were in all
odata_xsd_violationsUp to 50 XML schema problems, such as /Shop/Item/ID: 'Nulable' attribute not allowed for element
odata_xsd_violation_countHow many XML schema problems there were in all
odata_resolution_issuesUp to 50 reference and key problems, each a kind (reference or key), a path and a message, such as /Shop/Svc/Items/$Type: entity set 'Items' names `Shop.Itm`, which is not declared.
odata_resolution_issue_countHow many reference and key problems there were in all

The odata_xsd_* and odata_resolution_* fields are present only when there is a problem.

Lint reports each problem at its path: csdl:<path> for JSON schema, reference and key problems, and xml:<path> for XML schema problems. To stop services that do not match the OASIS schemas from being published, raise odata.csdl-schema and odata.csdl-xsd to error in a copy of your style guide.

Breaking changes between versions​

OData defines which model changes a service may make without breaking its clients: OData 4.01 Protocol, section 5.2 Model Versioning. When you compare two versions of an OData catalog item, each change is graded by those rules:

ChangeSeverityRule
A nullable property addedSafeodata.property-added-nullable
A non-nullable property added with a default valueSafeodata.property-added-with-default
A non-nullable property added with no defaultBreakingodata.property-added-required
A property's type changedBreakingodata.property-type-changed
A property made non-nullableBreakingodata.property-made-non-nullable
A property made nullableDangerousodata.property-made-nullable
An entity type's key changedBreakingodata.key-changed
A collection-valued or nullable navigation property addedSafeodata.navigation-added
A single-valued, non-nullable navigation property addedBreakingodata.navigation-added-required
A single-valued navigation property added whose nullability is not recordedDangerousodata.navigation-added-unknown
A navigation property removedBreakingodata.navigation-removed
A navigation property's target type changedBreakingodata.navigation-type-changed
A navigation property's partner changedDangerousodata.navigation-partner-changed
Annotations addedSafeodata.annotation-added
An annotation changed or removedDangerousodata.annotation-changed

New entity types, complex types, enumerations, entity sets, functions and actions are safe; anything removed is breaking. Because an overload is identified by its signature, changing a function's or action's parameters reads as the old overload removed (breaking) and a new one added (safe). Every other change is graded by the standard rules. A v2 or v3 navigation property's nullability comes from its association end (0..1 is nullable, 1 is not).

Schema version. Section 5.2 asks a service that makes a breaking change to version its metadata with the Core.SchemaVersion annotation, so clients can still ask for the old model with $schemaversion. Each breaking change says whether the schema's Core.SchemaVersion moved between the two versions (for example Core.SchemaVersion moved (Shop: '1' → '2')), or that it did not and should have. The grade itself does not change. The schema version is read from v4 metadata.

When the import refuses a document​

CodeWhyWhat to do
INPUT_MALFORMEDThe XML or JSON cannot be read.Fix the syntax the message names.
INPUT_SEMANTIC_INVALIDThe document declares no entity container, so it describes no service.Add the EntityContainer (XML) or $Kind: "EntityContainer" member (JSON).