Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the ruby SDK now returns the parsed json instead of openstruct if no JSON serializer is specified #4092

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Import } from "../Import";
export interface Condition {
rightSide?: string | AstNode;
leftSide?: string | AstNode;
negated?: boolean;
operation?: string;
expressions: (AstNode | string)[];
}
Expand All @@ -30,7 +31,8 @@ export class ConditionalStatement extends AstNode {

private writeCondition(startingTabSpaces: number, condition: Condition, type: "if" | "elsif" | "else"): void {
const updatedType =
condition.operation === "!" && (condition.leftSide === undefined || condition.rightSide === undefined)
condition.negated === true ||
(condition.operation === "!" && (condition.leftSide === undefined || condition.rightSide === undefined))
? "unless"
: type;
const leftString = condition.leftSide instanceof AstNode ? condition.leftSide.write({}) : condition.leftSide;
Expand All @@ -41,10 +43,12 @@ export class ConditionalStatement extends AstNode {
templateString: `${updatedType} %s`,
startingTabSpaces
});
if (condition.leftSide !== undefined && condition.rightSide !== undefined) {
if (condition.leftSide !== undefined && condition.rightSide !== undefined && condition.operation !== "!") {
this.addText({
templateString: ` ${condition.operation} %s`,
stringContent: rightString,
startingTabSpaces
startingTabSpaces,
appendToLastString: true
});
}
condition.expressions.forEach((exp) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ export class SerializableObject extends Class_ {

return toJsonIfPresent;
} else {
functionUsesParsedJson = true;
return new Expression({
leftSide: prop.name,
rightSide: parsedJsonVariable.fromJson() ?? structVariable,
// If there's no fromJson on the value, then let's return parsed JSON, as that would remain a hash,
// as opposed to returning the struct, which is what you almost always want.
rightSide: parsedJsonVariable.fromJson() ?? parsedJsonVariable,
isAssignment: true
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class UndiscriminatedUnion extends Class_ {
new ConditionalStatement({
if_: {
leftSide: new FunctionInvocation({
onObject: jsonObjectParameter.name,
onObject: "struct",
baseFunction: new Function_({
name: "nil?",
functionBody: []
Expand All @@ -74,7 +74,7 @@ export class UndiscriminatedUnion extends Class_ {
expressions: [
new Expression({
leftSide: "return",
rightSide: sc.fromJson(jsonObjectParameter.name) ?? jsonObjectParameter.name,
rightSide: sc.fromJson("struct") ?? "struct",
isAssignment: false
})
]
Expand Down
6 changes: 6 additions & 0 deletions generators/ruby/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.8.1] - 2024-07-22

- Fix: Nested `hash` types are recursively resolved in `from_json` such that they come back as true hashes, as opposed to structs

- Fix: Pass through additional params from request options even if the original request did not have those types of params (ex: query parameters)

## [0.8.0] - 2024-07-03

- Fix: Date snippets now wrap their examples in quotation marks to correctly use `.parse`
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.8.0
0.8.1
64 changes: 61 additions & 3 deletions generators/ruby/sdk/src/utils/EndpointGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export class EndpointGenerator {
];
}

public getFaradayParameters(): Expression | undefined {
public getFaradayParameters(): AstNode | undefined {
const additionalQueryProperty = this.requestOptions.getAdditionalQueryProperties(this.requestOptionsVariable);

const literalQueryParams = new Map(
Expand All @@ -384,7 +384,39 @@ export class EndpointGenerator {
}),
isAssignment: true
})
: undefined;
: new ConditionalStatement({
if_: {
negated: true,
leftSide: new FunctionInvocation({
onObject: this.requestOptionsVariable,
baseFunction: new Function_({
name: "nil?",
functionBody: []
}),
optionalSafeCall: false
}),
operation: "&&",
rightSide: new FunctionInvocation({
onObject: additionalQueryProperty,
baseFunction: new Function_({
name: "nil?",
functionBody: []
}),
optionalSafeCall: false
}),
expressions: [
new Expression({
leftSide: `${this.blockArg}.params`,
rightSide: new HashInstance({
additionalHashes: [{ value: additionalQueryProperty, defaultValue: "{}" }],
shouldCompact: true,
stringifyValues: false
}),
isAssignment: true
})
]
}
});
}

private getFaradayBodyForReference(additionalBodyProperty: string): AstNode[] {
Expand Down Expand Up @@ -526,8 +558,34 @@ export class EndpointGenerator {
throw new Error("Unknown request body type.");
}
});
} else {
return [
new ConditionalStatement({
if_: {
leftSide: new FunctionInvocation({
onObject: this.requestOptionsVariable,
baseFunction: new Function_({
name: "nil?",
functionBody: []
}),
optionalSafeCall: false
}),
operation: "!",
expressions: [
new Expression({
leftSide: `${this.blockArg}.body`,
rightSide: new HashInstance({
additionalHashes: [{ value: additionalBodyProperty, defaultValue: "{}" }],
shouldCompact: true,
stringifyValues: false
}),
isAssignment: true
})
]
}
})
];
}
return;
}

public getFaradayBlock(
Expand Down
5 changes: 3 additions & 2 deletions seed/ruby-model/alias/lib/seed_alias_client/types/type.rb

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

1 change: 1 addition & 0 deletions seed/ruby-model/audiences/.mock/definition/api.yml

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

6 changes: 5 additions & 1 deletion seed/ruby-model/audiences/.mock/definition/foo.yml

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.

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.

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
Loading