Skip to content

Commit 6410e9f

Browse files
committed
refactor(frontend): alias generated openapi types
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 5e5e578 commit 6410e9f

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

src/types.ts

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
11
// SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
22
// SPDX-License-Identifier: AGPL-3.0-or-later
33

4-
export type FieldType = 'text' | 'number'
5-
6-
export type FieldVisibility = 'private' | 'users' | 'public'
7-
8-
export interface FieldDefinition {
9-
id: number
10-
field_key: string
11-
label: string
12-
type: FieldType
13-
admin_only: boolean
14-
user_editable: boolean
15-
user_visible: boolean
16-
initial_visibility: FieldVisibility
17-
sort_order: number
18-
active: boolean
19-
created_at: string
20-
updated_at: string
21-
}
22-
23-
export interface FieldValuePayload {
24-
value?: string | number | null
4+
import type { components as ApiComponents, operations as ApiOperations } from './types/openapi/openapi-full'
5+
6+
type ApiJsonBody<TRequestBody> = TRequestBody extends {
7+
content: {
8+
'application/json': infer Body
9+
}
2510
}
11+
? Body
12+
: never
2613

27-
export interface FieldValueRecord {
28-
id: number
29-
field_definition_id: number
30-
user_uid: string
31-
value: FieldValuePayload
32-
current_visibility: FieldVisibility
33-
updated_by_uid: string
34-
updated_at: string
14+
type ApiOperationRequestBody<TOperation> = TOperation extends {
15+
requestBody?: infer RequestBody
3516
}
17+
? NonNullable<RequestBody>
18+
: never
19+
20+
type ApiRequestJsonBody<TOperation> = ApiJsonBody<ApiOperationRequestBody<TOperation>>
3621

37-
export interface EditableField {
22+
export type FieldType = ApiComponents['schemas']['Type']
23+
export type FieldVisibility = ApiComponents['schemas']['Visibility']
24+
export type FieldDefinition = ApiComponents['schemas']['Definition']
25+
26+
// openapi-typescript collapses the loose `value: mixed` schema to Record<string, never>.
27+
// Keep the surrounding contract generated and widen only this payload leaf for frontend use.
28+
export type FieldValuePayload = Omit<ApiComponents['schemas']['ValuePayload'], 'value'> & {
29+
value?: string | number | null
30+
}
31+
export type FieldValueRecord = Omit<ApiComponents['schemas']['ValueRecord'], 'value'> & {
32+
value: FieldValuePayload
33+
}
34+
export type EditableField = Omit<ApiComponents['schemas']['EditableField'], 'definition' | 'value'> & {
3835
definition: FieldDefinition
3936
value: FieldValueRecord | null
40-
can_edit: boolean
4137
}
38+
export type LookupField = Omit<ApiComponents['schemas']['LookupField'], 'definition' | 'value'> & {
39+
definition: FieldDefinition
40+
value: FieldValueRecord
41+
}
42+
export type LookupResult = Omit<ApiComponents['schemas']['LookupResult'], 'fields'> & {
43+
fields: Record<string, LookupField>
44+
}
45+
46+
export type CreateDefinitionPayload = ApiRequestJsonBody<ApiOperations['field_definition_api-create']>
47+
export type UpdateDefinitionPayload = ApiRequestJsonBody<ApiOperations['field_definition_api-update']>
48+
export type UpsertOwnValuePayload = ApiRequestJsonBody<ApiOperations['field_value_api-upsert']>
49+
export type UpdateOwnVisibilityPayload = ApiRequestJsonBody<ApiOperations['field_value_api-update-visibility']>
50+
export type UpsertAdminUserValuePayload = ApiRequestJsonBody<ApiOperations['field_value_admin_api-upsert']>
4251

43-
export interface AdminEditableField {
52+
export type AdminEditableField = {
4453
definition: FieldDefinition
4554
value: FieldValueRecord | null
4655
}
4756

48-
export interface ApiError {
57+
export type ApiError = {
4958
message: string
5059
}

0 commit comments

Comments
 (0)