Skip to content

Commit a41cb00

Browse files
committed
Merge branch 'master' of github.com:api-platform/doc
2 parents 7267cbd + 99dc55c commit a41cb00

File tree

3 files changed

+333
-493
lines changed

3 files changed

+333
-493
lines changed

generate-crud/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Works especially well with APIs built with the [API Platform](https://api-platfo
1818
* The generated HTML code is accessible to people with disabilities ([ARIA](https://www.w3.org/WAI/intro/aria) support)
1919
* The Redux and the React Router configuration is also generated
2020

21-
Previous chapter: [Using API Platform with Docker](../deployment/docker.md)
21+
Previous chapter: [API Platform Admin: Handling Relations to Collections](../admin/handling-relations-to-collections.md)
2222

2323
Next chapter: [Installation and Usage](installation-and-usage.md)

schema-generator/configuration.md

Lines changed: 141 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Example:
1111

1212
```yaml
1313
namespaces:
14-
entity: "Dunglas\EcommerceBundle\Entity"
15-
enum: "Dunglas\EcommerceBundle\Enum"
14+
entity: "Dunglas\EcommerceBundle\Entity"
15+
enum: "Dunglas\EcommerceBundle\Enum"
1616
interface: "Dunglas\EcommerceBundle\Model"
1717
```
1818
@@ -182,6 +182,30 @@ class Person
182182
private $email;
183183
```
184184

185+
## Making a Property Read Only
186+
187+
A property can be marked read only with the following configuration:
188+
189+
```yaml
190+
Person:
191+
properties:
192+
email: { writable: false }
193+
```
194+
195+
In such case, no mutator method will be generated.
196+
197+
## Making a Property Write Only
198+
199+
A property can be marked read only with the following configuration:
200+
201+
```yaml
202+
Person:
203+
properties:
204+
email: { radable: false }
205+
```
206+
207+
In this case, no getter method will be generated.
208+
185209
## Forcing a Property to be in a Serialization Group
186210

187211
Force a property to be in a `groups`.
@@ -281,13 +305,57 @@ annotationGenerators:
281305
- Acme\Generators\MyGenerator
282306
```
283307

284-
## Disabling `id` Generator
308+
## Skipping Accessor Method Generation
309+
310+
It's possible to skip the generation of accessor methods. This is particularly useful combined with the `visibility: public`
311+
option.
312+
313+
To skip the generation of accessor methods, use the following config:
314+
315+
```yaml
316+
accessorMethods: false
317+
```
285318

286-
By default, the generator adds a property called `id` not provided by Schema.org. This may be useful when generating an entity for use with an ORM or an ODM.
319+
It's possible to skip
320+
321+
## Disabling the `id` Generator
322+
323+
By default, the generator adds a property called `id` not provided by Schema.org.
324+
This is useful when generating an entity for use with an ORM or an ODM but not when generating DTOs.
287325
This behavior can be disabled with the following setting:
288326

289327
```yaml
290-
generateId: false
328+
id:
329+
generate: false
330+
```
331+
332+
## Generating UUIDs
333+
334+
It's also possible to let the DBMS generate [UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier) instead of autoincremented integers:
335+
336+
```yaml
337+
id:
338+
generationStrategy: uuid
339+
```
340+
341+
## User submitted UUIDs
342+
343+
To set manually a UUID instead of letting the DBMS generating it, use the following config:
344+
345+
```yaml
346+
id:
347+
generationStrategy: uuid
348+
writable: true
349+
```
350+
351+
## Generating Custom IDs
352+
353+
With this configuration option, an `$id` property of type `string` and the corresponding getters and setters will be
354+
generated, but the DBMS will not generate anything, the ID must be set manually.
355+
356+
```yaml
357+
id:
358+
generationStrategy: none
291359
```
292360

293361
## Disabling Usage of Doctrine Collection
@@ -301,7 +369,7 @@ doctrine:
301369
useCollection: false
302370
```
303371

304-
## Custom Field Visibility
372+
## Changing the Field Visibility
305373

306374
Generated fields have a `private` visibility and are exposed through getters and setters.
307375
The default visibility can be changed with the `fieldVisibility` otion.
@@ -312,6 +380,15 @@ Example:
312380
fieldVisibility: "protected"
313381
```
314382

383+
## Generating `@Assert\Type` Annotations
384+
385+
It's possible to automatically generate Symfony validator's `@Assert\Type` annotations using the following config:
386+
387+
```yaml
388+
validator:
389+
assertType: true
390+
```
391+
315392
## Forcing Doctrine Inheritance Mapping Annotation
316393

317394
The standard behavior of the generator is to use the `@MappedSuperclass` Doctrine annotation for classes with children and
@@ -401,41 +478,52 @@ header: |
401478
## Full Configuration Reference
402479

403480
```yaml
404-
# RDFa files to use
405-
rdfa:
481+
onfig:
406482
407-
# Prototype
408-
-
483+
# RDFa files
484+
rdfa:
409485
410-
# RDFa URI to use
411-
uri: 'https://schema.org/docs/schema_org_rdfa.html' # Example: https://schema.org/docs/schema_org_rdfa.html
486+
# Prototype
487+
-
412488
413-
# RDFa URI data format
414-
format: null # Example: rdfxml
489+
# RDFa URI to use
490+
uri: 'https://schema.org/docs/schema_org_rdfa.html' # Example: https://schema.org/docs/schema_org_rdfa.html
415491
416-
# OWL relation files to use
417-
relations:
492+
# RDFa URI data format
493+
format: null # Example: rdfxml
418494
419-
# Default:
420-
- https://purl.org/goodrelations/v1.owl
495+
# OWL relation files to use
496+
relations:
421497
422-
# Debug mode
423-
debug: false
498+
# Default:
499+
- https://purl.org/goodrelations/v1.owl
424500
425-
# Automatically add an id field to entities
426-
generateId: true
501+
# Debug mode
502+
debug: false
427503
428-
# Generate interfaces and use Doctrine's Resolve Target Entity feature
429-
useInterface: false
504+
# IDs configuration
505+
id:
430506
431-
# Emit a warning if a property is not derived from GoodRelations
432-
checkIsGoodRelations: false
507+
# Automatically add an id field to entities
508+
generate: true
433509
434-
# A license or any text to use as header of generated files
435-
header: false # Example: // (c) Kévin Dunglas <[email protected]>
510+
# The ID generation strategy to use ("none" to not let the database generate IDs).
511+
generationStrategy: auto # One of "auto"; "none"; "uuid"; "mongoid"
436512
437-
# PHP namespaces
438-
namespaces:
513+
# Is the ID writable? Only applicable if "generationStrategy" is "uuid".
514+
writable: false
515+
516+
# Generate interfaces and use Doctrine's Resolve Target Entity feature
517+
useInterface: false
518+
519+
# Emit a warning if a property is not derived from GoodRelations
520+
checkIsGoodRelations: false
521+
522+
# A license or any text to use as header of generated files
523+
header: false # Example: // (c) Kévin Dunglas <[email protected]>
524+
525+
# PHP namespaces
526+
namespaces:
439527
440528
# The namespace of the generated entities
441529
entity: AppBundle\Entity # Example: Acme\Entity
@@ -453,14 +541,26 @@ namespaces:
453541
useCollection: true
454542
455543
# The Resolve Target Entity Listener config file pass
456-
resolveTargetEntityConfigPath: null
544+
resolveTargetEntityConfigPath: null
545+
546+
# Symfony Validator Component
547+
validator:
548+
549+
# Generate @Assert\Type annotation
550+
assertType: false
457551
458552
# The value of the phpDoc's @author annotation
459553
author: false # Example: Kévin Dunglas <[email protected]>
460554
461555
# Visibility of entities fields
462556
fieldVisibility: private # One of "private"; "protected"; "public"
463557
558+
# Set this flag to false to not generate getter, setter, adder and remover methods
559+
accessorMethods: true
560+
561+
# Set this flag to true to generate fluent setter, adder and remover methods
562+
fluentMutatorMethods: false
563+
464564
# Schema.org's types to use
465565
types:
466566
@@ -484,14 +584,13 @@ namespaces:
484584
485585
# The namespace for the generated interface (override any other defined namespace)
486586
interface: null
487-
488587
doctrine:
489588
490589
# The Doctrine inheritance mapping type (override the guessed one)
491590
inheritanceMapping: null
492591
493592
# The parent class, set to false for a top level class
494-
parent: null
593+
parent: false
495594
496595
# If declaring a custom class, this will be the class from which properties type will be guessed
497596
guessFrom: Thing
@@ -518,7 +617,13 @@ namespaces:
518617
# Symfony Serialization Groups
519618
groups: []
520619
521-
# The property nullable
620+
# Is the property readable?
621+
readable: true
622+
623+
# Is the property writable?
624+
writable: true
625+
626+
# Is the property nullable?
522627
nullable: true
523628
524629
# The property unique
@@ -535,64 +640,10 @@ namespaces:
535640
536641
# Defaults:
537642
- ApiPlatform\SchemaGenerator\AnnotationGenerator\PhpDocAnnotationGenerator
538-
- ApiPlatform\SchemaGenerator\AnnotationGenerator\ConstraintAnnotationGenerator
539643
- ApiPlatform\SchemaGenerator\AnnotationGenerator\DoctrineOrmAnnotationGenerator
540644
- ApiPlatform\SchemaGenerator\AnnotationGenerator\ApiPlatformCoreAnnotationGenerator
541-
542-
543-
# RDFa files to use
544-
rdfa:
545-
546-
# Default:
547-
- http://schema.org/docs/schema_org_rdfa.html
548-
549-
# OWL relation files to use
550-
relations:
551-
552-
# Default:
553-
- http://purl.org/goodrelations/v1.owl
554-
555-
# Debug mode
556-
debug: false
557-
558-
# Automatically add an id field to entities
559-
generateId: true
560-
561-
# Generate interfaces and use Doctrine's Resolve Target Entity feature
562-
useInterface: false
563-
564-
# Emit a warning if a property is not derived from GoodRelations
565-
checkIsGoodRelations: false
566-
567-
# A license or any text to use as header of generated files
568-
header: false # Example: // (c) Kévin Dunglas <[email protected]>
569-
570-
# PHP namespaces
571-
namespaces:
572-
573-
# The namespace of the generated entities
574-
entity: SchemaOrg\Entity # Example: Acme\Entity
575-
576-
# The namespace of the generated enumerations
577-
enum: SchemaOrg\Enum # Example: Acme\Enum
578-
579-
# The namespace of the generated interfaces
580-
interface: SchemaOrg\Model # Example: Acme\Model
581-
582-
# Doctrine
583-
doctrine:
584-
585-
# Use Doctrine's ArrayCollection instead of standard arrays
586-
useCollection: true
587-
588-
# The Resolve Target Entity Listener config file pass
589-
resolveTargetEntityConfigPath: null
590-
591-
# The value of the phpDoc's @author annotation
592-
author: false # Example: Kévin Dunglas <[email protected]>
593-
594-
# Visibility of entities fields
595-
fieldVisibility: ~ # One of "private"; "protected"; "public"
645+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\ConstraintAnnotationGenerator
646+
- ApiPlatform\SchemaGenerator\AnnotationGenerator\SerializerGroupsAnnotationGenerator
596647
```
597648

598649
Previous chapter: [Getting Started](getting-started.md)

0 commit comments

Comments
 (0)