Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions packages/quicktype-core/src/language/CPlusPlus/CPlusPlusRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,12 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
getter = [name];
}

const value = this._stringType.wrapEncodingChange(
[ourQualifier],
cppType,
toType,
["x.", getter],
);
const assignment: Sourcelike[] = [
"j[",
this._stringType.wrapEncodingChange(
Expand All @@ -1608,31 +1614,17 @@ export class CPlusPlusRenderer extends ConvenienceRenderer {
]),
),
"] = ",
this._stringType.wrapEncodingChange(
[ourQualifier],
cppType,
toType,
["x.", getter],
),
value,
";",
];
if (p.isOptional && this._options.hideNullOptional) {
this.emitBlock(
[
"if (",
this._stringType.wrapEncodingChange(
[ourQualifier],
cppType,
toType,
["x.", getter],
),
")",
],
false,
() => {
this.emitLine(assignment);
},
);
const condition =
propType.kind === "null" || propType.kind === "any"
? ["!", value, ".is_null()"]
: value;
this.emitBlock(["if (", condition, ")"], false, () => {
this.emitLine(assignment);
});
} else {
this.emitLine(assignment);
}
Expand Down
1 change: 1 addition & 0 deletions packages/quicktype-core/src/language/Php/PhpRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,7 @@ export class PhpRenderer extends ConvenienceRenderer {

protected emitSourceStructure(givenFilename: string): void {
this.emitLine("<?php");
this.emitLine("declare(strict_types=1);");
this.forEachNamedType(
"leading-and-interposing",
(c: ClassType, n: Name) => this.emitClassDefinition(c, n),
Expand Down
4 changes: 3 additions & 1 deletion test/inputs/schema/optional-any.1.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"bar": true
}
5 changes: 4 additions & 1 deletion test/inputs/schema/optional-any.2.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ "foo": 123 }
{
"foo": 123,
"bar": false
}
3 changes: 3 additions & 0 deletions test/inputs/schema/optional-any.3.fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bar": "not a boolean"
}
6 changes: 4 additions & 2 deletions test/inputs/schema/optional-any.schema
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"type": "object",
"additionalProperties": false,
"properties": {
"foo": {}
}
"foo": {},
"bar": { "type": "boolean" }
},
"required": ["bar"]
}
2 changes: 2 additions & 0 deletions test/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ export const CPlusPlusLanguage: Language = {
// boost and std optional/variant code paths differ.
["unions.json", { boost: "true" }],
["pokedex.json", { boost: "true" }],
["optional-any.schema", { "hide-null-optional": "true" }],
],
sourceFiles: ["src/language/CPlusPlus/index.ts"],
};
Expand Down Expand Up @@ -2211,6 +2212,7 @@ export const ElixirLanguage: Language = {
"strict-optional.schema",
"required.schema",
"intersection.schema",
"optional-any.schema",

// The test incorrectly succeeds due to the emitter being permissive for unions that contain only primitives. A future enhancement
// for the Elixir emitter could be a user-controlled 'strict' mode that pattern matches even on unions of only primitive types.
Expand Down
4 changes: 2 additions & 2 deletions test/unit/cjson-enum-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe("cJSON enum invalid value", () => {
const output = await cJSONOutput();

expect(output).toContain(`enum Subscription {
SUBSCRIPTION_CONFIG = 1,
SUBSCRIPTION_STATE = 1,
SUBSCRIPTION_CONFIG,
SUBSCRIPTION_HEARTBEAT,
SUBSCRIPTION_STATE,
};`);
expect(output).toContain("enum Subscription x = 0;");
});
Expand Down
Loading