Allow "required" list to have undefined properties

Aperta
#97 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
openapi, python
Ambito
api, testing-qa

Direzione di ricerca

Start in openapi_spec_validator/validators.py around the require_properties argument and the linked validation block, then read tests/integration/test_validators.py around the existing case. Check the relevant OpenAPI and JSON Schema behavior before deciding the expected result; done means the validator and integration tests consistently accept or reject the undefined required properties case.

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

Descrizione

I think requiring property names listed in required to be defined in properties is too strict. I also couldn't find this requirement in the JSON Schema or OpenAPI specs. JSON Schema validators and the Swagger Editor are fine with property names listed in required that are not defined in properties.

It makes sense to list required properties without defining them in properties when using allOf where one sub-schema requires some properties but does not specify them while another sub-schema only provides the specifications of the properties (possibly even without stating which ones are required and which ones aren't). This is especially useful when referencing and merging schema definitions or when expressing discriminated unions with some properties that are common to all union members.

I suggest to remove the following code block

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L134-L142

and the require_properties argument:

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/openapi_spec_validator/validators.py#L123

I have seen the test case

https://github.com/p1c2u/openapi-spec-validator/blob/3f53e957812a9c545d71226e3a4d696240e2cee6/tests/integration/test_validators.py#L83-L115

but it also seems to be valid to express this schema like this:

{
    'Credit': {
        'type': 'object',
        'properties': {
            'clientId': {'type': 'string'},
        }
    },
    'CreditCreate': {
        'type': 'object',
        'required': ['clientId'],
        'allOf': [
            {
                '$ref': '#/components/schemas/Credit'
            },
            # possibly more schemas to merge ...
        ]
    }
}

Or did I miss this rule somewhere in the spec?

Lingua principale
Python
Stelle
409
Fork
73
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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.

Altre issue di python-openapi/openapi-spec-validator

Tutte le issue di python-openapi/openapi-spec-validator

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.