Skip to content

Commit

Permalink
One source directory for odata-csdl
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Jul 28, 2023
1 parent 61ca3f6 commit dbe0f49
Show file tree
Hide file tree
Showing 33 changed files with 135 additions and 449 deletions.
8 changes: 5 additions & 3 deletions docs/odata-csdl-json/odata-csdl-json.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ <h2 id="22-design-considerations"><a name="DesignConsiderations" href="#DesignCo
<p>In general, all members that have a default value SHOULD be omitted if they have the default value.</p>
<h2 id="23-json-schema-definition"><a name="JSONSchemaDefinition" href="#JSONSchemaDefinition">2.3 JSON Schema Definition</a></h2>
<p>The structure of CSDL JSON documents can be verified with the JSON Schema <a href="#ODataCSDL">OData-CSDL-Schema</a> provided as an additional artifact of this prose specification. This schema only defines the shape of a well-formed CSDL JSON document but is not descriptive enough to define what a correct CSDL JSON document MUST be in every imaginable use case. This specification document defines additional rules that correct CSDL JSON documents MUST fulfill. In case of doubt on what makes a CSDL JSON document correct the rules defined in this specification document take precedence.</p>
<!-- These source files can be used to produce the JSON variant or the XML variant,
by using either new Number("...", "json") or new Number("...", "xml"). -->

<h1 id="3-entity-model"><a name="EntityModel" href="#EntityModel">3 Entity Model</a></h1>
<p>An OData service exposes a single entity model. This model may be distributed over several <a href="#Schema">schemas</a>, and these schemas may be distributed over several documents.</p>
<p>A service is defined by a single CSDL document which can be accessed by sending a <code>GET</code> request to <code>&lt;serviceRoot&gt;/$metadata</code>. This document is called the metadata document. It MAY <a href="#Reference">reference</a> other CSDL documents.</p>
Expand Down Expand Up @@ -530,7 +533,7 @@ <h2 id="36-annotations"><a name="Annotations" href="#Annotations">3.6 Annotation
<p>A model element MUST NOT specify more than one annotation for a given combination of term and qualifier.</p>
<hr />
<h1 id="4-csdl-json-document"><a name="CSDLJSONDocument" href="#CSDLJSONDocument">4 CSDL JSON Document</a></h1>
<div class="varjson rep">
<p>::: {.varjson .rep} <!-- Lines from here to the closing ::: belong to the JSON variant only. --></p>
<h3 id="-document-object"><a name="DocumentObject1" href="#DocumentObject1"> Document Object</a></h3>
<p>A CSDL JSON document consists of a single JSON object. This document object MUST contain the member <code>$Version</code>.</p>
<p>The document object MAY contain the member <a href="#Reference"><code>$Reference</code></a> to reference other CSDL documents.</p>
Expand All @@ -539,8 +542,7 @@ <h3 id="-document-object"><a name="DocumentObject1" href="#DocumentObject1"> Doc
<h3 id="-version"><a name="Version1.1" href="#Version1.1"> <code>$Version</code></a></h3>
<p>The value of <code>$Version</code> is a string containing either 4.0 or 4.01.</p>
<h3 id="-entitycontainer"><a name="EntityContainer1.2" href="#EntityContainer1.2"> <code>$EntityContainer</code></a></h3>
<p>The value of <code>$EntityContainer</code> is value is the namespace-qualified name of the entity container of that service. This is the only place where a model element MUST be referenced with its namespace-qualified name and use of the alias-qualified name is not allowed.</p>
</div>
<p>The value of <code>$EntityContainer</code> is value is the namespace-qualified name of the entity container of that service. This is the only place where a model element MUST be referenced with its namespace-qualified name and use of the alias-qualified name is not allowed. :::</p>
<div class="varjson example">
<p>Example 2:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode json"><code class="sourceCode json"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">{</span></span>
Expand Down
4 changes: 3 additions & 1 deletion docs/odata-csdl-json/odata-csdl-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ additional rules that correct CSDL JSON documents MUST fulfill. In case
of doubt on what makes a CSDL JSON document correct the rules defined in
this specification document take precedence.

<!-- These source files can be used to produce the JSON variant or the XML variant,
by using either new Number("...", "json") or new Number("...", "xml"). -->

# <a name="EntityModel" href="#EntityModel">3 Entity Model</a>

Expand Down Expand Up @@ -575,7 +577,7 @@ combination of term and qualifier.

# <a name="CSDLJSONDocument" href="#CSDLJSONDocument">4 CSDL JSON Document</a>

::: {.varjson .rep}
::: {.varjson .rep} <!-- Lines from here to the closing ::: belong to the JSON variant only. -->
### <a name="DocumentObject1" href="#DocumentObject1"> Document Object</a>

A CSDL JSON document consists of a single JSON object. This document object MUST contain the member `$Version`.
Expand Down
Binary file modified docs/odata-csdl-json/odata-csdl-json.pdf
Binary file not shown.
8 changes: 5 additions & 3 deletions docs/odata-csdl-xml/odata-csdl-xml.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ <h3>Representation-Specific Headline</h3>
odata-csdl-xml-v4.02-csd01.md</code></pre>
<p>This uses pandoc 3.1.2 from <a href="https://github.com/jgm/pandoc/releases/tag/3.1.2">https://github.com/jgm/pandoc/releases/tag/3.1.2</a>.</p>
</div>
<!-- These source files can be used to produce the JSON variant or the XML variant,
by using either new Number("...", "json") or new Number("...", "xml"). -->

<h1 id="2-xml-representation"><a name="XMLRepresentation" href="#XMLRepresentation">2 XML Representation</a></h1>
<p>OData CSDL XML is a full representation of the OData Common Schema Definition Language in the Extensible Markup Language (XML) 1.1 (Second Edition) <a href="#XML11">XML-1.1</a> with further building blocks from the W3C XML Schema Definition Language (XSD) 1.1 as described in <a href="#XMLSchema1">XML-Schema-1</a> and <a href="#XMLSchema2">XML-Schema-2</a>.</p>
<p>It is an alternative to the CSDL JSON representation defined in <a href="#ODataCSDLJSON">OData-CSDLJSON</a> and neither adds nor removes features.</p>
Expand Down Expand Up @@ -524,15 +527,14 @@ <h2 id="36-annotations"><a name="Annotations" href="#Annotations">3.6 Annotation
<p>A model element MUST NOT specify more than one annotation for a given combination of term and qualifier.</p>
<hr />
<h1 id="4-csdl-xml-document"><a name="CSDLXMLDocument" href="#CSDLXMLDocument">4 CSDL XML Document</a></h1>
<div class="varxml rep">
<p>::: {.varxml .rep} <!-- Lines from here to the closing ::: belong to the XML variant only. --></p>
<h3 id="-element-edmxedmx"><a name="ElementedmxEdmx1" href="#ElementedmxEdmx1"> Element <code>edmx:Edmx</code></a></h3>
<p>The <code>edmx:Edmx</code> element is the root element of a CSDL XML document. It MUST contain the <code>Version</code> attribute and it MUST contain exactly one <code>edmx:DataServices</code> element.</p>
<p>It MAY contain <a href="#Reference"><code>edmx:Reference</code></a> elements to reference other CSDL documents.</p>
<h3 id="-attribute-version"><a name="AttributeVersion1.1" href="#AttributeVersion1.1"> Attribute <code>Version</code></a></h3>
<p>The <code>Version</code> attribute specifies the OData protocol version of the service. For OData 4.0 responses the value of this attribute MUST be <code>4.0.</code> For OData 4.01 responses the value of this attribute MUST be <code>4.01.</code> Services MUST return an OData 4.0 response if the request was made with an <code>OData-MaxVersion </code>header with a value of <code>4.0</code>.</p>
<h3 id="-element-edmxdataservices"><a name="ElementedmxDataServices1.2" href="#ElementedmxDataServices1.2"> Element <code>edmx:DataServices</code></a></h3>
<p>The <code>edmx:DataServices</code> element MUST contain one or more <a href="#Schema"><code>edm:Schema</code></a> elements which define the schemas exposed by the OData service.</p>
</div>
<p>The <code>edmx:DataServices</code> element MUST contain one or more <a href="#Schema"><code>edm:Schema</code></a> elements which define the schemas exposed by the OData service. :::</p>
<div class="varxml example">
<p>Example 2:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode xml"><code class="sourceCode xml"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>&lt;<span class="kw">edmx:Edmx</span><span class="ot"> xmlns:edmx=</span><span class="st">&quot;http://docs.oasis-open.org/odata/ns/edmx&quot;</span></span>
Expand Down
4 changes: 3 additions & 1 deletion docs/odata-csdl-xml/odata-csdl-xml.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ This uses pandoc 3.1.2 from https://github.com/jgm/pandoc/releases/tag/3.1.2.
:::


<!-- These source files can be used to produce the JSON variant or the XML variant,
by using either new Number("...", "json") or new Number("...", "xml"). -->
# <a name="XMLRepresentation" href="#XMLRepresentation">2 XML Representation</a>

OData CSDL XML is a full representation of the OData Common Schema
Expand Down Expand Up @@ -517,7 +519,7 @@ combination of term and qualifier.



::: {.varxml .rep}
::: {.varxml .rep} <!-- Lines from here to the closing ::: belong to the XML variant only. -->
### <a name="ElementedmxEdmx1" href="#ElementedmxEdmx1"> Element `edmx:Edmx`</a>

The `edmx:Edmx` element is the root element of a CSDL XML document. It
Expand Down
Binary file modified docs/odata-csdl-xml/odata-csdl-xml.pdf
Binary file not shown.
Binary file modified docs/odata-data-aggregation-ext/odata-data-aggregation-ext.pdf
Binary file not shown.
Binary file modified docs/odata-json-format/odata-json-format.pdf
Binary file not shown.
Binary file modified docs/odata-protocol/odata-protocol.pdf
Binary file not shown.
Binary file modified docs/odata-url-conventions/odata-url-conventions.pdf
Binary file not shown.
30 changes: 11 additions & 19 deletions lib/build-pdf.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
const iterator = require("./iterator");
const pdf = require("./pdf.js");
const fs = require("fs");

fs.readdirSync(__dirname + "/..", { withFileTypes: true }).forEach(function (
doc
) {
if (doc.isDirectory() && doc.name.startsWith("odata-")) {
fs.readdirSync(`${__dirname}/../${doc.name}`)
.filter((fn) => fn.endsWith(".yaml"))
.forEach(function (metaname) {
pdf(doc.name, metaname.substring(0, metaname.length - 5))
.then((refreshed) => {
if (refreshed) console.log("✓ " + doc.name, metaname);
})
.catch((error) => {
console.log("❌ " + doc.name, metaname);
console.error(error);
process.exitCode = 1;
});
});
}
iterator(function (srcname, name, variant, meta) {
pdf(name, variant, meta)
.then((refreshed) => {
console.log(refreshed ? "✓" : "=", srcname, variant);
})
.catch((error) => {
console.log("❌", srcname, variant);
console.error(error);
process.exitCode = 1;
});
});
85 changes: 34 additions & 51 deletions lib/build.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,40 @@
const iterator = require("./iterator");
const fs = require("fs");
const Number = require("./number");
const pandoc = require("./pandoc");
const { PassThrough } = require("stream");
const yaml = require("js-yaml");

fs.readdirSync(__dirname + "/..", { withFileTypes: true }).forEach(function (
doc
) {
if (doc.isDirectory() && doc.name.startsWith("odata-")) {
fs.readdirSync(`${__dirname}/../${doc.name}`)
.filter((fn) => fn.endsWith(".yaml"))
.forEach(function (metaname) {
var meta = yaml.load(
fs.readFileSync(`${__dirname}/../${doc.name}/${metaname}`)
);
var name =
metaname === "meta.yaml" || !meta.dirname ? doc.name : meta.dirname;
fs.cpSync(
`${__dirname}/../styles`,
`${__dirname}/../docs/${name}/styles`,
{ recursive: true }
);
var md = fs.createWriteStream(
`${__dirname}/../docs/${name}/${name}.md`
);
var html = pandoc({
"--metadata-file": `${__dirname}/../${doc.name}/${metaname}`,
});
html.stdout.pipe(
fs.createWriteStream(`${__dirname}/../docs/${name}/${name}.html`)
);
md.write(Buffer.of(0xef, 0xbb, 0xbf));
new Number(doc.name, metaname.substring(0, metaname.length - 5))
.build(
new PassThrough()
.on("data", function (chunk) {
md.write(chunk);
html.stdin.write(chunk);
})
.on("end", function () {
md.end();
html.stdin.end();
})
)
.then(() => {
console.log("✓ " + doc.name, metaname);
})
.catch((err) => {
console.log("❌ " + doc.name, metaname);
console.error(err.join("\n"));
console.error();
process.exitCode = 1;
});
});
}
iterator(function (srcname, name, variant, meta) {
fs.cpSync(`${__dirname}/../styles`, `${__dirname}/../docs/${name}/styles`, {
recursive: true,
});
var md = fs.createWriteStream(`${__dirname}/../docs/${name}/${name}.md`);
var html = pandoc({
"--metadata-file": `${__dirname}/../${srcname}/${variant}.yaml`,
});
html.stdout.pipe(
fs.createWriteStream(`${__dirname}/../docs/${name}/${name}.html`)
);
md.write(Buffer.of(0xef, 0xbb, 0xbf));
new Number(srcname, variant, meta)
.build(
new PassThrough()
.on("data", function (chunk) {
md.write(chunk);
html.stdin.write(chunk);
})
.on("end", function () {
md.end();
html.stdin.end();
})
)
.then(() => {
console.log("✓", srcname, variant);
})
.catch((err) => {
console.log("❌", srcname, variant);
console.error(err.join("\n"));
console.error();
process.exitCode = 1;
});
});
26 changes: 26 additions & 0 deletions lib/iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
const yaml = require("js-yaml");

module.exports = function (callback) {
fs.readdirSync(__dirname + "/..", { withFileTypes: true }).forEach(function (
doc
) {
if (doc.isDirectory() && doc.name.startsWith("odata-")) {
fs.readdirSync(`${__dirname}/../${doc.name}`)
.filter((fn) => fn.endsWith(".yaml"))
.forEach(function (metaname) {
var meta = yaml.load(
fs.readFileSync(`${__dirname}/../${doc.name}/${metaname}`)
);
var name =
metaname === "meta.yaml" || !meta.dirname ? doc.name : meta.dirname;
callback(
doc.name,
name,
metaname.substring(0, metaname.length - 5),
meta
);
});
}
});
};
10 changes: 6 additions & 4 deletions lib/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ const yaml = require("js-yaml");
const { compareSectionNumbers } = require("./utilities");

class Number {
constructor(dir, variant) {
constructor(dir, variant, meta) {
this.dir = dir;
this.variant = variant;
this.chapters = fs
.readdirSync(dir)
.filter((fn) => fn.endsWith(".md"))
.sort(compareSectionNumbers);
this.meta = yaml.load(
fs.readFileSync(dir + "/" + (this.variant || "meta") + ".yaml")
);
this.meta =
meta ||
yaml.load(
fs.readFileSync(dir + "/" + (this.variant || "meta") + ".yaml")
);
}

secno(type) {
Expand Down
7 changes: 1 addition & 6 deletions lib/pdf.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const puppeteer = require("puppeteer");
const fs = require("fs");
const url = require("url");
const yaml = require("js-yaml");

module.exports = async function (name, variant, force) {
const meta = yaml.load(
fs.readFileSync(`${__dirname}/../${name}/${variant}.yaml`)
);
if (variant !== "meta" || meta.dirname) name = meta.dirname;
module.exports = async function (name, _variant, meta, force) {
if (!force) {
const htmlFile = `${__dirname}/../docs/${name}/${name}.html`;
const pdfFile = `${__dirname}/../docs/${name}/${name}.pdf`;
Expand Down
78 changes: 35 additions & 43 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pandoc = require("./pandoc");
const http = require("http");
const { execSync } = require("child_process");
const path = require("path");
const fs = require("fs");
const iterator = require("./iterator");

const livereload = require("livereload");
const liveReloadServer = livereload.createServer({ extraExts: ["md"] });
Expand All @@ -14,50 +14,42 @@ const connectLivereload = require("connect-livereload");

var app = express()
.use(connectLivereload())
.use(express.static(__dirname + "/../docs"))
.get("/", function (req, res, next) {
const docs = fs
.readdirSync(__dirname + "/..", { withFileTypes: true })
.filter((doc) => doc.isDirectory() && doc.name.startsWith("odata-"))
.map((doc) => `<li><a href="${doc.name}">${doc.name}</a></li>`);
.use("/styles", express.static(`${__dirname}/../styles`))
.get("/", function (_req, res, _next) {
var docs = [];
iterator(function (srcname, name, variant) {
docs.push(`<li><a href="${srcname}?variant=${variant}">${name}</a></li>`);
});
res.send(`<h1>Documents</h1><ul>${docs.join("")}</ul>`);
})
.get("/*", function (req, res, next) {
if (req.path.endsWith("/")) {
try {
var branch = execSync("git branch --show-current", {
cwd: __dirname,
}).toString();
if (branch) req.query["-T"] = branch;
} catch (e) {}
var dir = req.params[0].substring(0, req.params[0].length - 1);
try {
var number = new Number(__dirname + "/../" + dir, req.query.variant);
var meta =
__dirname +
"/../" +
dir +
"/" +
(req.query.variant || "meta") +
".yaml";
delete req.query.variant;
res.type("html");
var proc = pandoc({
"--metadata-file": meta,
...req.query,
});
proc.stdout.pipe(res);
number.build(proc.stdin).catch((err) => {
console.error();
console.error(err.join("\n"));
});
} catch (err) {
next();
}
} else {
var url = new URL("s://" + req.originalUrl);
url.pathname += "/";
res.redirect(url.href.substring(4));
.get("/:doc", function (req, res, next) {
try {
var branch = execSync("git branch --show-current", {
cwd: __dirname,
}).toString();
if (branch) req.query["-T"] = branch;
} catch (e) {}
try {
var number = new Number(
__dirname + "/../" + req.params.doc,
req.query.variant
);
var meta = `${__dirname}/../${req.params.doc}/${
req.query.variant || "meta"
}.yaml`;
delete req.query.variant;
res.type("html");
var proc = pandoc({
"--metadata-file": meta,
...req.query,
});
proc.stdout.pipe(res);
number.build(proc.stdin).catch((err) => {
console.error();
console.error(err.join("\n"));
});
} catch (err) {
next();
}
});

Expand Down
Loading

0 comments on commit dbe0f49

Please sign in to comment.