`oav generate-examples` on typespec with `byte` generates invalid examples
- Dominant language
- TypeScript
- Stars
- 104
- Forks
- 62
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 5
Description
[Discovered in this typespec generated PR](https://github.com/Azure/azure-rest-api-specs/pull/26146/files#diff-b778072065da049405b5ce6d1f38c84c6c7c12a853b7e4a59806bdb036332c20)
User entered `oav generate-examples ./generated.json` using the `generated.json` spec present in above PR.
[Here is an example of the specific place in the generated example that was problematic.](https://github.com/Azure/azure-rest-api-specs/pull/26146/files#r1369412256)
Prior to user manually correcting with `""` these were generated with values that _failed_ validation. Specifically:
```
{
message: [ {
code: 'INVALID_TYPE',
message: 'Expected type string but found type object',
schemaUrl: '.\\ImageAnalysis.json',
exampleUrl: 'examples\\SegmentFromStream_MaximumSet_Gen.json',
schemaPosition: {
line: 139, column: 23
}
,
schemaJsonPath: '#/properties/body/type',
examplePosition: {
line: 7, column: 21
}
,
exampleJsonPath: '$parameters.imageContent',
severity: 0,
source: 'request',
operationId: 'SegmentFromStream',
[Symbol(level)]: 'error',
[Symbol(message)]: '{"code":"INVALID_TYPE","exampleJsonPath":"$parameters.imageContent","examplePosition":{"column":21,"line":7},"exampleUrl":"examples\\\\SegmentFromStream_MaximumSet_Gen.json","level":"error","message":"Expected type string but found type object","operationId":"SegmentFromStream","schemaJsonPath":"#/properties/body/type","schemaPosition":{"column":23,"line":139},"schemaUrl":".\\\\ImageAnalysis.json","severity":0,"source":"request"}'
}
level: '\x1B[31merror\x1B[39m'
}
```
This is because the `imageContent` was generating with erroneous value `{}`. User correct `{}` to `""` and example passed validation.
Contributor guide
Research direction
Reproduce the issue with `oav generate-examples ./generated.json` using the `generated.json` spec from PR 26146, then validate the generated example. Inspect how the `byte`-typed `imageContent` value for `SegmentFromStream` is generated; done means the output uses a string value rather than `{}` and passes validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- cli, testing, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100