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

Support SwiftData models

Aperta
#398 0 commenti 0 reazioni 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
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
swift
Ambito
api

Direzione di ricerca

Start from JSONSchema.derivedJsonSchema and PropertyValue.init(from:), which uses Mirror on the JSONSchemaConvertible example instance. Reproduce with a SwiftData @Model type and note which synthesized _/$ properties trigger JSONSchemaConvertationError.typeUnsupported. Decide whether to skip those names, otherwise document the limitation; there is no named test file in the issue.

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

Descrizione

Hello all, thanks for the nice project.

Is your feature request related to a problem? Please describe.

JSONSchemaConvertible doesn't work with SwiftData @Model classes. Calling derivedJsonSchema() throws JSONSchemaConvertationError.typeUnsupported at runtime:

@Model
final class DictionaryEntry: Codable {
    var input: String = ""
    var entries: [Entry] = []
}

extension DictionaryEntry: JSONSchemaConvertible {
    static var example: DictionaryEntry { /* ... */ }
}

// Throws typeUnsupported
let schema = JSONSchema.derivedJsonSchema(DictionaryEntry.self)

Describe the solution you'd like

I believe the root cause is that PropertyValue.init(from:) uses Mirror to reflect the example instance. For @Model classes, Mirror sees internal SwiftData properties (injected by the macro) that have unsupported types. Probably the solution could be to filter out properties starting with _ or $, use some enum to determine which properties to include or at least document this limitation.

Describe alternatives you've considered

Creating plain structs that duplicate the model structure:

struct DictionaryEntryDTO: Codable, JSONSchemaConvertible {
    let input: String
    let entries: [EntryDTO]
    static var example: Self { /* ... */ }
}

let schema = JSONSchema.derivedJsonSchema(DictionaryEntryDTO.self)

The above works but I need to maintain duplicate types.

Additional context

  • SwiftData @Model macro synthesizes properties for observation/persistence
  • These are visible to Mirror but not part of Codable
  • Tested with v0.4.7
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.