mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-13 09:42:23 +03:00
FBI-459: improvements
This commit is contained in:
parent
068ba23c00
commit
c4133cfdf5
|
@ -12,12 +12,14 @@ interface CsvExampleProps {
|
||||||
samplerOptions: object;
|
samplerOptions: object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasSameHeaders = (headers, sample) => Object.keys(sample).every(key => headers.includes(key));
|
||||||
|
|
||||||
const getCsvRows = (sample: OpenAPIExample): string => {
|
const getCsvRows = (sample: OpenAPIExample): string => {
|
||||||
const headers = Object.keys(sample?.[0] ?? sample).join(',');
|
const headers = Object.keys(sample?.[0] ?? sample).join(',');
|
||||||
// Ensure the schema has deterministic headers
|
// Ensure the schema has deterministic headers
|
||||||
const hasValidHeaders =
|
const hasValidHeaders = (Array.isArray(sample) ? sample : [sample]).every(row =>
|
||||||
!Array.isArray(sample) ||
|
hasSameHeaders(headers, row),
|
||||||
sample.every(row => Object.keys(row).every(key => headers.includes(key)));
|
);
|
||||||
if (!hasValidHeaders) return '';
|
if (!hasValidHeaders) return '';
|
||||||
|
|
||||||
let values;
|
let values;
|
||||||
|
@ -62,7 +64,7 @@ export const generateCsvExample = ({
|
||||||
exampleSummary: subSchema.title || schema.title || 'Example CSV',
|
exampleSummary: subSchema.title || schema.title || 'Example CSV',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (subSchema?.allOf) {
|
if (subSchema.allOf) {
|
||||||
const resolved: OpenAPISchema = {
|
const resolved: OpenAPISchema = {
|
||||||
...schema,
|
...schema,
|
||||||
items: parser.deref(subSchema.allOf as MergedOpenAPISchema).resolved,
|
items: parser.deref(subSchema.allOf as MergedOpenAPISchema).resolved,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user