Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=../../../../../fern-changes-yml.schema.json

- summary: |
Fix boolean `clientDefault` values being incorrectly wrapped in quotes in the
generated PHP SDK constructor. Boolean literals now emit bare `true`/`false` instead
of string `'true'`/`'false'`.
type: fix
- summary: |
Fix inline path parameters with `clientDefault` in wrapped request classes.
The field type is no longer made optional, which preserves the `clientDefault`
initializer in the generated constructor instead of discarding it with `?? null`.
type: fix
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ export class WrappedEndpointRequestGenerator extends FileGenerator<
const clientDefaultInit = DefaultValueExtractor.extractClientDefaultCodeBlock(
pathParameter.clientDefault
);
let type = this.context.phpTypeMapper.convert({ reference: pathParameter.valueType });
if (clientDefaultInit != null && !this.context.isOptional(pathParameter.valueType)) {
type = php.Type.optional(type);
}
const type = this.context.phpTypeMapper.convert({ reference: pathParameter.valueType });
this.addFieldWithMethods({
clazz,
name: pathParameter.name,
Expand Down
23 changes: 17 additions & 6 deletions generators/php/sdk/src/root-client/RootClientGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,10 @@ export class RootClientGenerator extends FileGenerator<PhpFile, SdkCustomConfigS
for (const param of constructorParameters.optional) {
if (param.environmentVariable != null) {
if (param.clientDefault != null) {
const defaultWire = this.getClientDefaultLiteralWireValue(param.clientDefault);
const escaped = defaultWire.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
const phpLiteral = this.getClientDefaultPhpLiteral(param.clientDefault);
writer.writeLine(`$envValue = getenv('${param.environmentVariable}');`);
writer.writeTextStatement(
`$${param.name} ??= ($envValue !== false ? $envValue : '${escaped}')`
`$${param.name} ??= ($envValue !== false ? $envValue : ${phpLiteral})`
);
} else {
writer.write(`$${param.name} ??= `);
Expand All @@ -344,9 +343,8 @@ export class RootClientGenerator extends FileGenerator<PhpFile, SdkCustomConfigS

for (const param of constructorParameters.optional) {
if (param.clientDefault != null && param.environmentVariable == null) {
const defaultWire = this.getClientDefaultLiteralWireValue(param.clientDefault);
const escaped = defaultWire.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
writer.writeTextStatement(`$${param.name} ??= '${escaped}'`);
const phpLiteral = this.getClientDefaultPhpLiteral(param.clientDefault);
writer.writeTextStatement(`$${param.name} ??= ${phpLiteral}`);
}
}

Expand Down Expand Up @@ -795,6 +793,19 @@ export class RootClientGenerator extends FileGenerator<PhpFile, SdkCustomConfigS
}
}

private getClientDefaultPhpLiteral(literal: FernIr.Literal): string {
switch (literal.type) {
case "string": {
const escaped = literal.string.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
return `'${escaped}'`;
}
case "boolean":
return literal.boolean ? "true" : "false";
default:
assertNever(literal);
}
}

/**
* Resolves a basic auth scheme into its null-check condition and credential expressions,
* accounting for omitted username/password fields. Returns undefined if both fields are omitted.
Expand Down
Loading