[−][src]Attribute Macro odata_client::odata_client
#[odata_client]
Procedural macro to generate OData entity model types within a module.
N.B The value of generating code for an API substantially lies in the access to autocomplete functionality, and/or the ability to browse the API's endpoints & types. Currently, rust-analyzer's support for these features with code from procedural macros is limited.
A more productive development experience may be had by writing generated code to a file, instead of using this proc macro attribute. This can be done with the
write_module_build_artifact
function. This function additionally supports customisation of the generated code to some extent.
The proc macro attribute should be placed on an empty module:
#[odata_client(service_url = "https://example.ru/odata_api/")] mod my_entity_model {}
(The mod my_entity_model;
syntax, with a semicolon, can be used in nightly with
#![feature(proc_macro_hygiene)]
.)
With just the service_url
argument, the OData API's $metadata
document will be fetch during
build. This document can instead be set from a local file using the metadata_filepath
argument, or inline metadata XML can be set using the metadata_xml
argument. In either case,
the service_url
argument is still required:
#[odata_client( service_url = "https://example.ru/odata_api/", metadata_filepath = "metadata.xml" )] mod entity_model_document_file {} #[odata_client( service_url = "https://example.ru/odata_api/", metadata_xml = r#" <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"> <edmx:DataServices> <Schema Namespace="My.Entity.Model" xmlns="http://docs.oasis-open.org/odata/ns/edm"> [...] </Schema> </edmx:DataServices> </edmx:Edmx> "# )] mod entity_model_inline_document {}