Encoded names
There is some cases where the name you have in TypeSpec might differ from the name over the wire or for a certain language.
Update name for a given target
To update the name of a TypeSpec entity you can use the @encodedName
decorator. This decorator takes 2 parameters:
Parameter | Type | Description |
---|---|---|
mimeType | string | Mime type this should apply to. The mime type should be a known mime type as described here https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types without any suffix (e.g. +json ) |
encodedName | string | The name should be when serialized to the given mime type. |
Example:
Example
Json | Xml | Yaml |
---|---|---|
When serialized to `application/json` properties will use the encodedName for `application/json` if available or default to the property name. | When serialized to `application/xml` properties will use the encodedName for `application/xml` if available or default to the property name. | Yaml didn't provide any different names so it will serialize using the property names. |
Use in library/emitter
To consume the value of @encodedName
in your library or emitter you can use resolveEncodedName(target: Type, mimeType: string): string
from the compiler.