vault/ui/docs/serializers-adapters.md
claire bontempo ea292e8142
Ui: Add contributing pattern doc (#19897)
* format readme to prepare for pattern info

* small text changes

* add markdown files for each section

* readme updates

* routing md draft

* add table of contents

* add oidc pr sample

* update routing

* add decorator section

* serializer docs

* add table of contents

* update readme

* add title

* add decorator section

* models readme

* update comments

* modify examples

* add bullets and more comments

* what the heck fix bullet

* model docs

* form docs

* routing doc

* serializer/adapter

* adds docs for model-validations decorator (#20596)

* UI Docs: Components (#20602)

* Add CSS best practices (#20370)

* wip--saving work

* wip

* friday morning....

* update

* fix exists to exist

* one more change

* UI docs: Add ember engine creation documentation (#20789)

---------

Co-authored-by: Jordan Reimer <zofskeez@gmail.com>
Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
2023-05-30 10:24:35 -07:00

30 lines
1.2 KiB
Markdown

# Serializers & Adapters
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [Guidelines](#guidelines)
- [Gotchas](#gotchas)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## Guidelines
- Prepend internal functions with an underscore to differentiate from Ember methods `_getUrl`
- Consider using the [named-path](../app/adapters/named-path.js) adapter if the model name is part of the request path
- Utilize the serializer to remove sending model attributes that do not correspond to an API parameter. Example in [key serializer](../app/serializers/pki/key.js)
```js
export default class SomeSerializer extends ApplicationSerializer {
attrs = {
attrName: { serialize: false },
};
}
```
> Note: this will remove the attribute when calling `snapshot.serialize()` even if the method is called within the serialize method where custom logic may be written
## Gotchas
- The JSON serializer removes attributes with empty arrays [Example in MFA serializer](https://github.com/hashicorp/vault/blob/e55c18ed1299e0d36b88e603fa9f12adaf8e75dc/ui/app/serializers/mfa-login-enforcement.js#L37-L44)