openapi-generators / openapi-generators/openapi-python-client

Generator fails on type: array without items even though it's valid in JSON Schema 2020-12 / OpenAPI 3.1

Aperta
#1,435 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
2k
Fork
293
Merge medio
34m
PR unite (30g)
1

Descrizione

Describe the bug
When a schema has "type": "array" without an "items" field, the generator fails to produce a property for it. In JSON Schema 2020-12 (used by OpenAPI 3.1), omitting items is valid and means "array of any type". The generator should treat it as equivalent to "items": {} (i.e., generate a List[Any] property) rather than silently failing.

OpenAPI Spec File
We encountered this in two forms:
Case 1 — bare array with no constraints:

{
  "type": "array",
  "description": "Array of objects representing a row of metrics data - can be any format."
}

Case 2 — array with maxItems but no items:

{
  "anyOf": [
    { "type": "array", "maxItems": 0 },
    { "type": "object", "properties": { "tag": { "type": "array", "items": { "type": "string" } } } }
  ]
}

In both cases the generator silently skips the schema (or the anyOf branch) without an error. Adding ["items": {}] to each fixes the generation.

Expected behaviour: {"type": "array"} (with or without other constraints like maxItems) should generate a List[Any] property, consistent with how JSON Schema 2020-12 defines it.

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.3 LTS
  • Python Version: 3.12.3
  • openapi-python-client 0.28.1
  • OpenAPI version: 3.1.1 (JSON Schema 2020-12)

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia tracciando il modo in cui il generatore gestisce gli schemi di array e i rami anyOf quando items è assente, usando come input i due schemi nell'issue. Aggiungi una copertura di regressione per gli array semplici e per gli array con maxItems, quindi esegui il generatore e conferma che entrambi producano una proprietà List[Any] invece di essere ignorati.

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

Valutazione

Stack tecnologico
openapi, python
Ambito
api, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
64/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.