Skip to content

Commit

Permalink
fix, ruby: Ensure the name passed into the X-Fern-SDK-Name header i…
Browse files Browse the repository at this point in the history
…s the name of the gem, not the client class (#3073)
  • Loading branch information
armandobelardo authored Feb 28, 2024
1 parent 4f69eee commit 3f888df
Show file tree
Hide file tree
Showing 119 changed files with 620 additions and 366 deletions.
2 changes: 1 addition & 1 deletion generators/ruby/codegen/src/ast/classes/ClassReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ export class ClassReferenceFactory {
map: (mt: MapType) =>
new HashReference({
keyType: this.fromTypeReference(mt.keyType),
valueType: this.fromTypeReference(mt.keyType)
valueType: this.fromTypeReference(mt.valueType)
}),
// Optional types in Ruby look the same except they're defaulted to nil in signatures.
optional: (tr: TypeReference) => this.fromTypeReference(tr),
Expand Down
8 changes: 8 additions & 0 deletions generators/ruby/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.3.0] - 2024-02-27

- Fix: Ensure the name passed into the 'X-Fern-SDK-Name' header is the name of the gem, not the client class

- Fix: If an envvar is specified as a fallback for an auth header, the SDK will now mark that parameter as optional to allow fallback to actually happen

- Fix: Generated yardoc now appropriately reflects the typehint of the value type in maps

## [0.2.0] - 2024-02-20

- Improvement: Ruby enum construct now leverages class constants instead of hashes to support better autocomplete
Expand Down
2 changes: 1 addition & 1 deletion generators/ruby/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.3.0
10 changes: 5 additions & 5 deletions generators/ruby/sdk/src/AbstractionUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ function generateRequestClientInitializer(
isAsync: boolean,
sdkConfig: SdkConfig,
classReference: ClassReference,
clientName: string,
gemName: string,
sdkVersion: string | undefined,
headersGenerator: HeadersGenerator,
environmentCr: ClassReference | undefined,
Expand All @@ -564,7 +564,7 @@ function generateRequestClientInitializer(
const allHeaders = new Map([
// SDK Default Headers
[`"${sdkConfig.platformHeaders.language}"`, "Ruby"],
[`"${sdkConfig.platformHeaders.sdkName}"`, clientName]
[`"${sdkConfig.platformHeaders.sdkName}"`, gemName]
]);
if (sdkVersion !== undefined) {
allHeaders.set(`"${sdkConfig.platformHeaders.sdkVersion}"`, sdkVersion);
Expand Down Expand Up @@ -783,7 +783,7 @@ function generateRequestClientInitializer(

export function generateRequestClients(
sdkConfig: SdkConfig,
clientName: string,
gemName: string,
sdkVersion: string | undefined,
headersGenerator: HeadersGenerator,
environmentCr: ClassReference | undefined,
Expand Down Expand Up @@ -820,7 +820,7 @@ export function generateRequestClients(
false,
sdkConfig,
clientClassReference,
clientName,
gemName,
sdkVersion,
headersGenerator,
environmentCr,
Expand All @@ -843,7 +843,7 @@ export function generateRequestClients(
true,
sdkConfig,
asyncClientClassReference,
clientName,
gemName,
sdkVersion,
headersGenerator,
environmentCr,
Expand Down
5 changes: 1 addition & 4 deletions generators/ruby/sdk/src/ClientsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ClientsGenerator {
});
const [syncClientClass, asyncClientClass] = generateRequestClients(
this.intermediateRepresentation.sdkConfig,
this.clientName,
this.gemName,
this.sdkVersion,
this.headersGenerator,
environmentClass?.classReference,
Expand Down Expand Up @@ -214,7 +214,6 @@ export class ClientsGenerator {
services: Map<ServiceId, HttpService>,
subpackages: Map<SubpackageId, Subpackage>,
clientName: string,
gemName: string,
crf: ClassReferenceFactory,
irBasePath: string,
generatedClasses: Map<TypeId, Class_>,
Expand Down Expand Up @@ -251,7 +250,6 @@ export class ClientsGenerator {
services,
subpackages,
clientName,
gemName,
crf,
irBasePath,
generatedClasses,
Expand Down Expand Up @@ -298,7 +296,6 @@ export class ClientsGenerator {
this.services,
this.subpackages,
this.clientName,
this.gemName,
this.crf,
this.irBasePath,
this.generatedClasses,
Expand Down
19 changes: 11 additions & 8 deletions generators/ruby/sdk/src/utils/HeadersGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ export class HeadersGenerator {
new Parameter({
name: bas.token.snakeCase.safeName,
type: StringClassReference,
isOptional: !this.isAuthRequired
isOptional: bas.tokenEnvVar !== undefined || !this.isAuthRequired
})
],
basic: (bas: BasicAuthScheme) => [
new Parameter({
name: bas.username.snakeCase.safeName,
type: StringClassReference,
isOptional: !this.isAuthRequired
isOptional: bas.usernameEnvVar !== undefined || !this.isAuthRequired
}),
new Parameter({
name: bas.password.snakeCase.safeName,
type: StringClassReference,
isOptional: !this.isAuthRequired
isOptional: bas.passwordEnvVar !== undefined || !this.isAuthRequired
})
],
header: (has: HeaderAuthScheme) => [
new Parameter({
name: has.name.name.snakeCase.safeName,
type: StringClassReference,
isOptional: !this.isAuthRequired
isOptional: has.headerEnvVar !== undefined || !this.isAuthRequired
})
],
_other: () => {
Expand Down Expand Up @@ -121,27 +121,30 @@ export class HeadersGenerator {
new Property({
name: bas.token.snakeCase.safeName,
type: StringClassReference,
isOptional: isOptionalOverride ?? this.isAuthRequired,
// If you've overridden optionality, use that, otherwise:
// If there's an envvar it should be optional
// If there's not an envvar then check if auth is required
isOptional: isOptionalOverride ?? (bas.tokenEnvVar !== undefined || !this.isAuthRequired),
wireValue: "Authorization"
})
],
basic: (bas: BasicAuthScheme) => [
new Property({
name: bas.username.snakeCase.safeName,
type: StringClassReference,
isOptional: isOptionalOverride ?? this.isAuthRequired
isOptional: isOptionalOverride ?? (bas.usernameEnvVar !== undefined || !this.isAuthRequired)
}),
new Property({
name: bas.password.snakeCase.safeName,
type: StringClassReference,
isOptional: isOptionalOverride ?? this.isAuthRequired
isOptional: isOptionalOverride ?? (bas.passwordEnvVar !== undefined || !this.isAuthRequired)
})
],
header: (has: HeaderAuthScheme) => [
new Property({
name: has.name.name.snakeCase.safeName,
type: StringClassReference,
isOptional: isOptionalOverride ?? this.isAuthRequired,
isOptional: isOptionalOverride ?? (has.headerEnvVar !== undefined || !this.isAuthRequired),
wireValue: has.name.wireValue
})
],
Expand Down
2 changes: 1 addition & 1 deletion generators/ruby/sdk/src/utils/TypeUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export function isTypeOptional(typeReference: TypeReference): boolean {
named: () => false,
primitive: () => false,
_other: () => false,
unknown: () => false
unknown: () => true
});
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions seed/ruby-model/object/lib/seed_object_client/types/type.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3f888df

Please sign in to comment.