JSON:API compliance - optional attributes
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- typescript
- Ambito
- api
Direzione di ricerca
Inizia individuando le interfacce SingleResourceDoc, CollectionResourceDoc e AttributesObject e verificando i relativi vincoli generici e le firme di indice. Riproduci l’esempio di proprietà opzionale dell’issue con il compilatore TypeScript, quindi verifica che gli attributi opzionali siano accettati senza indebolire le restrizioni JSON:API dichiarate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is your feature request related to a problem? Please describe.
I would like to use the types in your library to describe the interfaces in our application to consume them in the backend and frontend libraries.
Currently, I have an issue with optional attributes that are not allowed by the index signature of the { [k: string]: JSON.Value } which is used by the SingleResourceDoc, CollectionResourceDoc and AttributesObject interfaces.
Following a simplified and JSON:API compliant use case:
Example response body 1:
{
"data": {
"id": "1",
"type": "_resource_type",
"attributes": {
"mandatory_attribute": "mandatory value"
}
}
}
Example response body 2:
{
"data": {
"id": "2",
"type": "_resource_type",
"attributes": {
"mandatory_attribute": "mandatory value",
"optional_property": "optional value",
}
}
}
Expected interface specification:
export type ResourceRequestBody = SingleResourceDoc<
'_resource_type_',
{
mandatory_property: string;
optional_property?: string;
}
>;
This scenario would lead to the following typescript error:
TS2344: Type '{ mandatory_property: string; optional_property?: string | undefined; }' does not satisfy the constraint '{ [k: string]: Value; }'.
Property 'optional_property' is incompatible with index signature.
Type 'string | undefined' is not assignable to type 'Value'.
Type 'undefined' is not assignable to type 'Value'.
As described in the JSON:API specification (json-schema), attributes has to be an object which may contain properties with a naming scheme which matches the pattern ^[a-zA-Z0-9](?:[-\\w]*[a-zA-Z0-9])?$ and are not named relationships, links, id or type.
"attributes": {
"description": "Members of the attributes object (\"attributes\") represent information about the resource object in which it's defined.",
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9](?:[-\\w]*[a-zA-Z0-9])?$": {
"description": "Attributes may contain any valid JSON value."
}
},
"not": {
"anyOf": [
{"required": ["relationships"]},
{"required": ["links"]},
{"required": ["id"]},
{"required": ["type"]}
]
},
"additionalProperties": false
},
Describe the solution you'd like
I would appreciate the support for optional attributes or an example of how to use them. Sadly I am not aware of how to change the interface signature to support optional attributes so I am not able to provide a PR at the moment.
Describe alternatives you've considered
I tried to pass different specifications to the generic to support optional attributes but the index signature always wins as expected.
Additional context
- Lingua principale
- TypeScript
- Stelle
- 54
- Fork
- 6
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mike-north/jsonapi-typescript
-
Dependency DashboardAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
mike-north/jsonapi-typescript#246 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
mike-north/jsonapi-typescript#180 · 2 reazioni ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 58/100
mike-north/jsonapi-typescript#134 ·
-
Interested in validators?Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
mike-north/jsonapi-typescript#128 · 3 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
mike-north/jsonapi-typescript#126 ·
Tutte le issue di mike-north/jsonapi-typescript
Issue simili
-
ready-for-ai
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
umbraco/Umbraco-CMS-MCP-Dev#647 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
HelloAOLab/seed-bible#2173 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
hocinehacherouf/liberarr#77 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
LibreChat-AI/LibreChat#18225 ·
I maintainer di solito rispondono entro 1 giorno
-
b-ber/build/epub b-ber/themes
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
triplecanopy/b-ber#790 ·
I maintainer di solito rispondono entro 1 giorno