passing specConfiguration to validator
This commit is contained in:
@@ -27,7 +27,7 @@ export function AppProvider({ specConfiguration, children }: AppProviderProps) {
|
|||||||
|
|
||||||
const spec = await loadSpec(specConfiguration.specUrl);
|
const spec = await loadSpec(specConfiguration.specUrl);
|
||||||
|
|
||||||
const allMessages = validateSpec(spec);
|
const allMessages = validateSpec(spec, specConfiguration);
|
||||||
|
|
||||||
const errs = allMessages.filter((m) => m.type === "error");
|
const errs = allMessages.filter((m) => m.type === "error");
|
||||||
const warns = allMessages.filter((m) => m.type === "warning");
|
const warns = allMessages.filter((m) => m.type === "warning");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { OpenApiSpec, ValidationMessage } from "./types";
|
import type { OpenApiSpec, ValidationMessage, SpecConfiguration } from "./types";
|
||||||
|
|
||||||
export function validateSpec(spec: OpenApiSpec): ValidationMessage[] {
|
export function validateSpec(spec: OpenApiSpec, specConfig?: SpecConfiguration): ValidationMessage[] {
|
||||||
const messages: ValidationMessage[] = [];
|
const messages: ValidationMessage[] = [];
|
||||||
const schemas = (spec.components?.schemas ?? {}) as Record<string, any>;
|
const schemas = (spec.components?.schemas ?? {}) as Record<string, any>;
|
||||||
const paths = spec.paths ?? {};
|
const paths = spec.paths ?? {};
|
||||||
@@ -13,7 +13,7 @@ export function validateSpec(spec: OpenApiSpec): ValidationMessage[] {
|
|||||||
messages.push({ type: "error", message: "Missing 'info.title'" });
|
messages.push({ type: "error", message: "Missing 'info.title'" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spec.servers?.[0]?.url) {
|
if (!spec.servers?.[0]?.url && !specConfig?.baseApiUrl) {
|
||||||
messages.push({ type: "warning", message: "No 'servers[0].url' defined — provide 'baseApiUrl' in specConfiguration" });
|
messages.push({ type: "warning", message: "No 'servers[0].url' defined — provide 'baseApiUrl' in specConfiguration" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user