microsoft / microsoft/typespec
Allow reusing models between `multipart/form-data` and `application/json` operations.
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Clear and concise description of the problem
As we are trying to ingest (using the `tsp-openapi3` tool) a spec that has operations that reuse some of the models across different content-types. We ran into the issue that there isn't a good way to represent this, given the requirement of wrapping all fields in the `HttpPart` template.
An example of what we are trying to represent:
```yaml
openapi: 3.1.0
info:
title: My Spec
paths:
/my-operation:
post:
operationId: myOperation
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/FooMultiPart'
application/json:
schema:
$ref: '#/components/schemas/FooJson'
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Bar'
components:
schemas:
FooMultiPart:
type: object
properties:
file:
type: string
format: binary
allOf:
- $ref: '#/components/schemas/FooJson'
required:
- file
FooJson:
type: object
properties:
name:
type: string
age:
type: integer
required:
- name
Bar:
type: object
properties:
id:
type: string
required:
- id
```
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [docs](https://typespec.io/docs/).
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Contributor guide
Assessment
This issue has not been assessed yet.