+ All Categories
Home > Documents > OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema...

OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema...

Date post: 03-Apr-2018
Category:
Upload: buituyen
View: 260 times
Download: 4 times
Share this document with a friend
46
OData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 18 21 November 2014 Technical Committee: OASIS Open Data Protocol (OData) TC Chairs: Ram Jeyaraman ([email protected]), Microsoft Ralf Handl ([email protected]), SAP AG Editors: Ralf Handl ([email protected]), SAP AG Hubert Heijkers ([email protected]), IBM Mike Pizzo ([email protected]), Microsoft Martin Zurmuehl ([email protected]), SAP AG Additional artifacts: This prose specification is one component of a Work Product that also includes: OData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 (this document) edm.json V4-CSDL-to-JSON.xsl Related work: This specification replaces or supersedes: None This specification is related to: OData JSON Format Version 4.0. OASIS Standard. 24 February 2014. http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata- json-format-v4.0-os.html. OData Version 4.0, a multi-part Work Product which includes: OData Version 4.0 Part 1: Protocol . 24 February 2014. http://docs.oasis- open.org/odata/odata/v4.0/os/odata-v4.0-part1-protocol.html OData Version 4.0 Part 2: URL Conventions. 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/odata-v4.0-part2- url-conventions.html OData Version 4.0 Part 3: Common Schema Definition Language (CSDL) . 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/odata-v4.0- part3-csdl.html ABNF components: OData ABNF Construction Rules Version 4.0 and OData ABNF Test Cases. 14 August 2013. http://docs.oasis-open.org/odata/odata/v4.0/os/abnf/ odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014 Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 1 of 46
Transcript
Page 1: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

OData JSON Format for Common Schema Definition Language (CSDL) Version 4.0

Working Draft 01

18 21 November 2014

Technical Committee:OASIS Open Data Protocol (OData) TC

Chairs:Ram Jeyaraman ([email protected]), MicrosoftRalf Handl ([email protected]), SAP AG

Editors:Ralf Handl ([email protected]), SAP AGHubert Heijkers ([email protected]), IBMMike Pizzo ([email protected]), MicrosoftMartin Zurmuehl ([email protected]), SAP AG

Additional artifacts:This prose specification is one component of a Work Product that also includes: OData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 (this

document) edm.json V4-CSDL-to-JSON.xsl

Related work:This specification replaces or supersedes: NoneThis specification is related to: OData JSON Format Version 4.0. OASIS Standard. 24 February 2014. http://docs.oasis-

open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html. OData Version 4.0, a multi-part Work Product which includes:

OData Version 4.0 Part 1: Protocol. 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/odata-v4.0-part1-protocol.html

OData Version 4.0 Part 2: URL Conventions. 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/odata-v4.0-part2-url-conventions.html

OData Version 4.0 Part 3: Common Schema Definition Language (CSDL). 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/odata-v4.0-part3-csdl.html

ABNF components: OData ABNF Construction Rules Version 4.0 and OData ABNF Test Cases. 14 August 2013. http://docs.oasis-open.org/odata/odata/v4.0/os/abnf/

Vocabulary components: OData Core Vocabulary, OData Measures Vocabulary and OData Capabilities Vocabulary. 24 February 2014. http://docs.oasis-open.org/odata/odata/v4.0/os/vocabularies/

Declared XML namespaces: None

Abstract:The Open Data Protocol (OData) for representing and interacting with structured content is comprised of a set of specifications. This document extends the specification OData Version 4.0 Part 3: Conceptual Schema Definition Language (CSDL) by defining a JSON format for representing OData CSDL documents. This JSON format for CSDL is based on JSON Schema.

Status:This Working Draft (WD) has been produced by one or more TC Members; it has not yet been voted on by the TC or approved as a Committee Draft (Committee Specification Draft or a Committee Note Draft). The OASIS document Approval Process begins officially with a TC vote

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 1 of 39

Page 2: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

to approve a WD as a Committee Draft. A TC may approve a Working Draft, revise it, and re-approve it any number of times as a Committee Draft.

URI patterns:Initial publication URI:http://docs.oasis-open.org/odata/odata-json-csdl/v4.0/csd01/odata-json-csdl-v4.0-csd01.doc Permanent “Latest version” URI:http://docs.oasis-open.org/odata/odata-json-csdl/v4.0/odata-json-csdl-v4.0.doc Permanent link to latest version of edm.json:http://docs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json

(Managed by OASIS TC Administration; please don’t modify.)

Copyright © OASIS Open 2014. All Rights Reserved.All capitalized terms in the following text have the meanings assigned to them in the OASIS Intellectual Property Rights Policy (the "OASIS IPR Policy"). The full Policy may be found at the OASIS website.This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this section are included on all such copies and derivative works. However, this document itself may not be modified in any way, including by removing the copyright notice or references to OASIS, except as needed for the purpose of developing any document or deliverable produced by an OASIS Technical Committee (in which case the rules applicable to copyrights, as set forth in the OASIS IPR Policy, must be followed) or as required to translate it into languages other than English.The limited permissions granted above are perpetual and will not be revoked by OASIS or its successors or assigns.This document and the information contained herein is provided on an "AS IS" basis and OASIS DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 2 of 39

Page 3: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Table of Contents1 Introduction......................................................................................................................................... 5

1.1 Terminology....................................................................................................................................... 51.2 Normative References....................................................................................................................... 51.3 Typographical Conventions...............................................................................................................5

2 JSON CSDL Format Design...............................................................................................................62.1 Design Goals..................................................................................................................................... 62.2 Design Principles............................................................................................................................... 6

3 Requesting the JSON CSDL Format...................................................................................................74 CSDL Documents............................................................................................................................... 8

4.1 Definitions.......................................................................................................................................... 84.1.1 Entity Types and Complex Types...............................................................................................84.1.2 Structural Properties and Navigation Properties........................................................................9

4.1.2.1 Structural Properties.............................................................................................................................94.1.2.2 Navigation Properties..........................................................................................................................104.1.2.3 Collection-Valued Properties..............................................................................................................114.1.2.4 Nullable Properties..............................................................................................................................11

4.1.3 Enumeration Types.................................................................................................................. 124.1.4 Type Definitions....................................................................................................................... 14

4.2 Schemas......................................................................................................................................... 144.2.1 Actions and Functions..............................................................................................................144.2.2 Entity Container........................................................................................................................154.2.3 Terms....................................................................................................................................... 164.2.4 Annotations.............................................................................................................................. 17

4.2.4.1 Tagging Annotations...........................................................................................................................184.2.4.2 Constant Expressions.........................................................................................................................18 Path................................................................................................................................................................ 184.2.4.3 Expressions........................................................................................................................................184.2.4.4 Collection Expressions........................................................................................................................184.2.4.5 Record Expressions............................................................................................................................194.2.4.6 Comparison and Logical Operators and If Expression.....................................................................194.2.4.7 Expression Apply..............................................................................................................................194.2.4.8 Expressions Cast and IsOf..............................................................................................................204.2.4.9 Expressions LabeledElement and LabeledElementReference................................................204.2.4.10 Expression Not.................................................................................................................................204.2.4.11 Expression Null...............................................................................................................................214.2.4.12 Expression UrlRef..........................................................................................................................21

4.3 References...................................................................................................................................... 214.3.1 Includes.................................................................................................................................... 224.3.2 IncludeAnnotations...................................................................................................................22

5 The edm.json Schema....................................................................................................................225.1 Definitions........................................................................................................................................ 235.2 Keywords......................................................................................................................................... 245.3 Formats........................................................................................................................................... 25

6 Validation.......................................................................................................................................... 26

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 3 of 39

Page 4: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

7 Extensibility....................................................................................................................................... 278 CSDL Examples................................................................................................................................ 28

8.1 Products and Categories Example..................................................................................................288.2 Annotations for Products and Categories Example.........................................................................33

9 Conformance..................................................................................................................................... 35Appendix A. Acknowledgments............................................................................................................36Appendix B. Revision History...............................................................................................................37

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 4 of 39

Page 5: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

1 IntroductionOData services are described in terms of an Entity Data Model (EDM). [OData-CSDL] defines an XML representation of the entity data model exposed by an OData service. This document defines an alternative representation using the JavaScript Object Notation (JSON), see [RFC7159]

1.1 TerminologyThe key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC2119].

1.2 Normative References[JSON Schema] JSON Schema.

http://json-schema.org/. [JS-Core] JSON Schema: core definitions and terminology.

http://tools.ietf.org/html/draft-zyp-json-schema-04. [JS-Validation] JSON Schema: interactive and non interactive validation.

http://tools.ietf.org/html/draft-fge-json-schema-validation-00. [OData-CSDL] OData Version 4.0 Part 3: Common Schema Definition Language (CSDL).

See link in “Related work” section on cover page.[OData-JSON] OData JSON Format Version 4.0.

See link in “Related work” section on cover page.[OData-Protocol] OData Version 4.0 Part 1: Protocol.

See link in “Additional artifacts” section on cover page.[OData-URL] OData Version 4.0 Part 2: URL Conventions.

See link in "Related work" section on cover page.[RFC2119] Bradner, S., “Key words for use in RFCs to Indicate Requirement Levels”, BCP

14, RFC 2119, March 1997. http://www.ietf.org/rfc/rfc2119.txt. [RFC7159] Bray, T., Ed., “The JavaScript Object Notation (JSON) Data Interchange Format”,

RFC 7159, March 2014. http://tools.ietf.org/html/rfc7159. [ECMAScript] ECMAScript Language Specification Edition 5,1. June 2011. Standard ECMA-

262. http://www.ecma-international.org/publications/standards/Ecma-262.htm. [XML-Schema-2] W3C XML Schema Definition Language (XSD) 1.1 Part 2: DatatypesW3C XML

Schema Definition Language (XSD) 1.1 Part 2: Datatypes, D. Peterson, S. Gao, C. M. Sperberg-McQueen, H. S. Thompson, P. V. Biron, A. Malhotra, Editors, W3C Recommendation, 5 April 2012, http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/.Latest version available at http://www.w3.org/TR/xmlschema11-2/.

1.3 Non-Normative References[JSON Schema] JSON Schema.

http://json-schema.org/.

1.4 Typographical ConventionsKeywords defined by this specification use this monospaced font.

Normative source code uses this paragraph style.

Some sections of this specification are illustrated with non-normative examples.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 5 of 39

Page 6: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Example 1: text describing an example uses this paragraph style

Non-normative examples use this paragraph style.

All examples in this document are non-normative and informative only.All other text is normative unless otherwise labeled.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 6 of 39

Page 7: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

2 JSON CSDL Format DesignJSON, as described in [RFC7159], defines a text format for serializing structured data. Objects are serialized as an unordered collection of name-value pairs. JSON Schema (see [JSON Schema], [JS-Core], and [JS-Validation]) is an emerging standard that defines a JSON format for describing JSON formats. JSON Schema is extensible and allows adding keywords and formats for CSDL concepts that cannot be translated into JSON Schema concepts.

2.1 Design GoalsThe goals of guiding design principles are

JSON CSDL is valid JSON Schema JSON CSDL can be used to by standard JSON Schema validators to validate messages from

and to the service JSON CSDL contains the same information as the XML format for CSDL defined in

[OData-CSDL] JSON CSDL uses JSON Schema concepts that correspond to CSDL concepts JSON CSDL uses [OData-JSON] concepts where it goes beyond JSON Schema JSON.parse() of JSON CSDL creates a JavaScript object graph that

o Appeals to JavaScript programmers by following common naming conventions

o Satisfies basic access patterns

o Can easily be augmented with client-side post-processing to satisfy more sophisticated access patterns

2.2 Design PrinciplesTo achieve the design goals the following principles were applied:

Structure-describing CSDL elements (structured types, type definitions, enumerations, are translated into JSON Schema constructs

Attributes and child elements of structure-describing CSDL elements that cannot be translated into JSON Schema constructs are added as extension keywords to the target JSON Schema constructs

All other CSDL elements are translated into JSON with a consistent set of ruleso Element and attribute names in UpperCamelCase are converted to lowerCamelCase,

and uppercase attribute names are converted to lowercaseo Attributes and elements that can occur at most once within a parent become name/value

pairso Elements that can occur more than once within a parent and can be uniquely identified

within their parent (schemas, key properties, entity sets, …) became a name/value pair with pluralized name and a "dictionary" object as value containing one name/value pair per element with the identifier as name

o Elements that can occur more than once within a parent and cannot be uniquely identified within their parent (action overloads, function overloads, …) become a name/value pair with pluralized name and an array as value containing one item per child element

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 7 of 39

Page 8: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

3 Requesting the JSON CSDL FormatThe JSON CSDL format can be requested in Metadata Document Requests (see [OData-Protocol]) using the $format query option in the request URL with the MIME types application/schema+json or application/json, optionally followed by format parameters, or the case-insensitive abbreviation json which MUST NOT be followed by format parameters.

Alternatively, this format can be requested using the Accept header with the MIME type application/json, optionally followed by format parameters.

If specified, $format overrides any value specified in the Accept header.

Possible format parameters are: IEEE754Compatible odata.streaming

These are defined in [OData-JSON].

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 8 of 39

Page 9: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

4 CSDL DocumentsA CSDL document in JSON is represented as a JSON Format document with additional keywords.It must contain a name/value pair with name $schema, and it may contain definitions, schemas, and references.

The value of $schema is the canonical URL of the edm schema.

Example 2: Structure of CSDL document

{ "$schema":"http://docs.oasis-openodata.org/odata/odata-json-csdlschemas/v4.0/edm.json#", "definitions" : …, "schemas" : …, "references" : …}

4.1 DefinitionsThe definitions object contains one name/value pair per entity type, complex type, enumeration type, and type definition, using the namespace-qualified name of the type. It uses the namespace instead of the alias because these definitions can be reused by other CSDL documents, and aliases are document-local, so they are meaningless for referencing documents.

Example 3: Definitions

"definitions":{ "ODataDemo.Product" : …, "ODataDemo.Category" : …, "ODataDemo.Supplier" : …, "ODataDemo.Country" : …, "ODataDemo.Address" : …, "org.example.Employee": …, "org.example.Manager": … }

4.1.1 Entity Types and Complex TypesEach structured type is represented as a name/value pair of the standard JSON Schema definitions object. The name is the namespace-qualified name of the entity type or complex type. If the structured type has no base type, the value is a schema of type object. Otherwise the value is a schema with the keyword allOf whose value is an array of two items. The first item is a JSON Reference to the definition of the base type;, the second is a schema of type object.

The schema of type object may contain the standard JSON Schema name/value pairs appropriate for this type. It will not contain the additionalProperties keyword, allowing additional properties beyond the declared properties. This is necessary for inheritance as well as annotations and dynamic properties, and is in line with the model versioning rules defined in [OData-Protocol].In addition it may contain an odata name/value pair whose value is an object. The odata object may contain name/value pairs abstract and openType, and for entity types also kind, hasStreammediaEntity, and keys,.

The value of kind is entity.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 9 of 39

Ralf Handl, 11/21/14,
Is the trailing hash required?
Ralf Handl, 11/21/14,
Probably not required, but it expresses that this is a JSON Reference, and an empty fragment means that this refers to the full document located at this URL
Page 10: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

The abstract, openType, and hasStream mediaEntity name/value pairs have Boolean values. If not present, their value is false. They correspond to the Abstract, OpenType, and HasStream attributes defined in [OData-CSDL].The value of keys is an object with one name/value pair per key property, using the alias as name and the property path as value. If no alias is defined, it defaults to the key property name. For abstract entity types that neither specify a base type nor a key the value of keys is an empty object.

The schema may contain annotations.

Example 4: Product entity type

"ODataDemo.Product":{ "type":"object", "odata" : { "kind":"entity", "mediaEntityhasStream" : true, "keys":{ "ID":"ID" } }, "properties" : …, … }

Example 5: Manager entity type inheriting from Employee

"org.example.Manager":{ "allOf":[ { "$ref":"#/definitions/org.example.Employee" }, { "type":"object", … } ] },

[4.1.2] Structural Properties and Navigation PropertiesEach structural property and navigation property is represented as a name/value pair of the standard JSON Schema properties object. The name is the property name; the value is a schema describing the allowed values of the property.The schema may contain annotations.

Example 6: structural and navigation properties of Supplier entity type

"ODataDemo.Supplier":{ …, "properties":{ "ID":…, "Name":…, "Address":…, "Concurrency":…, "Products":… }, … }

4.1.1.1[4.1.2.1] Structural PropertiesProperties of type Edm.String are represented as JSON Schema primitive type string.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 10 of 39

Page 11: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Properties of type Edm.Boolean are represented as JSON Schema primitive type boolean.

Properties of type Edm.Decimal are represented as JSON Schema primitive type number. A numeric scale is represented with the multipleOf JSON Schema keyword and a value of 10-scale. The precision is represented with the minimum and maximum keywords and a value of ±10precision-scale - 10-scale (using 0 for scale if the scale is variable).

All other primitive types are represented as JSON references to definitions in the edm.json schema.

The precision of properties of types Edm.DateTimeOffset, Edm.Duration, and Edm.TimeOfDay is expressed as a pattern for the fractional part of the seconds portion of the property's value. The default value of a property is represented with the JSON Schema keyword default.

Complex properties are represented as JSON references to definition of the complex type, either as local references for types defined in this CSDL document, or as external references for types defined in referenced CSDL documents.

Example 7: structural properties of Supplier entity type

"properties":{ "ID":{ "type":"string" }, "Name":{ "type":[ "string", "null" ] }, "Address":{ "$ref":"#/definitions/ODataDemo.Address" }, "Concurrency":{ "$ref" : "http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Int32" }, … }

Example 8: string property with a default value

"Dimension":{ "type":"string", "maxLength":50, "default":"Unspecified" },

4.1.1.2[4.1.2.2] Navigation PropertiesNavigation properties are represented similar to complex properties so that a standard JSON Schema validator can validate the expanded representation of the navigation property.Navigation properties will contain an odata name/value pair whose value is an object. The odata object will contain a name/value pair kind with value navigation, and may contain name/value pairs partner, onDelete, and referentialConstraints.

The value of partner is the name of the partner navigation property. The value of onDelete is an object with a single name/value pair action whose value is one of the values Cascade, None, SetDefault, or SetNull defined in [OData-CSDL], section 7.3.1.

The value of referentialConstraints is an object with one name/value pair per dependent property, using the dependend ptoprty name as name and an object as value. This object contains the name/value

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 11 of 39

Ralf Handl, 11/21/14,
We could shorten this by defining Edm.Xxx locally as a reference to the central definition
Page 12: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

pair referencedProperty whose value is the name of the principal property. In addition this object may contain annotations.

Example 9: navigation property Products with partner and on-delete constraint

"Products":{ "type":"array", "items":{ "$ref":"#/definitions/ODataDemo.Product" }, "odatarelationship":{ "kind":"navigation", "partner":"Category", "onDelete":{ "action":"Cascade" } } }

Example 10: navigation property Country with referential constraint

"Country":{ "anyOf":[ { "$ref":"#/definitions/ODataDemo.Country" }, { "type":"null" } ], "odatarelationship":{ "kind":"navigation", "referentialConstraints":{ "CountryName":{ "referencedProperty":"Name" } } } }

4.1.1.3[4.1.2.3] Collection-Valued PropertiesCollection-valued structural and navigation properties are represented as schemas of type array. The value of the items keyword is a schema specifies the type of the items.

Example 11: collection-valued nullable string property Tags

"Tags":{ "type":"array", "items":{ "type":[ "string", "null" ] } }

Example 12: collection-valued navigation property Products of Supplier entity type

"properties":{ …, "Products":{ "type":"array", "items":{

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 12 of 39

Page 13: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"$ref":"#/definitions/ODataDemo.Product" }, "odatarelationship":{ "kind":"navigation", "partner":"Supplier" } } }

4.1.1.4[4.1.2.4] Nullable PropertiesNullable properties of types Edm.String and Edm.Boolean are represented with an array-valued JSON Schema type that consists of the corresponding JSON Schema primitive type and the JSON Schema null type.

Other nullable structural and navigation properties are represented by a schema using the anyOf keyword followed by a two-element array with a schema for the non-null values and a schema for the JSON Schema null type.

Example 13: nullable property Price of type Edm.Decimal with precision 15 and scale 3

"Price":{ "anyOf":[ { "type":"number", "multipleOf":1e-3, "minimum":-999999999999.999, "maximum":999999999999.999 }, { "type":"null" } ] }

Example 14: nullable property Created of type Edm.DateTimeOffset with precision 6

"Created":{ "anyOf":[ { "allOf":[ { "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.DateTimeOffset" }, { "pattern":"(^[^.]*$|[.][0-9]{1,6}$)" } ] }, { "type":"null" } ] }

Example 15: nullable collection-valued property Dates

"Dates":{ "type":"array", "items":{ "anyOf":[

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 13 of 39

Page 14: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

{ "$ref":"http://docs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Date" }, { "type":"null" } ] } },

Example 16: nullable navigation property Supplier

"Supplier":{ "anyOf":[{ "$ref":"#/definitions/ODataDemo.Supplier" }, { "type":"null" } ], "odatarelationship":{ "kind":"navigation", "partner":"Products" } }

4.1.2[4.1.3] Enumeration TypesEach enumeration type is represented as a name/value pair of the standard JSON Schema definitions object. The name is the namespace-qualified name of the type definition; the value is a schema describing the allowed values. If the enumeration type does not allow multiple members to be selected simultaneously, the schema uses the enum keyword to list all defined values. The value of the enum keyword is an array that contains a string with the member name and an integer with the member value for each enumeration member.If the enumeration type allows multiple members to be selected simultaneously, the schema uses the anyOf keyword with two sub-schemas: one schema using the enum keyword listing all explicitly defined member names and values, and one schema of type string using the pattern keyword with a regular expression for a comma-separated list of member names or nonnegative integer values.The schema may contain annotations. Annotations on enumeration members are represented similar to instance annotations on properties as name/value pairs whose name is the member name, followed by an at (@) sign, followed by the qualified term name, and optionally followed by a hash (#) sign and the qualifier. The annotation value is represented according to the rules specified in this document.

Example 17: enumeration type with exclusive members and annotations on members and on the type

"org.example.ShippingMethod":{ "enum":[ "FirstClass", "0", "TwoDay", "1", "Overnight", "2" ], "[email protected]":"Shipped with highest priority", "[email protected]":"Shipped within two days", "[email protected]":"Shipped overnight" "@Core.Description":"Method of shipping"

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 14 of 39

Ralf Handl, 11/21/14,
Do we allow numeric values if no Value attribute is present in CSDL? If not, we can remove the numeric enum values here.
Page 15: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

}

Example 18: enumeration type with flag values

"org.example.Pattern":{ "anyOf":[ { "enum":[ "Plain", "0", "Red", "1", "Blue", "2", "Yellow", "4", "Solid", "8", "Striped", "16", "SolidRed", "9", "SolidBlue", "10", "SolidYellow", "12", "RedBlueStriped", "19", "RedYellowStriped", "21", "BlueYellowStriped", "22" ], }, { "type":"string", "pattern":"^(Plain|Red|Blue|Yellow|Solid|Striped|SolidRed|SolidBlue|SolidYellow|RedBlueStriped|RedYellowStriped|BlueYellowStriped|[1-9][0-9]*)(,(Plain|Red|Blue|Yellow|Solid|Striped|SolidRed|SolidBlue|SolidYellow|RedBlueStriped|RedYellowStriped|BlueYellowStriped|[1-9][0-9]*))*$" } ], "odata":{ "underlyingType":"Edm.Int32", "isFlags":true } }

4.1.3[4.1.4] Type Definitions Each type definition is represented as a name/value pair of the standard JSON Schema definitions object. The name is the namespace-qualified name of the type definition; the value is a schema describing the allowed values of the type definition using the same rules as primitive properties.The schema may contain annotations.

Example 19: type definitions based on Edm.String, Edm.Decimal and Edm.DateTimeOffset

"Model1.Text50":{ "type":"string", "maxLength":50 }, "Model1.VariableDecimal":{ "type":"number",

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 15 of 39

Ralf Handl, 11/21/14,
Do we use numbers for enum values in payloads, or strings? I assume strings.
Page 16: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"@Core.Description":"A type definition" }, "Model1.ExactTimestamp":{ "$ref": "http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.DateTimeOffset" }

4.2 SchemasThe value of schemas is an object with one name/value pair per defined schema. The name is the namespace of the schema. Its value is an object with an alias name/value pair whose value is the alias of the namespace, or null if no alias is defined. The object may contain the name/value pairs actions, functions, terms, and entityContainer.

It also may contain annotations.

Example 20: schemas

"schemas":{ "Some.Model":{ "alias":"This", "actions": …, "functions": …, "terms": …, "entityContainer": …, "@Annotation.With.Some.Term": … }

4.2.1 Actions and FunctionsThe value of the actions and functions name/value pairs are arrays of JSON objects, each describing an action or function overload. These objects have name/value pairs name, isBound, entitySetPath, and parameters. Objects representing functions in addition have a returnType name/value pair and may have an isComposable name/value pair with a Boolean value.

The values of isBound and isComposable are Boolean.

The value of entitySetPath is a string.

The value of parameters is an object with one name/value pair per parameter. The name is the parameter name, the value is an object with a type name/value pair and optional name/value pairs maxLength, precision, scale, and srid for the type facets.

The value of returnType is an object with a type name/value pair and optional name/value pairs maxLength, precision, scale, and srid for the type facets.

All JSON objects may contain annotations.

Example 21: actions and functions

"actions":[ { "name":"Rejection", "isBound":true, "parameters":{ "Reason":{ "type":"Edm.String", "maxLength":"max", "nullable":true } } } ],

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 16 of 39

Ralf Handl, 11/21/14,
We could also make it optional, it was just easier when programming the XSL transformation to always have it.
Page 17: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"functions":[ { "name":"OddWaldos", "isBound":true, "entitySetPath":"in", "parameters":{ "in":{ "type":"Collection(Self.Waldo)" } }, "returnType":{ "type":"Collection(Self.Waldo)" } } ]

4.2.2 Entity ContainerThe value of the entityContainer name/value pair is an object with name/value pairs entitySets, singletons, actionImports, and functionImports. The values of these pairs are objects with one name/value pair per container child of that type. The name of each pair is the child's name, the value is an object.An object describing an entity set must have an entityType name/value pair whose value is the name of the entity type that is the base type of all entites in this set. It may have a navigationPropertyBindings name/value pair. Its value is an object with one name/value pair per navigation property that has a binding. The name is the path to the navigation property; the value is an object with a name/value pair target whose value is the name of the target entity set.An object describing a singleton must have a type name/value pair whose value is the name of the entity type of the singleton. It may have a navigationPropertyBindings name/value pair with the same structure as in objects describing an entity set.An object describing an action import must have an action name/value pair whose value is the name of the action triggered by this action import. It may have an entitySet name/value pair whose value is the name of the entity set containing the entity or entities returned by the action,An object describing a function import must have a function name/value pair whose value is the name of the function triggered by this function import. It may have an entitySet name/value pair whose value is the name of the entity set containing the entity or entities returned by the function, It also may have an includeInServiceDocument name/value pair with a Boolean value.

All objects may contain annotations.

Example 22: entity container

"entityContainer":{ "name":"DemoService", "entitySets":{ "Products":{ "entityType":"ODataDemo.Product", "navigationPropertyBindings":{ "Category":{ "target":"Categories" } } }, "Categories":{ "entityType":"ODataDemo.Category", "navigationPropertyBindings":{ "Products":{ "target":"Products" }

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 17 of 39

Page 18: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

} }, "Suppliers":{ "entityType":"ODataDemo.Supplier", "navigationPropertyBindings":{ "Products":{ "target":"Products" }, "Address/Country":{ "target":"Countries" } }, "@Core.OptimisticConcurrency":[ { "@odata.type":"#PropertyPath", "value":"Concurrency" } ] }, "Countries":{ "entityType":"ODataDemo.Country" } }, "singletons":{ "Contoso":{ "type":"Self.Supplier", "navigationPropertyBindings":{ "Products":{ "target":"Products" } } } }, "functionImports":{ "ProductsByRating":{ "entitySet":"Products", "function":"ODataDemo.ProductsByRating" } } }

4.2.3 TermsThe value of the terms name/value pair is an object with one name/value pair per term defined within the schema. The name of each pair is the term's name, the value is an object with a type name/value pair and optional name/value pairs appliesTo, baseTerm, nullable, defaultValue, maxLength, precision, scale, and srid.

All term definition objects may contain annotations.

Example 23: term definition

"terms":{ "Developer":{ "baseTerm":"X.Person", "type":"Y.DeveloperType" }, "DevelopmentTeam":{ "type":"Collection(Y.DeveloperType)", "@custom.ItemIsA":"Y.Developer", "@custom.IsA":"X.Team" }, "ScrumTeam":{

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 18 of 39

Page 19: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"baseTerm":"Y.DevelopmentTeam", "type":"Y.ScrumTeamType" }, "Movies":{ "type":"Collection(X.Movie)" }, "ArchivedMovies":{ "type":"Collection(Y.ArchivedMovieType)", "@custom.ItemIsA":"X.Movie" }, "SomeThing":{ "type":"Y.SomeThingType" } }

4.2.4 AnnotationsAnnotations can appear inline within a model element, or externally as a block that targets a model element. Annotations with external targeting are represented as an annotations name/value pair whose value is an array of JSON objects. Each of these objects contains a target name/value pair whose value is a string with a path expression identifying the annotated model element. In addition each object contains at least one annotation in the same format that is used for inline annotations and specified in the remaining part of this section.

Example 24: Annotations with external targeting

"annotations":[ { "target":"Some.EntityType/SomeProperty", "@X.Y":…, … }, { "target":"Another.EntityType", "@X.Y":…, … }, …]

Annotations are represented similar to instance annotations in [OData-JSON], chapter 18.Annotations for JSON objects are name/value pairs placed within the object, the name is an at (@) sign followed by the namespace- or alias-qualified name of the term, optionally followed by a hash (#) sign and the qualifier of the annotation.Annotations for JSON arrays or primitives are name/value pairs placed next to the name/value pair whose value is the annotated array or primitive value. The name is the name of the annotated name/value pair followed by the namespace- or alias-qualified name of the term, optionally followed by a hash (#) sign and the qualifier of the annotation.The value of the annotation is either a plain JSON value or a JSON object.

Example 25: annotation within an object, annotation of a non-object value, and annotation of an annotation

"@Some.Term" : …,"[email protected]" : …,"@Some.Term#[email protected]": …

4.2.4.1 Tagging AnnotationsTagging annotations that don't specify an explicit value are represented with an empty object as their value.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 19 of 39

Ralf Handl, 11/21/14,
Normalize to namespace?
Ralf Handl, 11/21/14,
Normalize to namespace?
Page 20: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Example 26: a tagging annotation

"@Core.IsLanguageDependent":{}

4.2.4.2 Constant ExpressionsThe constant expressions edm:Bool and edm:String are represented as plain JSON values; so are expressions edm:Double containing a numeric value not equal to NaN, -INF, or INF. The other constant expressions are represented similar to individual properties or operation responses in [OData-JSON], chapter 11, as an object with name/value pairs @odata.type and value. The value of @odata.type is a hash (#) sign followed by the unqualified type name, the value of value is the OData JSON representation of the annotation value defined in [OData-JSON], section 7.1.

Example 27: a string-valued annotation, a Boolean-valued annotation, a numeric float-valued annotation, an infinity-valued annotation, and an integer annotation

"@A.StringValue": "A plain string value,"@A.BooleanValue" : true,"@A.FloatValue":1.23e4,"@A.FloatValue#inf": { "@odata.type": "#Double", "value": "INF"},"@An.Integer":{ "@odata.type": "#Int64", "value": 42}

4.2.4.3 Path ExpressionsThe expressions edm:AnnotationPath, edm:NavigationPropertyPath, edm:Path, and edm:PropertyPath are represented similar to the constant expressions with a JSON object representation, using the dynamic expression name as an abstract primitive type name:

Example 28: annotation with edm:Path dynamic expression

"@Org.OData.Measures.V1.ISOCurrency":{ "@odata.type":"#Path", "value":"Currency"}

4.2.4.4 Collection ExpressionsThe dynamic expression edm:Collection is represented as a JSON array. Its items are representations of its child expressions according to the rules specified in this section.

Example 29: annotation with edm:Record dynamic expression, one Boolean edm:PropertyValue and one with an edm:Collection value

"@Capabilities.UpdateRestrictions":{ "Updatable":true, "NonUpdatableNavigationProperties":[ { "@odata.type":"#NavigationPropertyPath", "value":"Supplier" }, { "@odata.type":"#NavigationPropertyPath", "value":"Category" } ]}

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 20 of 39

Page 21: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

4.2.4.5 Record ExpressionsThe dynamic expression edm:Record is represented as a JSON object. The Type attribute of the edm:Record expression is represented as an @odata.type annotation. Each edm:PropertyValue child element is represented as a name/value pair with the value of the Property attribute as name. Its value expression is represented according to the rules specified in this section.

4.2.4.6 Comparison and Logical Operators and If ExpressionThe dynamic expression edm:If and the logical expressions edm:Eq, edm:Ne, edm:Ge, edm:Gt, edm:Le, edm:Lt, edm:And, and edm:Or are represented are represented as JSON objects with name/value pairs @odata.type and value. The value of @odata.type is a hash (#) sign followed by the dynamic expression name, the value of value is a JSON array with items that are representations of the child expressions according to the rules specified in this section.

Example 30: edm:If expression using an edm:Path expression as its condition and evaluating to one of two edm:String expressions

"@org.example.display.DisplayName":{ "@odata.type":"#If", "value":[ { "@odata.type":"#Path", "value":"IsFemale" }, "Female", "Male" ],}

4.2.4.7 Expression ApplyThe dynamic expression edm:Apply is represented as a JSON object with an @odata.type name/value pair whose value is #Apply. The Function attribute is represented as a function name/value pair with the function name as its string value. The child expressions are represented as a value name/value pair whose value is an array with items that are representations of the child expressions according to the rules specified in this section.

Example 31: edm:Apply expression using two edm:String expressions and one edm:Path expression as its parameters

"@Some.Computed.Url":{ "@odata.type":"#Apply", "function":"odata.concat", "value":[ "Products(", { "@odata.type":"#Path", "value":"ID" }, ")" ],}

4.2.4.8 Expressions Cast and IsOfThe dynamic expressions edm:Cast and edm:IsOf are represented as JSON objects with an @odata.type name/value pair whose value is is a hash (#) sign followed by the dynamic expression name. The Type attribute is represented as a type name/value pair with a string value. The facet attributes are represented as name/value pairs maxLength, precision, scale, and srid. The child

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 21 of 39

Page 22: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

expression is represented as the value of a value name/value pair according to the rules specified in this section.

Example 32: edm:IsOf expression using an edm:Path expression as its parameter

"@For.Testing":{ "@odata.type":"#IsOf", "type":"Edm.Binary", "value":{ "@odata.type":"#Path", "value":"ImageData" }}

4.2.4.9 Expressions LabeledElement and LabeledElementReferenceThe dynamic expression edm:LabeledElement is represented as a JSON object with an @odata.type name/value pair whose value is #LabeledElement. The Name attribute is represented as a name name/value pair with a string value. Its single child expression is represented as a value name/value pair whose value is the representation of the child expression according to the rules specified in this section.The dynamic expression edm:LabeledElementReference is represented as a JSON object with an @odata.type name/value pair whose value is #LabeledElementReference. Its single child expression is represented as a value name/value pair whose value is the representation of the child expression according to the rules specified in this section.

Example 33: edm:LabeledElement and edm:LabeledElementReference expressions

{ "@odata.type":"#LabeledElement", "name":"MyReusableAnnotation", "value":…,},{ "@odata.type":"#LabeledElementReference", "value":"Model.MyReusableAnnotation"}

4.2.4.10 Expression NotThe dynamic expression edm:Not is represented as a JSON object with an @odata.type name/value pair whose value is #Not. Its single child expression is represented as a value name/value pair whose value is the representation of the child expression according to the rules specified in this section.

Example 34: edm:Not expression

"@Some.Term": { "@odata.type": "#Not", "value":{ "@odata.type":"#Path", "value":"IsHappy" }}

4.2.4.11 Expression NullThe dynamic expression edm:Null is represented as a JSON object with an @odata.type name/value pair whose value is #Null. It may contain annotations.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 22 of 39

Page 23: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Example 35: edm:Null expression with nested annotations

"@Some.Term": { "@odata.type": "#Null", "@Within.Null": {}}

4.2.4.12 Expression UrlRefThe dynamic expression edm:UrlRef is represented as a JSON object with an @odata.type name/value pair whose value is #UrlRef. Its single child expression is represented as a value name/value pair whose value is the representation of the child expression according to the rules specified in this section.

Example 36: edm:UrlRef expressions with edm:String value and with edm:Path value

"@Good.Reference#one":{ "@odata.type":"#UrlRef", "value":"http:\/\/www.odata.org"},"@Good.Reference#two":{ "@odata.type":"#UrlRef", "value":{ "@odata.type":"#Path", "value":"DocumentationUrl" }}

4.3 ReferencesThe value of references is an object with one name/value pair per referenced CSDL document. The name is the URI of the CSDL document. Its value is an object that may contain name/value pairs includes and includeAnnotations.

It may contain annotations.

Example 37: references

"references": { "http://tinyurl.com/Org-OData-Measures-V1": { "includes": …, "@Some.Term": … }, "http://somewhere/Vocabulary/V1": { "includeAnnotations": … } }

4.3.1 IncludesThe value of includes is an object with one name/value pair per included namespace. The name is the namespace, the value is an object that may have an alias name/value pair whose value is the alias of the included namespace. If no alias is defined, the object is empty.

Example 38: includes

"includes": { "Org.OData.Measures.V1": { "alias": "Core" }, "Another.Namespace": {} }

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 23 of 39

Ralf Handl, 11/21/14,
Actually we could fold these into the schemas: add a name/value pair for the namespace and pack the URI and alias into an object, see example in 8.1
Page 24: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

4.3.2 IncludeAnnotationsThe value includeAnnotations is an array of objects. Each object has a termNamespace name/value pair and may have name/value pairs targetNamespace and qualifier. The values of these name/value pairs are strings.

Example 39: includeAnnotations

"includeAnnotations": [ { "termNamespace": "Name.Space", "targetNamespace": "Target.Space" }, { "termNamespace": "Name.Space", "targetNamespace": "Target.Space", "qualifier": "SomeName" }, { "termNamespace": "NameSpace", "qualifier": "SomeName" }, { "termNamespace": "Name.Space" } ]

5 The edm.json SchemaThe edm.json schema is an extension of JSON Schema Draft 04, see [JSON Schema] [JS-Core]. It defines the Edm primitive types, additional keywords, and additional values for the format keyword of JSON Schema.

Example 40: outline of the edm.json schema

{ "id":"http://odata.org/schemas/edm-v4.0#", "$schema":"http://json-schema.org/draft-04/schema#", "description":"JSON Schema of OData JSON Format for CSDL Version 4.0", "definitions": …, "allOf":[ { "$ref":"http://json-schema.org/draft-04/schema#" } ], { "properties":{ "schemas": …, "references: … } } ]}

5.1 DefinitionsThe definitions object contains one name/value pair per Edm primitive type, and one for the standard OData error response. For each Edm primitive type the corresponding schema states the JSON Schema primitive type (string, number, or integer) used to represent the Edm primitive type, and additional restrictions on the values: pattern for strings, minimum and maximum for integers. In addition some types specify a custom format.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 24 of 39

Ralf Handl, 11/21/14,
No: hyper-schema definition is itself a hyper-schema document, while edm.json is not a CSDL document.
Ralf Handl, 11/21/14,
Refer to edm.json itself? Cross-check with hyper-schema schema
Page 25: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

A special case is the schema for Edm.Stream: it specifies an unfulfillable constraint on the values as stream properties don't have an inline representation in OData 4.0.

Example 41: definitions for Edm primitive types and the OData standard error message

"definitions":{ "Edm.Binary":{ "type":"string", "pattern":"^([A-Za-z0-9_-]{4})*([A-Za-z0-9_-]{3}[A-Za-z0-9_-]|[A-Za-z0-9_-]{2}[AEIMQUYcgkosw048]=?|[A-Za-z0-9_-][AQgw](==)?)?$" }, "Edm.Byte":{ "type":"integer", "minimum":0, "maximum":255 }, "Edm.Date":{ "type":"string", "pattern":"^[0-9]{4,}-([0][1-9]|[1][012])-([0][1-9]|[12][0-9]|[3][01])$", "format":"xsd:date" }, "Edm.DateTimeOffset":{ "type":"string", "pattern":"^[0-9]{4,}-([0][1-9]|[1][012])-([0][1-9]|[12][0-9]|[3][01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$", "format":"xsd:date-timestamp" }, "Edm.Double":{ "anyOf":[ { "type":"number", "format":"xsd:double" }, { "enum":["-INF","INF","NaN"] } ] }, "Edm.Duration":{ "type":"string", "pattern":"^-?P([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+([.][0-9]+)?S)?)?$", "format":"xsd:dayTimeDuration" }, "Edm.Guid":{ "type":"string", "pattern":"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" }, "Edm.Int16":{ "type":"integer", "minimum":-32768, "maximum":32767 }, "Edm.Int32":{ "type":"integer", "minimum":-2147483648, "maximum":2147483647 }, "Edm.Int64":{ "type":"integer", "minimum":-9223372036854775808,

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 25 of 39

Page 26: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"maximum":9223372036854775807 }, "Edm.SByte":{ "type":"integer", "minimum":-128, "maximum":127 }, "Edm.Single":{ "anyOf":[ { "type":"number", "format":"xsd:float" }, { "enum":["-INF","INF","NaN"] } ] }, "Edm.Stream":{ "description":"unfulfillable constraint, no inline representation of Edm.Stream", "type":"string", "enum":[ null ] }, "Edm.TimeOfDay":{ "type":"string", "pattern":"^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?$" }, "Edm.Geo*":{ "@TODO":"expand into subtypes and define GeoJSON format" }, "odata.error":{ "@TODO":"define" } }

5.2 KeywordsOData CSDL contains many concepts that cannot be translated into JSON Schema, these are represented using the custom keywords schemas and references on the document root level, and the keyword odata for extending standard JSON Schema constructs.

The edm.json schema defines the structure of schemas and references in a way that can be validated by standard JSON Schema validators. The structure of the odata keyword is only defined textually in preceding sections of this specification; JSON Schema Draft 04 does not specify how to define extensions to standard JSON Schema constructs with JSON Schema means.

Example 30: top-level keywords for schemas and references

"allOf":[ { "$ref":"http://json-schema.org/draft-04/schema#" }, { "properties":{ "schemas":{ "@TODO":"define" }, "references":{

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 26 of 39

Ralf Handl, 11/21/14,
Alternative name?
Page 27: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"@TODO":"define" } } } ]

5.3 FormatsNot all constraints on values of Edm primitive types can be expressed with standard JSON Schema means, yet the format keyword of JSON Schema allows defining new values. The edm.json schema uses the following custom formats, based in XML Schema data types:

xsd:date for Edm.Date, see [XML - Schema - 2] , section 3.3.9.

xsd:datetimestamp for Edm.DateTimeOffset, see [XML - Schema - 2] , section 3.4.28.

xsd:dayTimeDuration for Edm.Duration, see [XML - Schema - 2] , section 3.4.27.

xsd:double for Edm.Double, see [XML - Schema - 2] , section 3.3.4.

xsd:float for Edm.Single, see [XML-Schema-2], section 3.3.5.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 27 of 39

Page 28: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

6 ValidationA JSON CSDL $metadata document contains definitions that can be used to validate request and response messages. Depending on the request URL a small wrapper schema has to be used that refers to the corresponding definition in the JSON $metadata document.

Example 42: a schema for validating messages containing a single Product entity

{ "$schema":"http://json-schema.org/draft-04/schema#", "allOf": [{ "$ref": "csdl-16.1.json#/definitions/ODataDemo.Product" } ]}

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 28 of 39

Page 29: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

7 ExtensibilityVocabularies and annotations already allow defining additional characteristics or capabilities of metadata elements, such as a service, entity type, property, function, action or parameter, and [OData-CSDL] defines which model elements can be annotated. This document specifies how these metadata annotations are represented in JSON CSDL documents.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 29 of 39

Page 30: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

8 CSDL ExamplesFollowing are two basic examples of valid EDM models as represented in CSDL. These examples demonstrate many of the topics covered above. They represent the same documents as the examples in chapter 16 of [OData-CSDL].

8.1 Products and Categories Example Example 43:

{ "$schema": "http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#", "definitions": { "ODataDemo.Product": { "type": "object", "odata":{ "kind":"entity", "hasStreammediaEntity" : true, "keys":{ "ID":"ID" } }, "properties":{ "ID":{ "type":"string" }, "Description":{ "type":[ "string", "null" ], "@Core.IsLanguageDependent":{} }, "ReleaseDate":{ "anyOf":[{ "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Date" }, { "type":"null" } ] }, "DiscontinuedDate":{ "anyOf":[{ "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Date" }, { "type":"null" } ] }, "Rating":{ "anyOf":[{ "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Int32" }, { "type":"null" } ]

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 30 of 39

Page 31: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

}, "Price":{ "anyOf":[{ "type":"number", "multipleOf":1 }, { "type":"null" } ], "@Org.OData.Measures.V1.ISOCurrency":{ "@odata.type":"#Path", "value":"Currency" } }, "Currency":{ "type":[ "string", "null" ], "maxLength" : 3 }, "Category":{ "$ref":"#/definitions/ODataDemo.Category", "odatarelationship":{ "kind":"navigation", "partner":"Products" } }, "Supplier":{ "anyOf":[{ "$ref":"#/definitions/ODataDemo.Supplier" }, { "type":"null" } ], "relationshipodata":{ "kind":"navigation", "partner":"Products" } } } }, "ODataDemo.Category":{ "type":"object", "odata":{ "kind":"entity", "keys":{ "ID":"ID" } }, "properties":{ "ID":{ "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Int32" }, "Name":{ "type":"string", "@Core.IsLanguageDependent":{} }, "Products":{ "type":"array", "items":{ "$ref":"#/definitions/ODataDemo.Product" },

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 31 of 39

Page 32: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"relationshipodata":{ "kind":"navigation", "partner":"Category", "onDelete":{ "action":"Cascade" } } } } }, "ODataDemo.Supplier":{ "type":"object", "odata":{ "kind":"entity", "keys":{ "ID":"ID" } }, "properties":{ "ID":{ "type":"string" }, "Name":{ "type":[ "string", "null" ] }, "Address":{ "$ref":"#/definitions/ODataDemo.Address" }, "Concurrency":{ "$ref":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#/definitions/Edm.Int32" }, "Products":{ "type":"array", "items":{ "$ref":"#/definitions/ODataDemo.Product" }, "relationshipodata":{ "kind":"navigation", "partner":"Supplier" } } } }, "ODataDemo.Country":{ "type":"object", "odata":{ "kind":"entity", "keys":{ "Code":"Code" } }, "properties":{ "Code":{ "type":"string", "maxLength" : 2 }, "Name":{ "type":[ "string", "null"

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 32 of 39

Page 33: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

] } } }, "ODataDemo.Address":{ "type":"object", "properties":{ "Street":{ "type":[ "string", "null" ] }, "City":{ "type":[ "string", "null" ] }, "State":{ "type":[ "string", "null" ] }, "ZipCode":{ "type":[ "string", "null" ] }, "CountryName":{ "type":[ "string", "null" ] }, "Country":{ "anyOf":[{ "$ref":"#/definitions/ODataDemo.Country" }, { "type":"null" } ], "relationshipodata":{ "kind":"navigation", "referentialConstraints":{ "CountryName":{ "referencedProperty":"Name" } } } } } } }, "schemas":{ "Org.OData.Core.V1":{ "uri":"http://docs.oasis-open.org/odata/odata/v4.0/cs01/vocabularies/Org.OData.Core.V1.xml", "alias":"Core" }, "Org.OData.Measures.V1":{

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 33 of 39

Ralf Handl, 11/21/14,
Auto-convert this to .json?
Ralf Handl, 11/21/14,
Should we provide JSON versions of the Core, Capabilities, and Measures vocabularies?
Page 34: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"uri":"http://docs.oasis-open.org/odata/odata/v4.0/cs01/vocabularies/Org.OData.Measures.V1.xml", "alias":"UoM" }, "ODataDemo":{ "alias" : null, "functions":[{ "name":"ProductsByRating", "parameters":{ "Rating":{ "type":"Edm.Int32" } }, "returnType":{ "type":"Collection(ODataDemo.Product)" } } ], "entityContainer":{ "name":"DemoService", "entitySets":{ "Products":{ "entityType":"ODataDemo.Product", "navigationPropertyBindings":{ "Category":{ "target":"Categories" } } }, "Categories":{ "entityType":"ODataDemo.Category", "navigationPropertyBindings":{ "Products":{ "target":"Products" } } }, "Suppliers":{ "entityType":"ODataDemo.Supplier", "navigationPropertyBindings":{ "Products":{ "target":"Products" }, "Address/Country":{ "target":"Countries" } }, "@Core.OptimisticConcurrency":[{ "@odata.type":"#PropertyPath", "value":"Concurrency" } ] }, "Countries":{ "entityType":"ODataDemo.Country" } }, "singletons":{ "Contoso":{ "type":"Self.Supplier", "navigationPropertyBindings":{ "Products":{ "target":"Products" }

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 34 of 39

Ralf Handl, 11/21/14,
Proposal: included schemas are also listed under "schemas". Could use "$ref" instead of "uri" to make this a JSON Reference
Page 35: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

} } }, "functionImports":{ "ProductsByRating":{ "entitySet":"Products", "function":"ODataDemo.ProductsByRating" } } } } }, "references":{ "http://docs.oasis-open.org/odata/odata/v4.0/cs01/vocabularies/Org.OData.Core.V1.xml":{ "includes":{ "Org.OData.Core.V1":{ "alias":"Core" } } }, "http://docs.oasis-open.org/odata/odata/v4.0/cs01/vocabularies/Org.OData.Measures.V1.xml":{ "includes":{ "Org.OData.Measures.V1":{ "alias":"UoM" } } } }}

8.2 Annotations for Products and Categories Example Example 44:

{ "$schema":"http://odata.org/schemasdocs.oasis-open.org/odata/odata-json-csdl/v4.0/edm.json#", "schemas":{ "Annotations":{ "alias" : null, "annotations":[{ "target":"ODataDemo.Supplier", "@Vocabulary1.EMail":{ "@odata.type":"#Null" }, "@Vocabulary1.AccountID":{ "@odata.type":"#Path", "value":"ID" }, "@Vocabulary1.Title":"Supplier Info", "@Vocabulary1.DisplayName":{ "@odata.type":"#Apply", "function":"odata.concat", "value":[{ "@odata.type":"#Path", "value":"Name" }, " in ", { "@odata.type":"#Path",

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 35 of 39

Ralf Handl, 11/21/14,
Auto-convert this to .json?
Page 36: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

"value":"Address\/CountryName" } ] } }, { "target":"ODataDemo.Product", "@Self.Tags":[ "MasterData" ] } ] } }, "references":{ "http://host/service/$metadata":{ "includes":{ "ODataDemo":{} } }, "http://somewhere/Vocabulary/V1":{ "includes":{ "Some.Vocabulary.V1":{ "alias":"Vocabulary1" } } } }}

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 36 of 39

Page 37: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

9 ConformanceConforming services MUST follow all rules of this specification document for the types, sets, functions, actions, containers and annotations they expose. Conforming clients MUST be prepared to consume a model that uses any or all of the constructs defined in this specification, including custom annotations, and MUST ignore any elements or attributes not defined in this version of the specification.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 37 of 39

Page 38: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Appendix A. AcknowledgmentsThe contributions of the OASIS OData Technical Committee members, enumerated in [OData-Protocol], are gratefully acknowledged.

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 38 of 39

Page 39: OData JSON Format for Common Schema Definition ... · Web viewOData JSON Format for Common Schema Definition Language (CSDL) Version 4.0 Working Draft 01 21 November 2014 Technical

Appendix B. Revision HistoryRevision Date Editor Changes Made

Working Draft 01

[Rev Date] [Modified By] [Summary of Changes]

odata-json-csdl-v4.0-wd01 Working Draft 01 30 October 2014Standards Track Draft Copyright © OASIS Open 2014. All Rights Reserved. Page 39 of 39


Recommended