matrei opened a new pull request, #16829:
URL: https://github.com/apache/grails-core/pull/16829
## Description
`LinkGeneratorSpec` (`grails-web-url-mappings`) and
`PersistentEntitySchemaSpec` (`grails-openapi`) fail on every build of 8.0.x
since the merge-up of 7.2.x in f0b720b4f95:
```
LinkGeneratorSpec > cache key should use identity of resource value
cacheKey == "somePrefix[resource:org.grails.web.mapping.Widget->1]"
somePrefix[resource:org.grails.web.mapping.Widget->Some
Widget]
LinkGeneratorSpec > resource links should use ident and allow controller
override
link == "/bar/widget/show/1"
/bar/widget/index
PersistentEntitySchemaSpec > describes the resource as a plain type when the
application has no mapping context
!openApi.components.schemas['Widget'].properties.id?.readOnly
|
true
```
Both describe a domain class fixture whose id data binding used to bind and
since ce2db7a52d3 does not. The change is right, so this adapts the specs.
### Why the fixtures bound their id
Data binding does not bind the `id`, `version`, `dateCreated` and
`lastUpdated` of a domain class.
`DefaultASTDatabindingHelperDomainClassSpecialPropertiesSpec` checks that `new
MyDirtyCheckedDomain(id: 99L, version: 7L, name: 'Grace')` leaves the id
`null`. Until ce2db7a52d3 the white list that does this was generated by
`ControllerDomainTransformer.performInjection`, which a domain class in
`grails-app/domain` and one annotated with `grails.persistence.Entity` go
through. The fixtures are declared otherwise: as `@Artefact('Domain')` in
`LinkGeneratorSpec`, which gets its map constructor through
`performInjectionOnAnnotatedClass` but no list, and as a GORM `@Entity` in
`PersistentEntitySchemaSpec`. A class without a list is bound without
restriction, so the id was bound too.
Since ce2db7a52d3, a global transformation generates the list for every
class that declares `constraints` or `transients`, and GORM's entity
transformation gives every entity a `transients` list, so the fixtures get the
same list as any other domain class:
- `new Widget(id: 1, name: 'Some Widget')` binds the name but not the id, so
`ident()` returns `null`, and the link generator falls back to `toString()` for
the cache key and to the `index` action for the link.
- `GrailsModelConverter` describes as read-only the properties of a type
that its list leaves out, so the id of the OpenAPI fixture is now read-only,
with or without a mapping context.
### The specs
- `LinkGeneratorSpec` sets the id of a widget after constructing it, as an
application has to for a domain class.
- `PersistentEntitySchemaSpec` expects the id of a resource described
without a mapping context to be read-only, as data binding does not bind it.
What only GORM knows, that the properties are required, is still left out.
### Upgrade note 89
The same holds in an application, as far as I can see: a GORM entity
compiled outside `grails-app/domain`, in `src/main/groovy` or in another
module, got no white list before 7.0.18, so `bindData` and `properties =
params` bound its id and version, and now they do not. Upgrade note 89 lists
the classes that now get the list, but does not mention these entities. Should
it?
### Tests
The three features fail without the change. All tests of
`grails-web-url-mappings` and `grails-openapi` pass with it, and so does
`codeStyle` for both.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]