Skip to content

Commit

Permalink
fix(typescript): Don't double check whether an optional string litera…
Browse files Browse the repository at this point in the history
…l alias is a string when using serializer to build query string parameters. (#5614)

* fix(typescript): Don't double check whether an optional string literal alias is a string when using serializer to build query string parameters
  • Loading branch information
Swimburger authored Jan 14, 2025
1 parent 9cdb96c commit 6b4959d
Show file tree
Hide file tree
Showing 85 changed files with 1,192 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export class TypeReferenceToStringExpressionConverter extends AbstractTypeRefere
optional: (optional) => getStringify(this.context.type.resolveTypeReference(optional)),
set: () => this.jsonStringify(mapExpression),
map: () => this.jsonStringify(mapExpression),
literal: () => this.jsonStringifyIfNotString(mapExpression),
literal: (literal) => {
if (literal.type === "string") {
return mapExpression;
}
return this.jsonStringify(mapExpression);
},
_other: () => {
throw new Error("Unknown ContainerType: " + containerType.type);
}
Expand Down
41 changes: 40 additions & 1 deletion generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,46 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.46.10] - 2025-01-13
## [0.46.11] - 2025-01-14

- Fix: Don't double check whether an optional string literal alias (see example below) is a string when using serializer to build query string parameters.

```yml
types:
LiteralAliasExample: literal<"MyLiteralValue">

service:
endpoints:
foo:
path: /bar
method: POST
request:
name: FooBarRequest
query-parameters:
optional_alias_literal: optional<LiteralAliasExample>
```
```ts
// before
if (optionalAliasLiteral != null) {
_queryParams["optional_alias_literal"] = typeof serializers.LiteralAliasExample.jsonOrThrow(optionalAliasLiteral, {
unrecognizedObjectKeys: "strip",
}) === "string" ? serializers.LiteralAliasExample.jsonOrThrow(optionalAliasLiteral, {
unrecognizedObjectKeys: "strip",
}) : JSON.stringify(serializers.LiteralAliasExample.jsonOrThrow(optionalAliasLiteral, {
unrecognizedObjectKeys: "strip",
}));
}

// after
if (optionalAliasLiteral != null) {
_queryParams["optional_alias_literal"] = serializers.LiteralAliasExample.jsonOrThrow(optionalAliasLiteral, {
unrecognizedObjectKeys: "strip",
});
}
```

## [0.46.10] - 2025-01-14

- Fix: Use serialization layer to convert types to JSON strings when enabled.

Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.46.10
0.46.11
27 changes: 21 additions & 6 deletions seed/csharp-model/literal/.mock/definition/query.yml

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

27 changes: 21 additions & 6 deletions seed/csharp-sdk/literal/.mock/definition/query.yml

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

6 changes: 6 additions & 0 deletions seed/csharp-sdk/literal/reference.md

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

2 changes: 1 addition & 1 deletion seed/csharp-sdk/literal/snippet.json

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

24 changes: 24 additions & 0 deletions seed/csharp-sdk/literal/src/SeedLiteral/Query/QueryClient.cs

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.

27 changes: 21 additions & 6 deletions seed/go-fiber/literal/.mock/definition/query.yml

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

16 changes: 13 additions & 3 deletions seed/go-fiber/literal/query.go

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

27 changes: 21 additions & 6 deletions seed/go-model/literal/.mock/definition/query.yml

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

4 changes: 4 additions & 0 deletions seed/go-model/literal/query.go

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

Loading

0 comments on commit 6b4959d

Please sign in to comment.