Skip to content

Add JSON format option for orm:mapping:describe command output#12071

Merged
greg0ire merged 2 commits intodoctrine:3.6.xfrom
stlgaits:mapping-command-json-output
Jul 23, 2025
Merged

Add JSON format option for orm:mapping:describe command output#12071
greg0ire merged 2 commits intodoctrine:3.6.xfrom
stlgaits:mapping-command-json-output

Conversation

@stlgaits
Copy link
Copy Markdown
Contributor

Following suggestion from doctrine/DoctrineBundle#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

@stlgaits stlgaits marked this pull request as ready for review July 11, 2025 10:07
@greg0ire

This comment was marked as resolved.

@stlgaits stlgaits force-pushed the mapping-command-json-output branch from dc3fb09 to 021c815 Compare July 11, 2025 14:34
@stlgaits
Copy link
Copy Markdown
Contributor Author

I've just updated the command help / description + added autocomplete for --format option (with text as default )

@greg0ire

This comment was marked as resolved.

@greg0ire

This comment was marked as resolved.

@stlgaits stlgaits force-pushed the mapping-command-json-output branch from 021c815 to f68b1d3 Compare July 12, 2025 11:30
@stlgaits stlgaits force-pushed the mapping-command-json-output branch 2 times, most recently from 45b9e8f to 915f5ed Compare July 21, 2025 13:03
@stlgaits stlgaits force-pushed the mapping-command-json-output branch from ec98aea to 88c395c Compare July 22, 2025 07:45
@greg0ire greg0ire requested a review from SenseException July 22, 2025 07:59
@greg0ire greg0ire added this to the 3.6.0 milestone Jul 23, 2025
@greg0ire greg0ire merged commit a2990e1 into doctrine:3.6.x Jul 23, 2025
85 checks passed
@greg0ire
Copy link
Copy Markdown
Member

Thanks @stlgaits !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants