Skip to content

Commit eaecf20

Browse files
[Bug AB#1475412]: [Infra][API Generator] Fixing type failing to generate correctly: unordered_map<optional<x>> (#98)
1 parent 35f33e5 commit eaecf20

File tree

9 files changed

+280
-2
lines changed

9 files changed

+280
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Fixed an issue where optional type information wasn't properly conveyed when inside an Record type.",
4+
"packageName": "@minecraft/markup-generators-plugin",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

tools/api-docs-generator-test-snapshots/test/optionals/__snapshots__/optionals.spec.ts.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Notes:
4141
## Methods
4242
- [methodThatReturnsOptional](#methodthatreturnsoptional)
4343
- [methodThatTakesOptionals](#methodthattakesoptionals)
44+
- [methodThatTakesRecordOfOptionalVariants](#methodthattakesrecordofoptionalvariants)
4445
- [methodWithDefaultValuesAreOptional](#methodwithdefaultvaluesareoptional)
4546
4647
### **methodThatReturnsOptional**
@@ -67,6 +68,19 @@ methodThatTakesOptionals(arg1?: boolean, arg2?: string): void
6768
Notes:
6869
- This function can't be called in read-only mode.
6970
71+
### **methodThatTakesRecordOfOptionalVariants**
72+
\`
73+
methodThatTakesRecordOfOptionalVariants(values: Record<string, boolean | number | string | undefined>): void
74+
\`
75+
76+
#### **Parameters**
77+
- **values**: Record<*string*, *boolean* | *number* | *string* | *undefined*>
78+
79+
**Returns** *void*
80+
81+
Notes:
82+
- This function can't be called in read-only mode.
83+
7084
### **methodWithDefaultValuesAreOptional**
7185
\`
7286
methodWithDefaultValuesAreOptional(defaultIs1?: number, defaultIs0?: number, defaultIsFalse?: boolean, defaultIsString?: string, defaultIsArray?: number[]): void
@@ -205,6 +219,12 @@ export class ClassWithOptionals {
205219
*
206220
*/
207221
methodThatTakesOptionals(arg1?: boolean, arg2?: string): void;
222+
/**
223+
* @remarks
224+
* This function can't be called in read-only mode.
225+
*
226+
*/
227+
methodThatTakesRecordOfOptionalVariants(values: Record<string, boolean | number | string | undefined>): void;
208228
/**
209229
* @remarks
210230
* This function can't be called in read-only mode.

tools/api-docs-generator-test-snapshots/test/optionals/input/test-module.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,71 @@
44
"base_types": [],
55
"constants": [],
66
"functions": [
7+
{
8+
"arguments": [
9+
{
10+
"details": null,
11+
"name": "values",
12+
"type": {
13+
"is_bind_type": true,
14+
"is_errorable": false,
15+
"key_type": {
16+
"is_bind_type": false,
17+
"is_errorable": false,
18+
"name": "string"
19+
},
20+
"name": "map",
21+
"value_type": {
22+
"is_bind_type": true,
23+
"is_errorable": false,
24+
"name": "optional",
25+
"optional_type": {
26+
"is_bind_type": false,
27+
"is_errorable": false,
28+
"name": "variant",
29+
"variant_types": [
30+
{
31+
"is_bind_type": false,
32+
"is_errorable": false,
33+
"name": "boolean"
34+
},
35+
{
36+
"is_bind_type": false,
37+
"is_errorable": false,
38+
"name": "double",
39+
"valid_range": {
40+
"max": 2147483647,
41+
"min": -2147483648
42+
}
43+
},
44+
{
45+
"is_bind_type": false,
46+
"is_errorable": false,
47+
"name": "float",
48+
"valid_range": {
49+
"max": 2147483647,
50+
"min": -2147483648
51+
}
52+
},
53+
{
54+
"is_bind_type": false,
55+
"is_errorable": false,
56+
"name": "string"
57+
}
58+
]
59+
}
60+
}
61+
}
62+
}
63+
],
64+
"is_constructor": false,
65+
"name": "methodThatTakesRecordOfOptionalVariants",
66+
"return_type": {
67+
"is_bind_type": false,
68+
"is_errorable": false,
69+
"name": "void"
70+
}
71+
},
772
{
873
"arguments": [],
974
"is_constructor": false,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Record of Optional Variants > Generates correct output for record of optional variants > # Of Files Generated 1`] = `4`;
4+
5+
exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/TOC.yml 1`] = `
6+
" - name: exampleMember
7+
items:
8+
- name: exampleMember
9+
href: examplemember/examplemember.md
10+
- name: ClassWithRecordOfOptionalVariantsProperty
11+
href: examplemember/ClassWithRecordOfOptionalVariantsProperty.md
12+
"
13+
`;
14+
15+
exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/examplemember/ClassWithRecordOfOptionalVariantsProperty.md 1`] = `
16+
"---
17+
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
18+
author: jakeshirley
19+
ms.author: jashir
20+
ms.service: minecraft-bedrock-edition
21+
ms.date: 02/10/2025
22+
title: examplemember.ClassWithRecordOfOptionalVariantsProperty Class
23+
description: Contents of the exampleMember.ClassWithRecordOfOptionalVariantsProperty class.
24+
---
25+
# ClassWithRecordOfOptionalVariantsProperty Class
26+
27+
## Properties
28+
29+
### **exampleMember**
30+
\`exampleMember?: Record<string, boolean | number | string | undefined>;\`
31+
32+
Type: Record<*string*, *boolean* | *number* | *string* | *undefined*>
33+
34+
Notes:
35+
- This property can't be used in read-only mode.
36+
"
37+
`;
38+
39+
exports[`Record of Optional Variants > Generates correct output for record of optional variants > msdocs/scriptapi/examplemember/examplemember.md 1`] = `
40+
"---
41+
# DO NOT TOUCH — This file was automatically generated by @minecraft/api-docs-generator, to report problems file an issue at https://github.com/Mojang/minecraft-scripting-libraries
42+
author: jakeshirley
43+
ms.author: jashir
44+
ms.service: minecraft-bedrock-edition
45+
ms.date: 02/10/2025
46+
title: examplemember Module
47+
description: Contents of the exampleMember module
48+
---
49+
# \`exampleMember\` Module
50+
51+
## Manifest Details
52+
\`\`\`json
53+
{
54+
"module_name": "exampleMember",
55+
"version": "1.0.0"
56+
}
57+
\`\`\`
58+
This is version 1.x.x of this module, which is the latest as of version 1.0.0 of Minecraft.
59+
60+
## Available Versions
61+
- \`1.0.0\`
62+
63+
## Classes
64+
- [ClassWithRecordOfOptionalVariantsProperty](ClassWithRecordOfOptionalVariantsProperty.md)
65+
"
66+
`;
67+
68+
exports[`Record of Optional Variants > Generates correct output for record of optional variants > typescript/[email protected] 1`] = `
69+
"// Type definitions for Minecraft Bedrock Edition script APIs
70+
// Project: https://docs.microsoft.com/minecraft/creator/
71+
// Definitions by: Jake Shirley <https://github.com/JakeShirley>
72+
// Mike Ammerlaan <https://github.com/mammerla>
73+
74+
/* *****************************************************************************
75+
Copyright (c) Microsoft Corporation.
76+
***************************************************************************** */
77+
/**
78+
* @packageDocumentation
79+
*
80+
* Manifest Details
81+
* \`\`\`json
82+
* {
83+
* "module_name": "exampleMember",
84+
* "version": "1.0.0"
85+
* }
86+
* \`\`\`
87+
*
88+
*/
89+
export class ClassWithRecordOfOptionalVariantsProperty {
90+
private constructor();
91+
/**
92+
* @remarks
93+
* This property can't be used in read-only mode.
94+
*
95+
*/
96+
exampleMember?: Record<string, boolean | number | string | undefined>;
97+
}
98+
"
99+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// File exists to ensure docs folder exists
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"classes": [
3+
{
4+
"base_types": [],
5+
"constants": [],
6+
"functions": [],
7+
"name": "ClassWithRecordOfOptionalVariantsProperty",
8+
"properties": [
9+
{
10+
"is_read_only": false,
11+
"name": "exampleMember",
12+
"type": {
13+
"is_bind_type": false,
14+
"is_errorable": false,
15+
"name": "optional",
16+
"optional_type": {
17+
"key_type": {
18+
"is_bind_type": false,
19+
"is_errorable": false,
20+
"name": "string"
21+
},
22+
"value_type": {
23+
"is_bind_type": false,
24+
"is_errorable": false,
25+
"name": "optional",
26+
"optional_type": {
27+
"is_bind_type": false,
28+
"is_errorable": false,
29+
"name": "variant",
30+
"variant_types": [
31+
{
32+
"is_bind_type": false,
33+
"is_errorable": false,
34+
"name": "boolean"
35+
},
36+
{
37+
"is_bind_type": false,
38+
"is_errorable": false,
39+
"name": "float",
40+
"valid_range": {
41+
"max": 2147483647,
42+
"min": -2147483648
43+
}
44+
},
45+
{
46+
"is_bind_type": false,
47+
"is_errorable": false,
48+
"name": "string"
49+
}
50+
]
51+
}
52+
},
53+
"is_bind_type": false,
54+
"is_errorable": false,
55+
"name": "map"
56+
}
57+
}
58+
}
59+
],
60+
"type": {
61+
"is_bind_type": true,
62+
"is_errorable": false,
63+
"name": "ClassWithRecordOfOptionalVariantsProperty"
64+
}
65+
}
66+
],
67+
"minecraft_version": "1.0.0",
68+
"name": "exampleMember",
69+
"uuid": "93faf953-0173-44dc-b542-b48f4fea7c4b",
70+
"version": "1.0.0",
71+
"module_type": "script"
72+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { describe, it } from 'vitest';
5+
import { runGeneratorForTest } from '../runGeneratorForTest';
6+
7+
describe('Record of Optional Variants', () => {
8+
it('Generates correct output for record of optional variants', () => {
9+
runGeneratorForTest({
10+
testDir: __dirname,
11+
generators: ['ts', 'msdocs'],
12+
});
13+
});
14+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#is_void_return}}*void*{{/is_void_return}}{{^is_void_return}}{{#is_data_buffer}}{{#data_buffer_type}}[{{> type}}](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{{> type}}){{/data_buffer_type}}{{/is_data_buffer}}{{^is_data_buffer}}{{#is_generator}}Generator<{{#generator_type}}{{#yield_type}}{{> type_with_links}}{{/yield_type}}, {{#return_type}}{{> type_with_links}}{{/return_type}}, {{#next_type}}{{> type_with_links}}{{/next_type}}{{/generator_type}}>{{/is_generator}}{{^is_generator}}{{#is_map}}Record<{{#key_type}}{{> type_with_links}}{{/key_type}}, {{#value_type}}{{> type_with_links}}{{/value_type}}>{{/is_map}}{{^is_map}}{{#is_iterator_result}}IteratorResult&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator_result}}{{^is_iterator_result}}{{#is_iterator}}Iterator&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator}}{{^is_iterator}}{{#is_optional_type}}{{#optional_type}}{{> type_with_links}}{{/optional_type}}{{/is_optional_type}}{{^is_optional_type}}{{#is_variant}}{{#variant_types}}{{> type_with_links}}{{^is_last}} | {{/is_last}}{{/variant_types}}{{/is_variant}}{{^is_variant}}{{#is_promise}}Promise&lt;{{#promise_type}}{{> type_with_links}}{{/promise_type}}&gt;{{/is_promise}}{{^is_promise}}{{#is_array}}{{#element_type}}{{#is_optional_type}}{{#optional_type}}({{/optional_type}}{{/is_optional_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*){{/optional_type}}{{/is_optional_type}}{{#is_variant}}){{/is_variant}}[]{{/element_type}}{{/is_array}}{{^is_array}}{{#is_undefined}}*undefined*{{/is_undefined}}{{^is_undefined}}{{#is_closure}}{{#closure_type}}({{#argument_types}}arg{{index}}: {{> type_with_links}}{{^is_last}}, {{/is_last}}{{/argument_types}}) => {{#return_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_variant}}){{/is_variant}}{{/return_type}}{{/closure_type}}{{^closure_type}}() => void{{/closure_type}}{{/is_closure}}{{^is_closure}}{{#argument_valid_values.length}}{{#argument_valid_values}}`'{{argument_valid_value}}'`{{^argument_valid_value_end}}, {{/argument_valid_value_end}}{{/argument_valid_values}}{{/argument_valid_values.length}}{{^argument_valid_values}}{{#is_bind_type}}[{{/is_bind_type}}*{{#from_module.is_external_module}}{{{from_module.name}}}.{{/from_module.is_external_module}}{{{name}}}*{{#is_bind_type}}]({{#from_module.is_external_module}}../../../{{{from_module.folder_path}}}/{{{from_module.filepath_name}}}/{{/from_module.is_external_module}}{{{name}}}.md){{/is_bind_type}}{{/argument_valid_values}}{{/is_closure}}{{/is_undefined}}{{/is_array}}{{/is_promise}}{{/is_variant}}{{/is_optional_type}}{{/is_iterator}}{{/is_iterator_result}}{{/is_map}}{{/is_generator}}{{/is_data_buffer}}{{/is_void_return}}
1+
{{#is_void_return}}*void*{{/is_void_return}}{{^is_void_return}}{{#is_data_buffer}}{{#data_buffer_type}}[{{> type}}](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{{> type}}){{/data_buffer_type}}{{/is_data_buffer}}{{^is_data_buffer}}{{#is_generator}}Generator<{{#generator_type}}{{#yield_type}}{{> type_with_links}}{{/yield_type}}, {{#return_type}}{{> type_with_links}}{{/return_type}}, {{#next_type}}{{> type_with_links}}{{/next_type}}{{/generator_type}}>{{/is_generator}}{{^is_generator}}{{#is_map}}Record<{{#key_type}}{{> type_with_links}}{{/key_type}}, {{#value_type}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*{{/optional_type}}{{/is_optional_type}}{{/value_type}}>{{/is_map}}{{^is_map}}{{#is_iterator_result}}IteratorResult&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator_result}}{{^is_iterator_result}}{{#is_iterator}}Iterator&lt;{{#iterator_type}}{{> type_with_links}}{{/iterator_type}}&gt;{{/is_iterator}}{{^is_iterator}}{{#is_optional_type}}{{#optional_type}}{{> type_with_links}}{{/optional_type}}{{/is_optional_type}}{{^is_optional_type}}{{#is_variant}}{{#variant_types}}{{> type_with_links}}{{^is_last}} | {{/is_last}}{{/variant_types}}{{/is_variant}}{{^is_variant}}{{#is_promise}}Promise&lt;{{#promise_type}}{{> type_with_links}}{{/promise_type}}&gt;{{/is_promise}}{{^is_promise}}{{#is_array}}{{#element_type}}{{#is_optional_type}}{{#optional_type}}({{/optional_type}}{{/is_optional_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_optional_type}}{{#optional_type}} | *undefined*){{/optional_type}}{{/is_optional_type}}{{#is_variant}}){{/is_variant}}[]{{/element_type}}{{/is_array}}{{^is_array}}{{#is_undefined}}*undefined*{{/is_undefined}}{{^is_undefined}}{{#is_closure}}{{#closure_type}}({{#argument_types}}arg{{index}}: {{> type_with_links}}{{^is_last}}, {{/is_last}}{{/argument_types}}) => {{#return_type}}{{#is_variant}}({{/is_variant}}{{> type_with_links}}{{#is_variant}}){{/is_variant}}{{/return_type}}{{/closure_type}}{{^closure_type}}() => void{{/closure_type}}{{/is_closure}}{{^is_closure}}{{#argument_valid_values.length}}{{#argument_valid_values}}`'{{argument_valid_value}}'`{{^argument_valid_value_end}}, {{/argument_valid_value_end}}{{/argument_valid_values}}{{/argument_valid_values.length}}{{^argument_valid_values}}{{#is_bind_type}}[{{/is_bind_type}}*{{#from_module.is_external_module}}{{{from_module.name}}}.{{/from_module.is_external_module}}{{{name}}}*{{#is_bind_type}}]({{#from_module.is_external_module}}../../../{{{from_module.folder_path}}}/{{{from_module.filepath_name}}}/{{/from_module.is_external_module}}{{{name}}}.md){{/is_bind_type}}{{/argument_valid_values}}{{/is_closure}}{{/is_undefined}}{{/is_array}}{{/is_promise}}{{/is_variant}}{{/is_optional_type}}{{/is_iterator}}{{/is_iterator_result}}{{/is_map}}{{/is_generator}}{{/is_data_buffer}}{{/is_void_return}}

0 commit comments

Comments
 (0)