mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[OpenAPI Type Generator] Exit with error if a $ref
contains a URL (#182175)
## Summary Closes https://github.com/elastic/kibana/issues/181948 We do not support URLs in `$ref` fields but we were previously exiting with success and generating an invalid .ts file. This makes the error more explicit. I have also removed the reference which drew our attention to this bug. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Pablo Machado <pablo.nevesmachado@elastic.co>
This commit is contained in:
parent
b40b6d81f2
commit
c49cb1fa9e
3 changed files with 16 additions and 6 deletions
|
@ -20,9 +20,21 @@ const hasRef = (obj: unknown): obj is NormalizedReferenceObject => {
|
|||
return typeof obj === 'object' && obj !== null && '$ref' in obj;
|
||||
};
|
||||
|
||||
const stringIsUrl = (str: string) => {
|
||||
try {
|
||||
new URL(str);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export function normalizeSchema(schema: OpenAPIV3.Document) {
|
||||
traverseObject(schema, (element) => {
|
||||
if (hasRef(element)) {
|
||||
if (stringIsUrl(element.$ref)) {
|
||||
throw new Error(`URL references are not supported: ${element.$ref}`);
|
||||
}
|
||||
const referenceName = element.$ref.split('/').pop();
|
||||
if (!referenceName) {
|
||||
throw new Error(`Cannot parse reference name: ${element.$ref}`);
|
||||
|
|
|
@ -29,10 +29,10 @@ export type DataViewId = z.infer<typeof DataViewId>;
|
|||
export const DataViewId = z.string();
|
||||
|
||||
/**
|
||||
* An elasticsearch DSL filter object. Used to filter the risk inputs involved, which implicitly filters the risk scores themselves.
|
||||
* An elasticsearch DSL filter object. Used to filter the risk inputs involved, which implicitly filters the risk scores themselves. See https://cloud.elastic.co/api/v1/api-docs/spec.json#/definitions/QueryContainer
|
||||
*/
|
||||
export type Filter = z.infer<typeof Filter>;
|
||||
export const Filter = z.unknown();
|
||||
export const Filter = z.object({});
|
||||
|
||||
/**
|
||||
* Specifies how many scores will be involved in a given calculation. Note that this value is per `identifier_type`, i.e. a value of 10 will calculate 10 host scores and 10 user scores, if available. To avoid missed data, keep this value consistent while paginating through scores.
|
||||
|
|
|
@ -32,10 +32,8 @@ components:
|
|||
type: string
|
||||
|
||||
Filter:
|
||||
description: An elasticsearch DSL filter object. Used to filter the risk inputs involved, which implicitly filters the risk scores themselves.
|
||||
# TODO Fix the following line reference. Issue: https://github.com/elastic/kibana/issues/181948
|
||||
# $ref: 'https://cloud.elastic.co/api/v1/api-docs/spec.json#/definitions/QueryContainer'
|
||||
|
||||
type: object
|
||||
description: An elasticsearch DSL filter object. Used to filter the risk inputs involved, which implicitly filters the risk scores themselves. See https://cloud.elastic.co/api/v1/api-docs/spec.json#/definitions/QueryContainer
|
||||
|
||||
PageSize:
|
||||
description: Specifies how many scores will be involved in a given calculation. Note that this value is per `identifier_type`, i.e. a value of 10 will calculate 10 host scores and 10 user scores, if available. To avoid missed data, keep this value consistent while paginating through scores.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue