mirror of
https://github.com/Redocly/redoc.git
synced 2024-12-03 05:43:44 +03:00
FBI-459: improvements
This commit is contained in:
parent
c4133cfdf5
commit
1d4c0dc242
|
@ -12,7 +12,8 @@ interface CsvExampleProps {
|
|||
samplerOptions: object;
|
||||
}
|
||||
|
||||
const hasSameHeaders = (headers, sample) => Object.keys(sample).every(key => headers.includes(key));
|
||||
const hasSameHeaders = (headers: string, sample: OpenAPIExample) =>
|
||||
Object.keys(sample).every(key => headers.includes(key));
|
||||
|
||||
const getCsvRows = (sample: OpenAPIExample): string => {
|
||||
const headers = Object.keys(sample?.[0] ?? sample).join(',');
|
||||
|
@ -22,10 +23,10 @@ const getCsvRows = (sample: OpenAPIExample): string => {
|
|||
);
|
||||
if (!hasValidHeaders) return '';
|
||||
|
||||
let values;
|
||||
let values: string;
|
||||
|
||||
if (Array.isArray(sample)) {
|
||||
values = sample.map(row => Object.values(row)).join('\n');
|
||||
values = sample.map(Object.values).join('\n');
|
||||
} else {
|
||||
values = Object.values(sample).join(',');
|
||||
}
|
||||
|
@ -33,7 +34,7 @@ const getCsvRows = (sample: OpenAPIExample): string => {
|
|||
};
|
||||
|
||||
const cleanUpExamples = (examples: Example[]): Example[] =>
|
||||
examples.filter(example => example.exampleValue !== '');
|
||||
examples.filter(({ exampleValue }) => exampleValue);
|
||||
|
||||
export const generateCsvExample = ({
|
||||
parser,
|
||||
|
@ -50,20 +51,20 @@ export const generateCsvExample = ({
|
|||
),
|
||||
);
|
||||
|
||||
const processSamplesWithSchema = subSchema => {
|
||||
if (subSchema) {
|
||||
const subItems = subSchema.items as OpenAPISchema;
|
||||
const processSamplesWithSchema = (subSchema: OpenAPISchema) => {
|
||||
if (!subSchema) {
|
||||
return;
|
||||
}
|
||||
|
||||
const subItems = subSchema.items as OpenAPISchema;
|
||||
if (subSchema.type === 'array' && subItems && depthCount < MAX_ITEM_DEPTH) {
|
||||
depthCount++;
|
||||
processSamplesWithSchema(subItems);
|
||||
}
|
||||
|
||||
const metadata = {
|
||||
exampleDescription: subSchema.description || schema.description || '',
|
||||
exampleSummary: subSchema.title || schema.title || 'Example CSV',
|
||||
};
|
||||
|
||||
if (subSchema.allOf) {
|
||||
const resolved: OpenAPISchema = {
|
||||
...schema,
|
||||
|
@ -110,7 +111,6 @@ export const generateCsvExample = ({
|
|||
...metadata,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (isValidSample) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user