private/apigen: use correct TS type for nillable fields
This change gives the proper type to TS class fields generated from nillable Go struct fields. Previously, Go struct fields having a nil representation ([]Type, *Type, etc.) were translated into TypeScript as "Type | undefined". This isn't correct because these fields, when nil, are given the value "null" when marshalled into JSON. This change fixes this issue by giving these fields the type "Type | null". Change-Id: I5a1a83eb3810a3cba10895bb2f0f75ca5fd7d1b5
This commit is contained in:
parent
0f4f1ddde8
commit
587fa8fdff
@ -13,7 +13,7 @@ export class Document {
|
||||
|
||||
export class Metadata {
|
||||
owner?: string;
|
||||
tags?: string[][];
|
||||
tags: string[][] | null;
|
||||
}
|
||||
|
||||
export class NewDocument {
|
||||
|
@ -15,7 +15,7 @@ export class Document {
|
||||
|
||||
export class Metadata {
|
||||
owner?: string;
|
||||
tags?: string[][];
|
||||
tags: string[][] | null;
|
||||
}
|
||||
|
||||
export class NewDocument {
|
||||
|
@ -135,12 +135,14 @@ func (types *Types) GenerateTypescriptDefinitions() string {
|
||||
continue
|
||||
}
|
||||
|
||||
isOptional := ""
|
||||
if isNillableType(field.Type) || jsonInfo.OmitEmpty {
|
||||
var isOptional, isNullable string
|
||||
if jsonInfo.OmitEmpty {
|
||||
isOptional = "?"
|
||||
} else if isNillableType(field.Type) {
|
||||
isNullable = " | null"
|
||||
}
|
||||
|
||||
pf("\t%s%s: %s;", jsonInfo.FieldName, isOptional, TypescriptTypeName(field.Type))
|
||||
pf("\t%s%s: %s%s;", jsonInfo.FieldName, isOptional, TypescriptTypeName(field.Type), isNullable)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
# API Docs
|
||||
|
||||
**Description:**
|
||||
**Description:**
|
||||
|
||||
**Version:** `v1`
|
||||
|
||||
|
@ -8,13 +8,13 @@ export class APIKeyInfo {
|
||||
id: UUID;
|
||||
projectId: UUID;
|
||||
projectPublicId: UUID;
|
||||
userAgent?: string;
|
||||
userAgent: string | null;
|
||||
name: string;
|
||||
createdAt: Time;
|
||||
}
|
||||
|
||||
export class APIKeyPage {
|
||||
apiKeys?: APIKeyInfo[];
|
||||
apiKeys: APIKeyInfo[] | null;
|
||||
search: string;
|
||||
limit: number;
|
||||
order: number;
|
||||
@ -46,7 +46,7 @@ export class CreateAPIKeyRequest {
|
||||
|
||||
export class CreateAPIKeyResponse {
|
||||
key: string;
|
||||
keyInfo?: APIKeyInfo;
|
||||
keyInfo: APIKeyInfo | null;
|
||||
}
|
||||
|
||||
export class Project {
|
||||
@ -54,18 +54,18 @@ export class Project {
|
||||
publicId: UUID;
|
||||
name: string;
|
||||
description: string;
|
||||
userAgent?: string;
|
||||
userAgent: string | null;
|
||||
ownerId: UUID;
|
||||
rateLimit?: number;
|
||||
burstLimit?: number;
|
||||
maxBuckets?: number;
|
||||
rateLimit: number | null;
|
||||
burstLimit: number | null;
|
||||
maxBuckets: number | null;
|
||||
createdAt: Time;
|
||||
memberCount: number;
|
||||
storageLimit?: MemorySize;
|
||||
bandwidthLimit?: MemorySize;
|
||||
userSpecifiedStorageLimit?: MemorySize;
|
||||
userSpecifiedBandwidthLimit?: MemorySize;
|
||||
segmentLimit?: number;
|
||||
storageLimit: MemorySize | null;
|
||||
bandwidthLimit: MemorySize | null;
|
||||
userSpecifiedStorageLimit: MemorySize | null;
|
||||
userSpecifiedBandwidthLimit: MemorySize | null;
|
||||
segmentLimit: number | null;
|
||||
defaultPlacement: number;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ export class ResponseUser {
|
||||
fullName: string;
|
||||
shortName: string;
|
||||
email: string;
|
||||
userAgent?: string;
|
||||
userAgent: string | null;
|
||||
projectLimit: number;
|
||||
isProfessional: boolean;
|
||||
position: string;
|
||||
|
Loading…
Reference in New Issue
Block a user