BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.99k stars 211 forks source link

[BUG] revision_id is in schema even it should be removed by Document.schema_extra #418

Closed nadir-albajari-hs closed 1 year ago

nadir-albajari-hs commented 1 year ago

Describe the bug revision_id still in the schema and since it's hidden it should not appear in the schema hidden is not compliant with OpenAPI/JSONSchema

To Reproduce

class MyModel(Document):
    a:int

print(MyModel.get_hidden_fields())
print(MyModel.schema_json(indent=2))
{'revision_id'}
{
  "title": "MyModel",
  "description": "Document Mapping class.\n\nFields:\n\n- `id` - MongoDB document ObjectID \"_id\" field.\nMapped to the PydanticObjectId class\n\nInherited from:\n\n- Pydantic BaseModel\n- [UpdateMethods](https://roman-right.github.io/beanie/api/interfaces/#aggregatemethods)",
  "type": "object",
  "properties": {
    "_id": {
      "title": " Id",
      "type": "string",
      "examples": [
        "5eb7cf5a86d9755df3a6c593",
        "5eb7cfb05e32e07750a1756a"
      ]
    },
    "revision_id": {
      "title": "Revision Id",
      "hidden": true,
      "type": "string",
      "format": "uuid"
    },
    "a": {
      "title": "A",
      "type": "integer"
    }
  },
  "required": [
    "a"
  ]
}

Expected behavior since the field is hidden it should not appear in the schema this causes some OpenAPI tools to crash, e.g: generating a client

docker run  --network host  --rm -v "{PWD}:/local" openapitools/openapi-generator-cli generate \
    -i local/openapi.json \
        -g python \
        -o /local/out/python

Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 3, Warning count: 0
Errors: 
    -attribute components.schemas.Model.hidden is unexpected
    -attribute paths.'/Model'(get).parameters.[revision_id].schemas.hidden is unexpected
    -attribute components.schemas.Model.hidden is unexpected
Vitalium commented 1 year ago

It is also included in repr. However use_revision is set to False by default.