|
| 1 | +# Should handle flatten model with all readonly properties correctly |
| 2 | + |
| 3 | +## TypeSpec |
| 4 | + |
| 5 | +This is tsp definition. |
| 6 | + |
| 7 | +```tsp |
| 8 | +
|
| 9 | +model SolutionProperties { |
| 10 | + @visibility(Lifecycle.Read) |
| 11 | + solutionId?: string; |
| 12 | +
|
| 13 | + @visibility(Lifecycle.Read) |
| 14 | + title?: string; |
| 15 | +
|
| 16 | + @visibility(Lifecycle.Read) |
| 17 | + content?: string; |
| 18 | +} |
| 19 | +model Solution{ |
| 20 | + @Azure.ClientGenerator.Core.Legacy.flattenProperty |
| 21 | + properties: SolutionProperties; |
| 22 | + @Azure.ClientGenerator.Core.Legacy.flattenProperty |
| 23 | + propertiesOptional?: SolutionProperties; |
| 24 | +} |
| 25 | +op test(@body body:Solution):void; |
| 26 | +
|
| 27 | +``` |
| 28 | + |
| 29 | +Enable the raw content with TCGC dependency. |
| 30 | + |
| 31 | +```yaml |
| 32 | +needTCGC: true |
| 33 | +``` |
| 34 | +
|
| 35 | +## Models |
| 36 | +
|
| 37 | +```ts models |
| 38 | +import { areAllPropsUndefined } from "../static-helpers/serialization/check-prop-undefined.js"; |
| 39 | + |
| 40 | +/** |
| 41 | + * This file contains only generated model types and their (de)serializers. |
| 42 | + * Disable the following rules for internal models with '_' prefix and deserializers which require 'any' for raw JSON input. |
| 43 | + */ |
| 44 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 45 | +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ |
| 46 | +/** model interface Solution */ |
| 47 | +export interface Solution { |
| 48 | + readonly solutionId?: string; |
| 49 | + readonly title?: string; |
| 50 | + readonly content?: string; |
| 51 | + readonly solutionIdPropertiesOptionalSolutionId?: string; |
| 52 | + readonly titlePropertiesOptionalTitle?: string; |
| 53 | + readonly contentPropertiesOptionalContent?: string; |
| 54 | +} |
| 55 | + |
| 56 | +export function solutionSerializer(item: Solution): any { |
| 57 | + return { |
| 58 | + properties: _solutionPropertiesSerializer(item), |
| 59 | + propertiesOptional: areAllPropsUndefined(item, []) |
| 60 | + ? undefined |
| 61 | + : _solutionPropertiesOptionalSerializer(item), |
| 62 | + }; |
| 63 | +} |
| 64 | + |
| 65 | +/** model interface SolutionProperties */ |
| 66 | +export interface SolutionProperties { |
| 67 | + readonly solutionId?: string; |
| 68 | + readonly title?: string; |
| 69 | + readonly content?: string; |
| 70 | +} |
| 71 | + |
| 72 | +export function solutionPropertiesSerializer(item: SolutionProperties): any { |
| 73 | + return item; |
| 74 | +} |
| 75 | + |
| 76 | +export function _solutionPropertiesSerializer(item: Solution): any { |
| 77 | + return item; |
| 78 | +} |
| 79 | + |
| 80 | +export function _solutionPropertiesOptionalSerializer(item: Solution): any { |
| 81 | + return item; |
| 82 | +} |
| 83 | +``` |
0 commit comments