[PR #12071] Add JSON format option for orm:mapping:describe command output #13455

Open
opened 2026-01-22 16:17:09 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/12071

State: closed
Merged: Yes


Following suggestion from https://github.com/doctrine/DoctrineBundle/issues/1883, this PR adds the --format=json option to the orm:mapping:describe command to enable JSON output (hence allowing jq filtering of said-output).

For example, when running symfony console doctrine:mapping:describe App\\Entity\\Book --format=json, we get the following output :


{
    "name": "App\\Entity\\Book",
    "rootEntityName": "App\\Entity\\Book",
    "customGeneratorDefinition": null,
    "customRepositoryClassName": "App\\Repository\\BookRepository",
    "isMappedSuperclass": false,
    "isEmbeddedClass": false,
    "parentClasses": [],
    "subClasses": [],
    "embeddedClasses": [],
    "identifier": [
        "id"
    ],
    "inheritanceType": 1,
    "discriminatorColumn": null,
    "discriminatorValue": null,
    "discriminatorMap": [],
    "generatorType": 4,
    "table": {
        "name": "book"
    },
    "isIdentifierComposite": false,
    "containsForeignIdentifier": false,
    "containsEnumIdentifier": false,
    "sequenceGeneratorDefinition": null,
    "changeTrackingPolicy": 1,
    "isVersioned": false,
    "versionField": null,
    "isReadOnly": false,
    "entityListeners": [],
    "associationMappings": {
        "author": {
            "cascade": [],
            "fetch": 2,
            "inherited": null,
            "declared": null,
            "cache": null,
            "id": null,
            "isOnDeleteCascade": true,
            "originalClass": null,
            "originalField": null,
            "orphanRemoval": false,
            "unique": null,
            "fieldName": "author",
            "sourceEntity": "App\\Entity\\Book",
            "targetEntity": "App\\Entity\\Author",
            "inversedBy": "books",
            "indexBy": null,
            "orderBy": [],
            "joinTable": {
                "quoted": null,
                "joinColumns": [
                    {
                        "deferrable": null,
                        "unique": null,
                        "quoted": null,
                        "fieldName": null,
                        "onDelete": "CASCADE",
                        "columnDefinition": null,
                        "nullable": null,
                        "options": null,
                        "name": "book_id",
                        "referencedColumnName": "id"
                    }
                ],
                "inverseJoinColumns": [
                    {
                        "deferrable": null,
                        "unique": null,
                        "quoted": null,
                        "fieldName": null,
                        "onDelete": "CASCADE",
                        "columnDefinition": null,
                        "nullable": null,
                        "options": null,
                        "name": "author_id",
                        "referencedColumnName": "id"
                    }
                ],
                "options": [],
                "schema": null,
                "name": "book_author"
            },
            "joinTableColumns": [
                "book_id",
                "author_id"
            ],
            "relationToSourceKeyColumns": {
                "book_id": "id"
            },
            "relationToTargetKeyColumns": {
                "author_id": "id"
            }
        }
    },
    "fieldMappings": {
        "id": {
            "length": null,
            "id": true,
            "nullable": false,
            "notInsertable": null,
            "notUpdatable": null,
            "columnDefinition": null,
            "generated": null,
            "enumType": null,
            "precision": null,
            "scale": null,
            "unique": false,
            "index": false,
            "inherited": null,
            "originalClass": null,
            "originalField": null,
            "quoted": null,
            "declared": null,
            "declaredField": null,
            "options": null,
            "version": null,
            "default": null,
            "type": "integer",
            "fieldName": "id",
            "columnName": "id"
        },
        "title": {
            "length": 255,
            "id": null,
            "nullable": false,
            "notInsertable": null,
            "notUpdatable": null,
            "columnDefinition": null,
            "generated": null,
            "enumType": null,
            "precision": null,
            "scale": null,
            "unique": false,
            "index": false,
            "inherited": null,
            "originalClass": null,
            "originalField": null,
            "quoted": null,
            "declared": null,
            "declaredField": null,
            "options": null,
            "version": null,
            "default": null,
            "type": "string",
            "fieldName": "title",
            "columnName": "title"
        },
        "price": {
            "length": null,
            "id": null,
            "nullable": false,
            "notInsertable": null,
            "notUpdatable": null,
            "columnDefinition": null,
            "generated": null,
            "enumType": null,
            "precision": null,
            "scale": null,
            "unique": false,
            "index": false,
            "inherited": null,
            "originalClass": null,
            "originalField": null,
            "quoted": null,
            "declared": null,
            "declaredField": null,
            "options": null,
            "version": null,
            "default": null,
            "type": "integer",
            "fieldName": "price",
            "columnName": "price"
        },
        "topics": {
            "length": null,
            "id": null,
            "nullable": true,
            "notInsertable": null,
            "notUpdatable": null,
            "columnDefinition": null,
            "generated": null,
            "enumType": null,
            "precision": null,
            "scale": null,
            "unique": false,
            "index": false,
            "inherited": null,
            "originalClass": null,
            "originalField": null,
            "quoted": null,
            "declared": null,
            "declaredField": null,
            "options": null,
            "version": null,
            "default": null,
            "type": "json",
            "fieldName": "topics",
            "columnName": "topics"
        }
    }
}

which we can then filter using jq - for example :


symfony console doctrine:mapping:describe App\\Entity\\Book --format=json | jq '.fieldMappings | to_entries | map({(.key): .value.type}) | add'

will output a simple fieldMapping + typehint list
image

Bonus small fix of embeddedClasses output which falsely returned subClasses

**Original Pull Request:** https://github.com/doctrine/orm/pull/12071 **State:** closed **Merged:** Yes --- Following suggestion from https://github.com/doctrine/DoctrineBundle/issues/1883, this PR adds the `--format=json `option to the `orm:mapping:describe` command to enable JSON output (hence allowing [jq](https://jqlang.org/) filtering of said-output). For example, when running `symfony console doctrine:mapping:describe App\\Entity\\Book --format=json`, we get the following output : ```json { "name": "App\\Entity\\Book", "rootEntityName": "App\\Entity\\Book", "customGeneratorDefinition": null, "customRepositoryClassName": "App\\Repository\\BookRepository", "isMappedSuperclass": false, "isEmbeddedClass": false, "parentClasses": [], "subClasses": [], "embeddedClasses": [], "identifier": [ "id" ], "inheritanceType": 1, "discriminatorColumn": null, "discriminatorValue": null, "discriminatorMap": [], "generatorType": 4, "table": { "name": "book" }, "isIdentifierComposite": false, "containsForeignIdentifier": false, "containsEnumIdentifier": false, "sequenceGeneratorDefinition": null, "changeTrackingPolicy": 1, "isVersioned": false, "versionField": null, "isReadOnly": false, "entityListeners": [], "associationMappings": { "author": { "cascade": [], "fetch": 2, "inherited": null, "declared": null, "cache": null, "id": null, "isOnDeleteCascade": true, "originalClass": null, "originalField": null, "orphanRemoval": false, "unique": null, "fieldName": "author", "sourceEntity": "App\\Entity\\Book", "targetEntity": "App\\Entity\\Author", "inversedBy": "books", "indexBy": null, "orderBy": [], "joinTable": { "quoted": null, "joinColumns": [ { "deferrable": null, "unique": null, "quoted": null, "fieldName": null, "onDelete": "CASCADE", "columnDefinition": null, "nullable": null, "options": null, "name": "book_id", "referencedColumnName": "id" } ], "inverseJoinColumns": [ { "deferrable": null, "unique": null, "quoted": null, "fieldName": null, "onDelete": "CASCADE", "columnDefinition": null, "nullable": null, "options": null, "name": "author_id", "referencedColumnName": "id" } ], "options": [], "schema": null, "name": "book_author" }, "joinTableColumns": [ "book_id", "author_id" ], "relationToSourceKeyColumns": { "book_id": "id" }, "relationToTargetKeyColumns": { "author_id": "id" } } }, "fieldMappings": { "id": { "length": null, "id": true, "nullable": false, "notInsertable": null, "notUpdatable": null, "columnDefinition": null, "generated": null, "enumType": null, "precision": null, "scale": null, "unique": false, "index": false, "inherited": null, "originalClass": null, "originalField": null, "quoted": null, "declared": null, "declaredField": null, "options": null, "version": null, "default": null, "type": "integer", "fieldName": "id", "columnName": "id" }, "title": { "length": 255, "id": null, "nullable": false, "notInsertable": null, "notUpdatable": null, "columnDefinition": null, "generated": null, "enumType": null, "precision": null, "scale": null, "unique": false, "index": false, "inherited": null, "originalClass": null, "originalField": null, "quoted": null, "declared": null, "declaredField": null, "options": null, "version": null, "default": null, "type": "string", "fieldName": "title", "columnName": "title" }, "price": { "length": null, "id": null, "nullable": false, "notInsertable": null, "notUpdatable": null, "columnDefinition": null, "generated": null, "enumType": null, "precision": null, "scale": null, "unique": false, "index": false, "inherited": null, "originalClass": null, "originalField": null, "quoted": null, "declared": null, "declaredField": null, "options": null, "version": null, "default": null, "type": "integer", "fieldName": "price", "columnName": "price" }, "topics": { "length": null, "id": null, "nullable": true, "notInsertable": null, "notUpdatable": null, "columnDefinition": null, "generated": null, "enumType": null, "precision": null, "scale": null, "unique": false, "index": false, "inherited": null, "originalClass": null, "originalField": null, "quoted": null, "declared": null, "declaredField": null, "options": null, "version": null, "default": null, "type": "json", "fieldName": "topics", "columnName": "topics" } } } ``` which we can then filter using jq - for example : ```bash symfony console doctrine:mapping:describe App\\Entity\\Book --format=json | jq '.fieldMappings | to_entries | map({(.key): .value.type}) | add' ``` will output a simple fieldMapping + typehint list <img width="1688" height="157" alt="image" src="https://github.com/user-attachments/assets/a18c1d73-1aff-428c-bf85-16112e48e3a7" /> Bonus small fix of embeddedClasses output which falsely returned subClasses
admin added the pull-request label 2026-01-22 16:17:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#13455