Skip to content

Commit

Permalink
fix(type-safe-api): fix typescript generated code for dictionary types
Browse files Browse the repository at this point in the history
  • Loading branch information
cogwirrel committed Oct 30, 2024
1 parent 752077c commit a590627
Show file tree
Hide file tree
Showing 5 changed files with 2,761 additions and 308 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export type <%- model.name %> =<% model.properties.forEach((composedType, i) =>
<%_ } _%>
*/
export interface <%= model.name %> {
<%_ if (model.additionalProperties) { _%>
[key: string]: <%- model.additionalProperties.typescriptType %>;
<%_ if (model.export === "dictionary" && model.link) { _%>
[key: string]: <%- model.link.typescriptType %>;
<%_ } _%>
<%_ model.properties.forEach((property) => { _%>
/**
Expand Down Expand Up @@ -126,7 +126,7 @@ export function <%= model.name %>FromJSONTyped(json: any, ignoreDiscriminator: b
<%_ } else { _%>
return {
<%_ if (model.additionalProperties) { _%>
<%_ if (model.export === "dictionary") { _%>
...json,
<%_ } _%>
<%_ model.properties.forEach((property) => { _%>
Expand Down Expand Up @@ -173,7 +173,7 @@ export function <%= model.name %>ToJSON(value?: <%= model.name %> | null): any {
<%_ } else { _%>
return {
<%_ if (model.additionalProperties) { _%>
<%_ if (model.export === "dictionary") { _%>
...value,
<%_ } _%>
<%_ model.properties.forEach((property) => { _%>
Expand Down
30 changes: 30 additions & 0 deletions packages/type-safe-api/test/resources/specs/edge-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ArrayOfOneOfs"
/additional-properties:
post:
operationId: dictionary
responses:
200:
description: ok
content:
application/json:
schema:
$ref: "#/components/schemas/AdditionalPropertiesResponse"
components:
schemas:
MyEnum:
Expand Down Expand Up @@ -165,3 +175,23 @@ components:
type: array
items:
$ref: "#/components/schemas/NamedOneOfUnion"
AdditionalPropertiesResponse:
type: object
properties:
dictionaryOfObjects:
$ref: "#/components/schemas/Dictionary"
dictionaryOfPrimitives:
type: object
additionalProperties:
type: string
Dictionary:
type: object
additionalProperties:
type: array
items:
$ref: "#/components/schemas/SomeObject"
SomeObject:
type: object
properties:
a:
type: string
Loading

0 comments on commit a590627

Please sign in to comment.