api-platform / schema-generator

PHP Model Scaffolding from Schema.org and other RDF vocabularies
https://api-platform.com/docs/schema-generator/
MIT License
453 stars 108 forks source link

Using labels instead of the local IDs for naming API resources and PHP classes #412

Open Angatar opened 9 months ago

Angatar commented 9 months ago

Description

The schema-generator currently defines the API resources and PHP classes names using the designated vocabulary/ontology classes' local IDs (=ID of the URI fragment identifier). If we want to use another name for the corresponding Entities/classes we have to set it manually in the config file. This behavior is quite OK when using small config or if the vocabulary/ontology is using comprehensive IDs like with Schema.org, but it is not OK with any extensive use of vocabulary/ontology like OBO ontologies or wikidata that are using numerical IDs. https://obofoundry.org/ https://www.wikidata.org/

It would be great to have a new configuration option allowing to name Entities/PHP classes from the corresponding vocabularies/ontologies labels instead of using the ID part of their URI fragment Identifier.

Example

As an example, the run of schema-generator with the following small graph

vocabularies:

Should lead to the creation of intelligible PHP files names.

Blocking_antibody.php Virus_neutralizing_antibody.php

In this example the list of exposed API resources should only contain Virus_neutralizing_antibody as it is a child of Blocking_antibody in the provided graph

Advantages

This feature would widely enable api-platform with the generation of intelligible APIs from all vocabularies/ontologies, even the ones using numerical IDs, including the structured data from Wikidata and OBO ontologies.

A basic use case would be to make it possible to simply generate an API with the API platform schema generator directly from a project ontology that contains Wikidata and/or OBO resources as entities classes.