@balena/pinejs 21.1.0-build-odata-metadata-json-395a55cb54e7b9ce0960ab93aad5f69d6c0e0462-2 → 21.1.0-build-key-left-join-890e86b168483d6158e251ab2c0d7e41b8bd50ae-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,98 +0,0 @@
1
- import * as odataMetadata from 'odata-openapi';
2
- import type { generateODataMetadata } from './odata-metadata-generator.js';
3
- import _ from 'lodash';
4
-
5
- export const generateODataMetadataAsOpenApi = (
6
- odataCsdl: ReturnType<typeof generateODataMetadata>,
7
- versionBasePathUrl = '',
8
- hostname = '',
9
- ) => {
10
- // console.log(`odataCsdl:${JSON.stringify(odataCsdl, null, 2)}`);
11
- const openAPIJson: any = odataMetadata.csdl2openapi(odataCsdl, {
12
- scheme: 'https',
13
- host: hostname,
14
- basePath: versionBasePathUrl,
15
- diagram: false,
16
- maxLevels: 5,
17
- });
18
-
19
- /**
20
- * Manual rewriting OpenAPI specification to delete OData default functionality
21
- * that is not implemented in Pinejs yet or is based on PineJs implements OData V3.
22
- *
23
- * Rewrite odata body response schema properties from `value: ` to `d: `
24
- * Currently pinejs is returning `d: `
25
- * https://www.odata.org/documentation/odata-version-2-0/json-format/ (6. Representing Collections of Entries)
26
- * https://www.odata.org/documentation/odata-version-3-0/json-verbose-format/ (6.1 Response body)
27
- *
28
- * New v4 odata specifies the body response with `value: `
29
- * http://docs.oasis-open.org/odata/odata-json-format/v4.01/odata-json-format-v4.01.html#sec_IndividualPropertyorOperationRespons
30
- *
31
- *
32
- * Currently pinejs does not implement a $count=true query parameter as this would return the count of all rows returned as an additional parameter.
33
- * This was not part of OData V3 and is new for OData V4. As the odata-openapi converte is opionionated on V4 the parameter is put into the schema.
34
- * Until this is in parity with OData V4 pinejs needs to cleanup the `odata.count` key from the response schema put in by `csdl2openapi`
35
- *
36
- *
37
- * Used oasis translator generates openapi according to v4 spec (`value: `)
38
- *
39
- * Unfortunantely odata-openapi does not export the genericFilter object.
40
- * Using hardcoded generic filter description as used in odata-openapi code.
41
- * Putting the genericFilter into the #/components/parameters/filter to reference it from paths
42
- *
43
- * */
44
- const parameters = openAPIJson?.components?.parameters;
45
- parameters['filter'] = {
46
- name: '$filter',
47
- description:
48
- 'Filter items by property values, see [Filtering](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_SystemQueryOptionfilter)',
49
- in: 'query',
50
- schema: {
51
- type: 'string',
52
- },
53
- };
54
-
55
- for (const idx of Object.keys(openAPIJson.paths)) {
56
- // rewrite `value: ` to `d: `
57
- const properties =
58
- openAPIJson?.paths[idx]?.get?.responses?.['200']?.content?.[
59
- 'application/json'
60
- ]?.schema?.properties;
61
- if (properties?.value) {
62
- properties['d'] = properties.value;
63
- delete properties.value;
64
- }
65
-
66
- // cleanup the `odata.count` key from the response schema
67
- if (properties?.['@odata.count']) {
68
- delete properties['@odata.count'];
69
- }
70
-
71
- // copy over 'delete' and 'patch' action from single entiy path
72
- // odata-openAPI converter does not support collection delete and collection update.
73
- // pinejs support collection delete and update with $filter parameter
74
- const entityCollectionPath = openAPIJson?.paths[idx];
75
- const singleEntityPath = openAPIJson?.paths[idx + '({id})'];
76
- if (entityCollectionPath != null && singleEntityPath != null) {
77
- const genericFilterParameterRef = {
78
- $ref: '#/components/parameters/filter',
79
- };
80
- for (const action of ['delete', 'patch']) {
81
- entityCollectionPath[action] = _.clone(singleEntityPath?.[action]);
82
- if (entityCollectionPath[action]) {
83
- entityCollectionPath[action]['parameters'] = [
84
- genericFilterParameterRef,
85
- ];
86
- }
87
- }
88
- }
89
- }
90
-
91
- // cleanup $batch path as pinejs does not implement it.
92
- // http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_BatchRequests
93
- if (openAPIJson?.paths['/$batch']) {
94
- delete openAPIJson.paths['/$batch'];
95
- }
96
-
97
- return openAPIJson;
98
- };
@@ -1,6 +0,0 @@
1
- declare module 'odata-openapi' {
2
- export const csdl2openapi: (
3
- csdl,
4
- { scheme, host, basePath, diagram, maxLevels } = {},
5
- ) => object;
6
- }