Skip to content

Commit 6c0f5ea

Browse files
committed
tooling improvements
1 parent 758709b commit 6c0f5ea

File tree

12 files changed

+63621
-57421
lines changed

12 files changed

+63621
-57421
lines changed

cli

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env sh
22
# simple wrapper to the ./packages/b2c-cli/bin/dev.js script
3-
pushd ./packages/b2c-cli > /dev/null
4-
./bin/dev.js "$@"
5-
popd > /dev/null
3+
(cd ./packages/b2c-cli && ./bin/dev.js "$@")

packages/b2c-cli/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ oclif.manifest.json
1111
yarn.lock
1212
package-lock.json
1313

14-
14+
dw.json

packages/b2c-cli/src/commands/code/delete.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,7 @@ export default class CodeDelete extends InstanceCommand<typeof CodeDelete> {
7575
}),
7676
);
7777

78-
try {
79-
await deleteCodeVersion(this.instance, codeVersion);
80-
this.log(t('commands.code.delete.deleted', 'Code version {{codeVersion}} deleted successfully', {codeVersion}));
81-
} catch (error) {
82-
if (error instanceof Error) {
83-
this.error(
84-
t('commands.code.delete.failed', 'Failed to delete code version: {{message}}', {
85-
message: error.message,
86-
}),
87-
);
88-
}
89-
throw error;
90-
}
78+
await deleteCodeVersion(this.instance, codeVersion);
79+
this.log(t('commands.code.delete.deleted', 'Code version {{codeVersion}} deleted successfully', {codeVersion}));
9180
}
9281
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Fixes OCAPI OpenAPI spec for proper openapi-fetch typing:
4+
* 1. Converts 'default' responses to '200' for success typing
5+
* 2. Adds fault schema for error responses
6+
* 3. Adds 'default' error response referencing fault schema
7+
*/
8+
import fs from 'node:fs';
9+
import path from 'node:path';
10+
import {fileURLToPath} from 'node:url';
11+
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13+
const specFile = path.join(__dirname, '..', 'specs', 'data-api.json');
14+
15+
console.log(`Reading ${specFile}...`);
16+
const spec = JSON.parse(fs.readFileSync(specFile, 'utf-8'));
17+
18+
// Add fault schema based on OCAPI documentation
19+
const faultSchema = {
20+
type: 'object',
21+
description: 'OCAPI error/fault response returned for 4xx/5xx status codes',
22+
properties: {
23+
_v: {
24+
type: 'string',
25+
description: 'API version',
26+
},
27+
fault: {
28+
type: 'object',
29+
required: ['type', 'message'],
30+
properties: {
31+
type: {
32+
type: 'string',
33+
description: 'Error type identifier (e.g., NotFoundException, CodeVersionIdNotFoundException)',
34+
},
35+
message: {
36+
type: 'string',
37+
description: 'Human-readable error message',
38+
},
39+
arguments: {
40+
type: 'object',
41+
description: 'Map of argument values integrated into the message',
42+
additionalProperties: {
43+
type: 'object',
44+
properties: {
45+
type: {
46+
type: 'string',
47+
enum: ['boolean', 'date', 'datetime', 'decimal', 'integer', 'string', 'time'],
48+
},
49+
value: {},
50+
},
51+
},
52+
},
53+
},
54+
},
55+
},
56+
};
57+
58+
// Add fault schema to components
59+
if (!spec.components) spec.components = {};
60+
if (!spec.components.schemas) spec.components.schemas = {};
61+
spec.components.schemas.fault = faultSchema;
62+
63+
let transformedCount = 0;
64+
65+
// Transform all paths
66+
for (const pathItem of Object.values(spec.paths || {})) {
67+
for (const [method, operation] of Object.entries(pathItem)) {
68+
if (method === 'parameters') continue;
69+
if (!operation.responses) continue;
70+
71+
// Convert 'default' to '200' if no 200 exists
72+
if (operation.responses.default && !operation.responses['200']) {
73+
operation.responses['200'] = operation.responses.default;
74+
delete operation.responses.default;
75+
}
76+
77+
// Add default error response if not present
78+
if (!operation.responses.default) {
79+
operation.responses.default = {
80+
description: 'Error response',
81+
content: {
82+
'application/json': {
83+
schema: {
84+
$ref: '#/components/schemas/fault',
85+
},
86+
},
87+
},
88+
};
89+
transformedCount++;
90+
}
91+
}
92+
}
93+
94+
console.log(`Added fault schema and ${transformedCount} default error responses`);
95+
96+
fs.writeFileSync(specFile, JSON.stringify(spec, null, 2));
97+
console.log(`Updated ${specFile}`);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OAS Schemas
2+
3+
This directory contains OpenAPI Specification (OAS) schemas used for defining and documenting APIs in the B2C tooling ecosystem. These are retrieved from public sources
4+
5+
## OCAPI
6+
7+
Note that the OCAPI DATA schema in ./data-api.json is a modified version adapted from the original Swagger 2.0 to OAS 3.0 and postprocessed to improve compatibility with openapi-fetch tooling. See ../scripts/fix-ocapi-spec.js

0 commit comments

Comments
 (0)