Skip to content

Commit 185c836

Browse files
committed
fix: replace backslashes with forward slashes in refs on Windows when splitting
1 parent e1c065b commit 185c836

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

.github/workflows/smoke.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ env:
99
REDOCLY_TELEMETRY: off
1010

1111
jobs:
12+
# Common smokes
13+
1214
prepare-smoke:
1315
runs-on: ubuntu-latest
1416
steps:
@@ -283,6 +285,8 @@ jobs:
283285
node-version: 18
284286
- run: bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn"
285287

288+
# Separate smokes
289+
286290
run-smoke--docker-image:
287291
runs-on: ubuntu-latest
288292
steps:
@@ -303,3 +307,21 @@ jobs:
303307
echo "Docs built incorrectly. Received lines: $(wc -l redoc-static.html) (expected 324 lines in redoc-static.html)."
304308
exit 1
305309
fi
310+
311+
run-smoke--split--windows:
312+
runs-on: windows-latest
313+
steps:
314+
- uses: actions/checkout@v3
315+
- uses: actions/setup-node@v3
316+
with:
317+
node-version: 22
318+
cache: 'npm'
319+
- name: Prepare CLI
320+
run: npm ci && npm run compile && npm i -g redocly-cli.tgz
321+
- name: Run smoke
322+
run: |
323+
redocly --version
324+
redocly split resources/pets.yaml --outDir __tests__/smoke/__split-pets
325+
git diff
326+
redocly split resources/museum.yaml --outDir __tests__/smoke/__split-museum
327+
git diff

packages/cli/src/commands/split/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ function replace$Refs(obj: unknown, relativeFrom: string, componentFiles = {} as
176176
const groupName = splittedNode[2];
177177
const filesGroupName = componentFiles[groupName];
178178
if (!filesGroupName || !filesGroupName[name!]) return;
179-
let filename = path.relative(relativeFrom, filesGroupName[name!].filename);
179+
let filename = slash(path.relative(relativeFrom, filesGroupName[name!].filename));
180180
if (!filename.startsWith('.')) {
181-
filename = '.' + path.sep + filename;
181+
filename = './' + filename;
182182
}
183183
node[key] = filename;
184184
}
@@ -192,11 +192,11 @@ function implicitlyReferenceDiscriminator(
192192
) {
193193
if (!obj.discriminator) return;
194194
const defPtr = `#/${COMPONENTS}/${OPENAPI3_COMPONENT.Schemas}/${defName}`;
195-
const implicitMapping = {} as any;
195+
const implicitMapping: Record<string, string> = {};
196196
for (const [name, { inherits, filename: parentFilename }] of Object.entries(schemaFiles) as any) {
197197
if (inherits.indexOf(defPtr) > -1) {
198-
const res = path.relative(path.dirname(filename), parentFilename);
199-
implicitMapping[name] = res.startsWith('.') ? res : '.' + path.sep + res;
198+
const res = slash(path.relative(path.dirname(filename), parentFilename));
199+
implicitMapping[name] = res.startsWith('.') ? res : './' + res;
200200
}
201201
}
202202

@@ -258,7 +258,7 @@ function extractFileNameFromPath(filename: string) {
258258
}
259259

260260
function getFileNamePath(componentDirPath: string, componentName: string, ext: string) {
261-
return path.join(componentDirPath, componentName) + `.${ext}`;
261+
return slash(path.join(componentDirPath, componentName) + `.${ext}`);
262262
}
263263

264264
function gatherComponentsFiles(
@@ -273,7 +273,7 @@ function gatherComponentsFiles(
273273
inherits = (
274274
(components?.[componentType]?.[componentName] as Oas3Schema | Oas3_1Schema)?.allOf || []
275275
)
276-
.map(({ $ref }) => $ref)
276+
.map(({ $ref }) => $ref && slash($ref))
277277
.filter(isTruthy);
278278
}
279279
componentsFiles[componentType] = componentsFiles[componentType] || {};

0 commit comments

Comments
 (0)