aqueduct icon indicating copy to clipboard operation
aqueduct copied to clipboard

Openapi generator (wrongly?) includes private ORM fields

Open point-source opened this issue 3 years ago • 0 comments

I have some ORMs with private fields that do not get serialized but are used internally. Despite not being exposed on any endpoint, the openapi generator includes these fields in the openapi json spec. Using the aqueduct "db" template as an example:

My model (with a non-serialized private field called _myPrivateField):

class Model extends ManagedObject<_Model> implements _Model {
  @override
  void willInsert() {
    createdAt = DateTime.now().toUtc();
  }
}

class _Model {
  @primaryKey
  int id;

  @Column(indexed: true)
  String name;

  DateTime createdAt;

  @Column(nullable: true)
  String _myPrivateField;
}

Generated Openapi JSON:

"components": {
        "schemas": {
            "Model": {
                "title": "Model",
                "type": "object",
                "properties": {
                    "id": {
                        "title": "id",
                        "type": "integer",
                        "description": "This is the primary identifier for this object.\n",
                        "nullable": false
                    },
                    "name": {
                        "title": "name",
                        "type": "string",
                        "nullable": false
                    },
                    "createdAt": {
                        "title": "createdAt",
                        "type": "string",
                        "format": "date-time",
                        "nullable": false
                    },
                    "_myPrivateField": {
                        "title": "_myPrivateField",
                        "type": "string",
                        "nullable": true
                    }
                },
                "description": ""
            }
        },

How can I tell the generator to ignore private fields?

Aqueduct version: 4.0.0-b1 Dart version: 2.9.1-stable

point-source avatar Sep 29 '20 20:09 point-source