@mintlify/validation
Advanced tools
Comparing version 0.1.117 to 0.1.118
@@ -14,3 +14,4 @@ import { OpenAPIV3_1 } from 'openapi-types'; | ||
private convertResponses; | ||
private convertCodeSamples; | ||
static convert(spec: OpenAPIV3_1.Document, path: string, method: HttpMethod, safeParse?: boolean): Endpoint | undefined; | ||
} |
@@ -43,2 +43,3 @@ import { BaseConverter } from './BaseConverter.js'; | ||
const deprecated = !!operationObject.deprecated; | ||
const codeSamples = this.convertCodeSamples(['#', 'paths', this.path, this.method], operationObject); | ||
const response = this.convertResponses(['#', 'paths', this.path, this.method, 'responses'], operationObject.responses); | ||
@@ -55,2 +56,3 @@ return { | ||
body, | ||
codeSamples, | ||
}, | ||
@@ -104,2 +106,41 @@ response, | ||
} | ||
convertCodeSamples(debugPath, operation) { | ||
let key; | ||
let rawCodeSamples; | ||
if ('x-codeSamples' in operation) { | ||
rawCodeSamples = operation['x-codeSamples']; | ||
key = 'x-codeSamples'; | ||
} | ||
else if ('x-code-samples' in operation) { | ||
rawCodeSamples = operation['x-code-samples']; | ||
key = 'x-code-samples'; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
if (!Array.isArray(rawCodeSamples)) { | ||
this.handleNewError(InvalidSchemaError, [...debugPath, key], `${key} must be an array`); | ||
return; | ||
} | ||
const codeSamples = []; | ||
rawCodeSamples.forEach((codeSample) => { | ||
if (!codeSample || | ||
typeof codeSample !== 'object' || | ||
!('source' in codeSample) || | ||
typeof codeSample.source !== 'string' || | ||
!('lang' in codeSample) || | ||
typeof codeSample.lang !== 'string') { | ||
this.handleNewError(InvalidSchemaError, [...debugPath, key], 'invalid code sample'); | ||
return; | ||
} | ||
codeSamples.push({ | ||
label: 'label' in codeSample && typeof codeSample.label === 'string' | ||
? codeSample.label | ||
: undefined, | ||
lang: codeSample['lang'].toLowerCase(), | ||
source: codeSample['source'], | ||
}); | ||
}); | ||
return codeSamples; | ||
} | ||
static convert(spec, path, method, safeParse) { | ||
@@ -106,0 +147,0 @@ return new OpenApiToEndpointConverter(spec, path, method, safeParse).convert(); |
@@ -35,3 +35,9 @@ export type Endpoint = { | ||
body: BodySchema; | ||
codeSamples?: CodeSample[]; | ||
}; | ||
export type CodeSample = { | ||
label?: string; | ||
lang: string; | ||
source: string; | ||
}; | ||
export type BodySchema = { | ||
@@ -38,0 +44,0 @@ [contentType: string]: ContentSchema; |
{ | ||
"name": "@mintlify/validation", | ||
"version": "0.1.117", | ||
"version": "0.1.118", | ||
"description": "Validates mint.json files", | ||
@@ -72,3 +72,3 @@ "author": "Mintlify, Inc.", | ||
}, | ||
"gitHead": "e316deba89f166b69f5c5d94c3122f6f1d54a848" | ||
"gitHead": "168db52ca32ca45c5b7f1b47a2b1f6e1b33eaf3d" | ||
} |
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
214582
3935