Skip to content

Commit

Permalink
additional ruby fixes to the 0.5.0 overhaul (#3359)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Apr 11, 2024
1 parent 7b2a0bf commit 7382808
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 44 deletions.
21 changes: 17 additions & 4 deletions generators/ruby/codegen/src/ast/abstractions/SerializableObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Argument } from "../Argument";
import {
AliasReference,
ArrayReference,
ClassReference,
DateReference,
Expand Down Expand Up @@ -102,7 +103,12 @@ export class SerializableObject extends Class_ {
block: {
arguments: "_k, v",
expressions: [
new Expression({ leftSide: "v", rightSide: OmittedValue, operation: "==" })
new Expression({
leftSide: "v",
rightSide: OmittedValue,
operation: "==",
isAssignment: false
})
]
},
onObject: propertyHash
Expand Down Expand Up @@ -165,11 +171,18 @@ export class SerializableObject extends Class_ {
});

usesParsedJson = parsedJsonVariable.fromJson() !== undefined;
const classReferenceForCast = prop.type[0];
const hasFromJson =
usesParsedJson &&
!(prop.type[0] instanceof ArrayReference) &&
!(prop.type[0] instanceof HashReference) &&
!(prop.type[0] instanceof DateReference);
!(classReferenceForCast instanceof ArrayReference) &&
!(classReferenceForCast instanceof HashReference) &&
!(classReferenceForCast instanceof DateReference) &&
!(
classReferenceForCast instanceof AliasReference &&
(classReferenceForCast.aliasOf instanceof ArrayReference ||
classReferenceForCast.aliasOf instanceof HashReference ||
classReferenceForCast.aliasOf instanceof DateReference)
);
if (hasFromJson) {
// If there's a special fromJson, then cast the object back to JSON before proceeding
const variable = new Variable({
Expand Down
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 @@ -227,7 +227,7 @@ export declare namespace AliasReference {
}
}
export class AliasReference extends ClassReference {
private aliasOf: ClassReference;
public aliasOf: ClassReference;
constructor({ aliasOf, ...rest }: AliasReference.Init) {
super(rest);
this.aliasOf = aliasOf;
Expand Down
4 changes: 2 additions & 2 deletions generators/ruby/codegen/src/ast/expressions/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export declare namespace Expression {
export interface Init extends AstNode.Init {
leftSide?: AstNode | string;
rightSide?: AstNode | string;
isAssignment?: boolean;
isAssignment: boolean;
operation?: string;
yardoc?: Yardoc;
}
Expand All @@ -18,7 +18,7 @@ export class Expression extends AstNode {
public yardoc: Yardoc | undefined;
public operation?: string;

constructor({ leftSide, rightSide, yardoc, operation, isAssignment = false, ...rest }: Expression.Init) {
constructor({ leftSide, rightSide, yardoc, operation, isAssignment, ...rest }: Expression.Init) {
super(rest);
this.leftSide = leftSide;
this.rightSide = rightSide;
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.5.0-rc0
0.5.0-rc1
6 changes: 4 additions & 2 deletions generators/ruby/sdk/src/AbstractionUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ function generateRequestClientInitializer(
rightSide: new ClassReference({
name: ":multipart",
import_: new Import({ from: "faraday/multipart", isExternal: true })
})
}),
isAssignment: false
}),
isAssignment: false
})
Expand Down Expand Up @@ -674,7 +675,8 @@ function generateRequestClientInitializer(
import_: new Import({ from: "faraday/retry", isExternal: true })
}),
rightSide: retryOptions,
operation: ", "
operation: ", ",
isAssignment: false
}),
isAssignment: false
})
Expand Down
37 changes: 31 additions & 6 deletions generators/ruby/sdk/src/utils/EndpointGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import {
AdditionalPropertiesProperty,
AliasReference,
Argument,
ArrayReference,
AstNode,
B64StringClassReference,
BlockConfiguration,
ClassReference,
ClassReferenceFactory,
Class_,
ConditionalStatement,
DateReference,
Expression,
FieldsetProperty,
FileClassReference,
FunctionInvocation,
Function_,
GenericClassReference,
HashInstance,
HashReference,
JsonClassReference,
Parameter,
Property,
Expand Down Expand Up @@ -512,7 +516,7 @@ export class EndpointGenerator {
type: GenericClassReference,
variableType: VariableType.LOCAL
});
return [
const parsingExpressions = [
new Expression({
leftSide: "parsed_json",
rightSide: new FunctionInvocation({
Expand All @@ -525,12 +529,33 @@ export class EndpointGenerator {
isNamed: false
})
]
}),
isAssignment: true
})
];
const hasFromJson =
responseCr.fromJson(nestedResponseValueVariable) !== undefined &&
!(responseCr instanceof ArrayReference) &&
!(responseCr instanceof HashReference) &&
!(responseCr instanceof DateReference) &&
!(
responseCr instanceof AliasReference &&
(responseCr.aliasOf instanceof ArrayReference ||
responseCr.aliasOf instanceof HashReference ||
responseCr.aliasOf instanceof DateReference)
);

if (hasFromJson) {
parsingExpressions.push(
new Expression({
leftSide: nestedResponseValueVariable,
rightSide: `parsed_json["${jrbwp.responseProperty.name.wireValue}"].to_json`,
isAssignment: true
})
}),
new Expression({
leftSide: nestedResponseValueVariable,
rightSide: `parsed_json["${jrbwp.responseProperty.name.wireValue}"].to_json`
}),
);
}
return [
...parsingExpressions,
responseCr.fromJson(nestedResponseValueVariable) ?? nestedResponseValueVariable
];
} else {
Expand Down

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

0 comments on commit 7382808

Please sign in to comment.