mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 10:03:45 +03:00
fix: definition name util (#1865)
* fix: definition name util * update snapshot
This commit is contained in:
parent
3e47932754
commit
95a7347931
|
@ -752,7 +752,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"required": Array [
|
"required": Array [
|
||||||
"type",
|
"type",
|
||||||
],
|
],
|
||||||
"title": "schemas",
|
"title": "Dog",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
"title": "Dog",
|
"title": "Dog",
|
||||||
|
@ -1488,7 +1488,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"required": Array [
|
"required": Array [
|
||||||
"type",
|
"type",
|
||||||
],
|
],
|
||||||
"title": "schemas",
|
"title": "Cat",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
"title": "Cat",
|
"title": "Cat",
|
||||||
|
@ -2454,7 +2454,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
||||||
"required": Array [
|
"required": Array [
|
||||||
"type",
|
"type",
|
||||||
],
|
],
|
||||||
"title": "schemas",
|
"title": "Dog",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
},
|
},
|
||||||
"title": "Dog",
|
"title": "Dog",
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
sortByRequired,
|
sortByRequired,
|
||||||
humanizeNumberRange,
|
humanizeNumberRange,
|
||||||
getContentWithLegacyExamples,
|
getContentWithLegacyExamples,
|
||||||
|
getDefinitionName,
|
||||||
} from '../';
|
} from '../';
|
||||||
|
|
||||||
import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
|
import { FieldModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
|
||||||
|
@ -1269,4 +1270,14 @@ describe('Utils', () => {
|
||||||
expect(content['text/plain']).toStrictEqual(info.content['text/plain']);
|
expect(content['text/plain']).toStrictEqual(info.content['text/plain']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getDefinitionName', () => {
|
||||||
|
test('should return the name if pointer match regex', () => {
|
||||||
|
expect(getDefinitionName('#/components/schemas/Call')).toEqual('Call');
|
||||||
|
});
|
||||||
|
test("should return the `undefined` if pointer not match regex or it's absent", () => {
|
||||||
|
expect(getDefinitionName('#/test/path/Call')).toBeUndefined();
|
||||||
|
expect(getDefinitionName()).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -384,14 +384,15 @@ export function langFromMime(contentType: string): string {
|
||||||
return 'clike';
|
return 'clike';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFINITION_NAME_REGEX = /^#\/components\/(schemas|pathItems)\/([^/]+)$/;
|
||||||
|
|
||||||
export function isNamedDefinition(pointer?: string): boolean {
|
export function isNamedDefinition(pointer?: string): boolean {
|
||||||
return /^#\/components\/(schemas|pathItems)\/[^\/]+$/.test(pointer || '');
|
return DEFINITION_NAME_REGEX.test(pointer || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefinitionName(pointer?: string): string | undefined {
|
export function getDefinitionName(pointer?: string): string | undefined {
|
||||||
if (!pointer) return undefined;
|
const [name] = pointer?.match(DEFINITION_NAME_REGEX)?.reverse() || [];
|
||||||
const match = pointer.match(/^#\/components\/(schemas|pathItems)\/([^\/]+)$/);
|
return name;
|
||||||
return match === null ? undefined : match[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function humanizeMultipleOfConstraint(multipleOf: number | undefined): string | undefined {
|
function humanizeMultipleOfConstraint(multipleOf: number | undefined): string | undefined {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user