mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Support references pointing to invalid files (#2930)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/openapi-parser': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support references pointing to invalid files
|
||||||
@@ -17,10 +17,13 @@ describe('#createFileSystem', () => {
|
|||||||
'/root/spec.yaml': await serveFixture('/remote-ref/root/spec.yaml'),
|
'/root/spec.yaml': await serveFixture('/remote-ref/root/spec.yaml'),
|
||||||
'/root/user.yaml': await serveFixture('/remote-ref/root/user.yaml'),
|
'/root/user.yaml': await serveFixture('/remote-ref/root/user.yaml'),
|
||||||
'/root/pet.yaml': await serveFixture('/remote-ref/root/pet.yaml'),
|
'/root/pet.yaml': await serveFixture('/remote-ref/root/pet.yaml'),
|
||||||
|
'/root/invalid.yaml': await serveFixture('/remote-ref/root/invalid.txt'),
|
||||||
'/tag.yaml': await serveFixture('/remote-ref/tag.yaml'),
|
'/tag.yaml': await serveFixture('/remote-ref/tag.yaml'),
|
||||||
},
|
},
|
||||||
fetch() {
|
fetch() {
|
||||||
return new Response('404!');
|
return new Response('<404>', {
|
||||||
|
status: 404,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
port: 3020,
|
port: 3020,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{ "invalid" <> }
|
||||||
@@ -676,19 +676,6 @@ components:
|
|||||||
xml:
|
xml:
|
||||||
name: address
|
name: address
|
||||||
type: object
|
type: object
|
||||||
Category:
|
|
||||||
x-swagger-router-model: io.swagger.petstore.model.Category
|
|
||||||
properties:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
example: 1
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
example: Dogs
|
|
||||||
xml:
|
|
||||||
name: category
|
|
||||||
type: object
|
|
||||||
User:
|
User:
|
||||||
$ref: 'user.yaml#/components/schemas/User'
|
$ref: 'user.yaml#/components/schemas/User'
|
||||||
Tag:
|
Tag:
|
||||||
@@ -696,17 +683,9 @@ components:
|
|||||||
Pet:
|
Pet:
|
||||||
$ref: 'http://localhost:3020/root/pet.yaml#/components/schemas/Pet'
|
$ref: 'http://localhost:3020/root/pet.yaml#/components/schemas/Pet'
|
||||||
ApiResponse:
|
ApiResponse:
|
||||||
properties:
|
$ref: 'http://localhost:3020/root/not-found.yaml'
|
||||||
code:
|
Category:
|
||||||
type: integer
|
$ref: 'http://localhost:3020/root/invalid.txt'
|
||||||
format: int32
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
xml:
|
|
||||||
name: '##default'
|
|
||||||
type: object
|
|
||||||
requestBodies:
|
requestBodies:
|
||||||
Pet:
|
Pet:
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { LoadPlugin } from '@scalar/openapi-parser';
|
import { type LoadPlugin, normalize } from '@scalar/openapi-parser';
|
||||||
|
|
||||||
export const fetchUrlsDefaultConfiguration = {
|
export const fetchUrlsDefaultConfiguration = {
|
||||||
limit: 40,
|
limit: 40,
|
||||||
@@ -52,7 +52,13 @@ export const fetchURLs: (customConfiguration: {
|
|||||||
numberOfRequests++;
|
numberOfRequests++;
|
||||||
const url = getReferenceUrl({ value, rootURL: configuration.rootURL });
|
const url = getReferenceUrl({ value, rootURL: configuration.rootURL });
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
return await response.text();
|
if (!response.ok) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const text = await response.text();
|
||||||
|
// Try to normalize the text to be sure it's a valid JSON or YAML.
|
||||||
|
await normalize(text);
|
||||||
|
return text;
|
||||||
} catch (_error: any) {
|
} catch (_error: any) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user