Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

A number of types that are `Codable` don't encode correctly

Aperta
#379 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
swift
Ambito
api

Direzione di ricerca

Start with Sources/OpenAI/Public/Models/ChatQuery.swift, especially ChatQuery.ChatCompletionMessageParam, and identify other typed enums with the same encoding or decoding concern. Add round-trip tests for the affected types and verify that encoding then decoding returns the initial value.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug
A number of types that are Codable don't encode correctly. This seems to impact a number of the typed enums that are typically received from an OpenAI compatible server and that are not persisted by a client (unless the client would persist its requests)

For instance ChatQuery.ChatCompletionMessageParam would need a decoding such as

public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    let role = try container.decode(Role.self, forKey: .role)
    switch role {
    case .system:
        self = try .system(.init(from: decoder))
    case .developer:
      self = try .developer(.init(from: decoder))
    case .user:
      self = try .user(.init(from: decoder))
    case .assistant:
      self = try .assistant(.init(from: decoder))
    case .tool:
      self = try .tool(.init(from: decoder))
    }
}

I mostly look at the types in ChatQuery but typically you need to hand write the encoding / decoding for each typed enum as the generated conformances are not correct and only you know about the key used to determine which nested type is right.

As a side note, it could be helpful to have tests that validate that the encoding and decoding of those types gives back the initial value.

Lmk if you want a PR.

Lingua principale
Swift
Stelle
2.9k
Fork
519
Merge medio
4g 9h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MacPaw/OpenAI

Tutte le issue di MacPaw/OpenAI

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.