openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

@hey-api/schemas should support inline schemas

Open hlgrondijs opened this issue 6 months ago • 2 comments

Description

When using the @hey-api/schemas plugin, I found that it only creates types for the schemas defined in #/components/schemas.

However, many openapi.json files also include "inline" schemas, that can be found directly in the parameters field of a path. These schemas do not use a $ref reference to #/components/schemas but are defined in place. OpenAPI spec allows this and I would expect the @hey-api/schemas plugin to also pick up these inline schemas and generate types for them.

The input validation usecase described in your docs (https://heyapi.dev/openapi-ts/output/json-schema) is what my team is looking for. But, our openapi.json is generated by FastAPI which uses these "inplace schemas" for the request parameters and thus they will not be included in the generated code. FastAPI currently does not support placing parameter schemas in #/components/schemas.

hlgrondijs avatar Jul 10 '25 13:07 hlgrondijs

Hi @hlgrondijs I think it would be great if you can provide an example of the OpenAPI spec generated by FastAPI.

malcolm-kee avatar Aug 22 '25 07:08 malcolm-kee

here's a repro

I added an inline parameter at the pathItem and operation. Additionally, I added an example of using content to cover both schema and content scenarios

openapi: 3.1.0
info:
  title: 2295
  version: v1
paths:
  /things:
    parameters:
      - name: $count
        description: OData V4 $count query parameter
        in: query
        schema:
          type: boolean
        required: false
    get:
      parameters:
      - name: $filter
        description: OData V4 $filter query parameter
        in: query
        schema:
          type: string
        required: false
      - name: test
        in: query
        content:
          'application/json':
            schema:
              type: object
              additionalProperties: false
              required:
              - name
              properties:
                name:
                    type: string
                age:
                    type: number
        required: false
      responses:
        '200':
          description: OK
          content:
            'application/json':
              schema: {}

jeremyfiel avatar Oct 28 '25 15:10 jeremyfiel