@api-platform/api-doc-parser
Advanced tools
Comparing version 0.16.1 to 0.16.2
import type { Resource } from "./Resource.js"; | ||
import type { Nullable } from "./types.js"; | ||
export declare type FieldType = "string" | "integer" | "negativeInteger" | "nonNegativeInteger" | "positiveInteger" | "nonPositiveInteger" | "number" | "decimal" | "double" | "float" | "boolean" | "date" | "dateTime" | "duration" | "time" | "byte" | "binary" | "hexBinary" | "base64Binary" | "array" | "object" | "email" | "url" | "uuid" | "password" | string; | ||
export type FieldType = "string" | "integer" | "negativeInteger" | "nonNegativeInteger" | "positiveInteger" | "nonPositiveInteger" | "number" | "decimal" | "double" | "float" | "boolean" | "date" | "dateTime" | "duration" | "time" | "byte" | "binary" | "hexBinary" | "base64Binary" | "array" | "object" | "email" | "url" | "uuid" | "password" | string; | ||
export interface FieldOptions extends Nullable<{ | ||
@@ -5,0 +5,0 @@ id?: string; |
import type { Document, RemoteDocument } from "jsonld/jsonld-spec"; | ||
import type { RequestInitExtended } from "./types.js"; | ||
export declare type RejectedResponseDocument = { | ||
export type RejectedResponseDocument = { | ||
response: Response; | ||
}; | ||
export declare type EmptyResponseDocument = { | ||
export type EmptyResponseDocument = { | ||
response: Response; | ||
@@ -8,0 +8,0 @@ }; |
import { __awaiter } from "tslib"; | ||
const jsonLdMimeType = "application/ld+json"; | ||
const jsonProblemMimeType = "application/problem+json"; | ||
/** | ||
@@ -14,3 +15,6 @@ * Sends a JSON-LD request to the API. | ||
} | ||
if (500 <= status || !contentType || !contentType.includes(jsonLdMimeType)) { | ||
if (500 <= status || | ||
!contentType || | ||
(!contentType.includes(jsonLdMimeType) && | ||
!contentType.includes(jsonProblemMimeType))) { | ||
const reason = { response }; | ||
@@ -17,0 +21,0 @@ return Promise.reject(reason); |
@@ -37,3 +37,3 @@ import { __awaiter } from "tslib"; | ||
} | ||
const matches = /<(.+)>; rel="http:\/\/www.w3.org\/ns\/hydra\/core#apiDocumentation"/.exec(linkHeader); | ||
const matches = /<([^<]+)>; rel="http:\/\/www.w3.org\/ns\/hydra\/core#apiDocumentation"/.exec(linkHeader); | ||
if (matches === null) { | ||
@@ -40,0 +40,0 @@ throw new Error('The "Link" HTTP header is not of the type "http://www.w3.org/ns/hydra/core#apiDocumentation".'); |
export interface RequestInitExtended extends Omit<RequestInit, "headers"> { | ||
headers?: HeadersInit | (() => HeadersInit); | ||
} | ||
export declare type IriTemplateMapping = { | ||
export type IriTemplateMapping = { | ||
"@type": "IriTemplateMapping"; | ||
@@ -10,3 +10,3 @@ variable: "string"; | ||
}; | ||
export declare type ExpandedOperation = { | ||
export type ExpandedOperation = { | ||
"@type": ["http://www.w3.org/ns/hydra/core#Operation"]; | ||
@@ -44,3 +44,3 @@ "http://www.w3.org/2000/01/rdf-schema#label": [ | ||
}; | ||
export declare type ExpandedRdfProperty = { | ||
export type ExpandedRdfProperty = { | ||
"@id": string; | ||
@@ -92,3 +92,3 @@ "@type": [ | ||
}; | ||
export declare type ExpandedSupportedProperty = { | ||
export type ExpandedSupportedProperty = { | ||
"@type": ["http://www.w3.org/ns/hydra/core#SupportedProperty"]; | ||
@@ -127,3 +127,3 @@ "http://www.w3.org/ns/hydra/core#title": [ | ||
}; | ||
export declare type ExpandedClass = { | ||
export type ExpandedClass = { | ||
"@id": string; | ||
@@ -159,3 +159,3 @@ "@type": ["http://www.w3.org/ns/hydra/core#Class"]; | ||
}; | ||
export declare type ExpandedDoc = { | ||
export type ExpandedDoc = { | ||
"@id": string; | ||
@@ -180,3 +180,3 @@ "@type": ["http://www.w3.org/ns/hydra/core#ApiDocumentation"]; | ||
}; | ||
export declare type Entrypoint = { | ||
export type Entrypoint = { | ||
"@id": string; | ||
@@ -183,0 +183,0 @@ "@type": [string]; |
import type { Nullable } from "./types.js"; | ||
export declare type OperationType = "show" | "edit" | "delete" | "list" | "create"; | ||
export type OperationType = "show" | "edit" | "delete" | "list" | "create"; | ||
export interface OperationOptions extends Nullable<{ | ||
@@ -4,0 +4,0 @@ method?: string; |
@@ -1,4 +0,4 @@ | ||
export declare type Nullable<T extends Record<string, unknown>> = { | ||
export type Nullable<T extends Record<string, unknown>> = { | ||
[P in keyof T]: T[P] | null; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -5,5 +5,5 @@ interface ResourceValue { | ||
} | ||
declare type ParsedJsonReplacerResult = ResourceValue | string | null; | ||
type ParsedJsonReplacerResult = ResourceValue | string | null; | ||
declare const parsedJsonReplacer: (key: string, value: null | ResourceValue) => ParsedJsonReplacerResult; | ||
export default parsedJsonReplacer; | ||
//# sourceMappingURL=parsedJsonReplacer.d.ts.map |
{ | ||
"name": "@api-platform/api-doc-parser", | ||
"version": "0.16.1", | ||
"version": "0.16.2", | ||
"description": "Transform an API documentation (Hydra, OpenAPI, GraphQL) in an intermediate representation that can be used for various tasks such as creating smart API clients, scaffolding code or building administration interfaces.", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -46,3 +46,3 @@ import fetchJsonLd from "./fetchJsonLd.js"; | ||
test("fetch an error", () => { | ||
test("fetch an error with Content-Type application/ld+json", () => { | ||
fetchMock.mockResponseOnce( | ||
@@ -73,2 +73,28 @@ `{ | ||
test("fetch an error with Content-Type application/error+json", () => { | ||
fetchMock.mockResponseOnce( | ||
`{ | ||
"@context": "http://json-ld.org/contexts/person.jsonld", | ||
"@id": "http://dbpedia.org/resource/John_Lennon", | ||
"name": "John Lennon", | ||
"born": "1940-10-09", | ||
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon" | ||
}`, | ||
{ | ||
status: 400, | ||
statusText: "Bad Request", | ||
headers: { "Content-Type": "application/error+json" }, | ||
} | ||
); | ||
return fetchJsonLd("/foo.jsonld").catch( | ||
({ response }: { response: Response }) => { | ||
void response.json().then((body: { born: string }) => { | ||
expect(response.ok).toBe(false); | ||
expect(body.born).toBe("1940-10-09"); | ||
}); | ||
} | ||
); | ||
}); | ||
test("fetch an empty document", () => { | ||
@@ -75,0 +101,0 @@ fetchMock.mockResponseOnce("", { |
@@ -5,2 +5,3 @@ import type { Document, JsonLd, RemoteDocument } from "jsonld/jsonld-spec"; | ||
const jsonLdMimeType = "application/ld+json"; | ||
const jsonProblemMimeType = "application/problem+json"; | ||
@@ -35,3 +36,8 @@ export type RejectedResponseDocument = { | ||
if (500 <= status || !contentType || !contentType.includes(jsonLdMimeType)) { | ||
if ( | ||
500 <= status || | ||
!contentType || | ||
(!contentType.includes(jsonLdMimeType) && | ||
!contentType.includes(jsonProblemMimeType)) | ||
) { | ||
const reason: RejectedResponseDocument = { response }; | ||
@@ -38,0 +44,0 @@ return Promise.reject(reason); |
@@ -16,4 +16,4 @@ import get from "lodash.get"; | ||
"body.hydra:search.hydra:mapping" | ||
) as IriTemplateMapping[], | ||
) as unknown as IriTemplateMapping[], | ||
})); | ||
}; |
@@ -1298,3 +1298,3 @@ import parseHydraDocumentation from "./parseHydraDocumentation.js"; | ||
headers: { | ||
Link: '<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"', | ||
Link: '<http://example.com/docs>; rel="http://example.com",<http://localhost/docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation"', | ||
"Content-Type": "application/ld+json", | ||
@@ -1301,0 +1301,0 @@ }, |
@@ -62,3 +62,3 @@ import jsonld from "jsonld"; | ||
const matches = | ||
/<(.+)>; rel="http:\/\/www.w3.org\/ns\/hydra\/core#apiDocumentation"/.exec( | ||
/<([^<]+)>; rel="http:\/\/www.w3.org\/ns\/hydra\/core#apiDocumentation"/.exec( | ||
linkHeader | ||
@@ -153,7 +153,7 @@ ); | ||
'["http://www.w3.org/2002/07/owl#equivalentClass"][0]["http://www.w3.org/2002/07/owl#onProperty"][0]["@id"]' | ||
) as string; | ||
) as unknown as string; | ||
const allValuesFrom = get( | ||
range, | ||
'["http://www.w3.org/2002/07/owl#equivalentClass"][0]["http://www.w3.org/2002/07/owl#allValuesFrom"][0]["@id"]' | ||
) as string; | ||
) as unknown as string; | ||
@@ -261,3 +261,3 @@ if ( | ||
'["http://www.w3.org/ns/hydra/core#property"][0]' | ||
) as ExpandedRdfProperty; | ||
) as unknown as ExpandedRdfProperty; | ||
const id = supportedProperty["@id"]; | ||
@@ -268,3 +268,3 @@ const range = get( | ||
null | ||
) as string; | ||
) as unknown as string; | ||
@@ -271,0 +271,0 @@ const field = new Field( |
@@ -13,4 +13,5 @@ import { parse as dereference } from "jsonref"; | ||
const isRef = <T>(maybeRef: T | OpenAPIV3.ReferenceObject): maybeRef is T => | ||
!("$ref" in maybeRef); | ||
const isRef = <T extends object>( | ||
maybeRef: T | OpenAPIV3.ReferenceObject | ||
): maybeRef is T => !("$ref" in maybeRef); | ||
@@ -184,3 +185,3 @@ export const removeTrailingSlash = (url: string): string => { | ||
"requestBody.content.application/json.schema" | ||
) as OpenAPIV3.SchemaObject) | ||
) as unknown as OpenAPIV3.SchemaObject) | ||
: null; | ||
@@ -187,0 +188,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276330
7085