mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
@kbn/openapi-generator: Support object keys which need to be surrounded by quotes (#172049)
## Summary ❓ Are there tests for @kbn/openapi-generator? I couldn't find them ❓ Our team had a `@timestamp` field in an API response, this caused the zod schema to break because the key was not being escaped in the object e.g: ```js export const AssetCriticalityRecord = CreateAssetCriticalityRecord.and(z.object({ // ❌ invalid JS @timestamp: z.string().datetime(), })); ``` With the fix, the `@timestamp` key is surrounded by quotes. ```js export const AssetCriticalityRecord = CreateAssetCriticalityRecord.and(z.object({ // ✅ '@timestamp': z.string().datetime(), })); ``` Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ad177dd94f
commit
bf5f8cb480
2 changed files with 8 additions and 1 deletions
|
@ -47,4 +47,7 @@ export function registerHelpers(handlebarsInstance: typeof Handlebars) {
|
|||
handlebarsInstance.registerHelper('isUnknown', (val: object) => {
|
||||
return !('type' in val || '$ref' in val || 'anyOf' in val || 'oneOf' in val || 'allOf' in val);
|
||||
});
|
||||
handlebarsInstance.registerHelper('startsWithSpecialChar', (val: string) => {
|
||||
return /^[^a-zA-Z0-9]/.test(val);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -80,7 +80,11 @@ z.unknown()
|
|||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{@key}}: {{> zod_schema_item requiredBool=(includes ../required @key)}},
|
||||
{{#if (startsWithSpecialChar @key)}}
|
||||
'{{@key}}': {{> zod_schema_item requiredBool=(includes ../required @key)}},
|
||||
{{else}}
|
||||
{{@key}}: {{> zod_schema_item requiredBool=(includes ../required @key)}},
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
})
|
||||
{{~#if (eq additionalProperties false)}}.strict(){{/if~}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue