Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement OAS3.1 dynamic references #2029

Open
1 task
hesxenon opened this issue Dec 2, 2024 · 2 comments
Open
1 task

implement OAS3.1 dynamic references #2029

hesxenon opened this issue Dec 2, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library

Comments

@hesxenon
Copy link

hesxenon commented Dec 2, 2024

Description

Generic data types

Proposal

Apparently since OAS3.1 it is possible to define $dynamicAnchor and $dynamicRef to achieve something resembling higher kinded types.

It appears that this is not possible yet.

Given
EDIT: example below is flawed, see here for official example

paths:
  /foos:
    get:
      responses:
        200:
          description: returns foos
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/List"
                $dynamicAnchor: T
                properties:
                  foo:
                    type: number
                  bar:
                    type: string
components:
  schemas:
    List:
      type: array
      items:
        $dynamicRef: T

I'd expect (if I'm reading the scarce info correctly)

interface paths {
  "/foos": {
    get: {
      responses: {
        200: {
          content: {
            "application/json": Array<{foo: number, bar: string}> // since typescript does not have higher kinded types (yet) I think the anchor should directly merge with the ref?
          }
      }
    }
  }
}

interface components {
  schemas: {
    List: never; // types marked with $dynamicRef should probably be reduced to avoid accidental widening later on
  }
}

Checklist

  • I’m willing to open a PR for this (see CONTRIBUTING.md) - sorry, absolutely no time currently, maybe in a week or so
@hesxenon hesxenon added enhancement New feature or request openapi-ts Relevant to the openapi-typescript library labels Dec 2, 2024
@hesxenon
Copy link
Author

hesxenon commented Dec 2, 2024

it seems my testing method was wrong, I'll investigate further. Have updated the example with a link to the official docs

@drwpow
Copy link
Contributor

drwpow commented Dec 10, 2024

This is definitely something we’d love to support. I think this likely looks like something we could do in partnership with the Redocly Core library, since that handles resolution and normalization of the OpenAPI schemas. Plus, adding support there would be a win for many projects using either (did a quick search and it doesn’t seem like they support it today, but I could be mistaken).

@drwpow drwpow self-assigned this Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

2 participants