-
Notifications
You must be signed in to change notification settings - Fork 200
fix(core): fix bug loading of .redocly.lint-ignore.yaml in browser environments
#2489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
53e4d61
323e239
f0491ec
04aff2e
80c55f0
b12cd36
25d06f0
dd80539
fb47186
0f336e4
a12049c
2d024cc
4a53e67
4465598
83bf54c
8cc6944
12cfd27
d85e099
cf41d7b
2c56788
483b4d1
aa636ba
1b0ddb8
a2514c0
4260ee7
d3abf6f
0f7eb30
42a85f6
236f083
d64b3ac
4a988ea
a67636b
76e98ee
a4aeeef
0908c72
aad5b73
5a026f5
84c82cf
0ee91d4
876d5ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@redocly/openapi-core": patch | ||
| --- | ||
|
|
||
| Fixed an issue where `.redocly.lint-ignore.yaml` was not loaded in browser environments. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| api.yaml: | ||
| operation-operationId: | ||
| - '#/paths/~1pets/get/operationId' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /pets: | ||
| get: | ||
| operationId: '' | ||
| summary: Get pets | ||
| responses: | ||
| '200': | ||
| description: OK |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| rules: | ||
| operation-operationId: error | ||
| operation-summary: error | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,58 @@ import { | |
| type Document, | ||
| type ResolvedRefMap, | ||
| } from '../resolve.js'; | ||
| import { CONFIG_FILE_NAME } from './constants.js'; | ||
| import { CONFIG_FILE_NAME, IGNORE_FILE } from './constants.js'; | ||
| import { isAbsoluteUrlOrFileUrl, getDir } from '../ref-utils.js'; | ||
|
|
||
| import type { RawUniversalConfig } from './types.js'; | ||
|
|
||
| function resolvePath(base: string, relative: string): string { | ||
tatomyr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (isAbsoluteUrlOrFileUrl(base)) { | ||
| return new URL(relative, base.endsWith('/') ? base : `${base}/`).href; | ||
| } | ||
| return path.resolve(base, relative); | ||
| } | ||
|
|
||
| async function loadIgnoreFile( | ||
| configPath: string | undefined, | ||
| resolver: BaseResolver | ||
| ): Promise<Record<string, Record<string, Set<string>>> | undefined> { | ||
| if (!configPath) return undefined; | ||
|
|
||
| const configDir = getDir(configPath); | ||
| const ignorePath = resolvePath(configDir, IGNORE_FILE); | ||
|
||
|
|
||
| if (fs?.existsSync && !isAbsoluteUrlOrFileUrl(ignorePath) && !fs.existsSync(ignorePath)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const ignoreDocument = await resolver.resolveDocument(null, ignorePath, true); | ||
|
|
||
| if (ignoreDocument instanceof Error || !ignoreDocument.parsed) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const ignore = (ignoreDocument.parsed || {}) as Record<string, Record<string, Set<string>>>; | ||
|
|
||
| for (const fileName of Object.keys(ignore)) { | ||
| const resolvedFileName = isAbsoluteUrlOrFileUrl(fileName) | ||
| ? fileName | ||
| : resolvePath(configDir, fileName); | ||
|
|
||
| ignore[resolvedFileName] = ignore[fileName]; | ||
|
|
||
| for (const ruleId of Object.keys(ignore[fileName])) { | ||
| ignore[fileName][ruleId] = new Set(ignore[fileName][ruleId]); | ||
| } | ||
|
|
||
| if (resolvedFileName !== fileName) { | ||
| delete ignore[fileName]; | ||
| } | ||
| } | ||
|
|
||
| return ignore; | ||
| } | ||
|
|
||
| export async function loadConfig( | ||
| options: { | ||
| configPath?: string; | ||
|
|
@@ -38,11 +86,14 @@ export async function loadConfig( | |
| externalRefResolver, | ||
| }); | ||
|
|
||
| const ignore = await loadIgnoreFile(configPath, resolver); | ||
|
|
||
| const config = new Config(resolvedConfig, { | ||
| configPath, | ||
| document: rawConfigDocument, | ||
| resolvedRefMap: resolvedRefMap, | ||
| plugins, | ||
| ignore, | ||
| }); | ||
|
|
||
| return config; | ||
|
|
@@ -79,11 +130,16 @@ export async function createConfig( | |
| configPath, | ||
| externalRefResolver, | ||
| }); | ||
|
|
||
| const resolver = externalRefResolver ?? new BaseResolver(); | ||
tatomyr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const ignore = await loadIgnoreFile(configPath, resolver); | ||
|
|
||
| return new Config(resolvedConfig, { | ||
| configPath, | ||
| document: rawConfigDocument, | ||
| resolvedRefMap, | ||
| plugins, | ||
| ignore, | ||
| }); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.