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

Schemas namespace missing for schema refs within parameter arrays #51

Open
njbair opened this issue Sep 10, 2024 · 3 comments
Open

Schemas namespace missing for schema refs within parameter arrays #51

njbair opened this issue Sep 10, 2024 · 3 comments

Comments

@njbair
Copy link

njbair commented Sep 10, 2024

A parameter of type array, with the items schema defined by reference, produces incorrect output.

Minimal example spec

openapi: 3.0.3
info:
  title: Test API Spec
  version: 1.0.0
components:
  schemas:
    Test:
      enum:
        - FOO
        - BAR
      type: string
paths:
  /test:
    get:
      operationId: getTest
      parameters:
        - in: query
          name: test
          schema:
            items:
              $ref: '#/components/schemas/Test'
            type: array
      responses:
        '200':
          content:
            application/json:
              schema: {}
servers:
  - url: https://api.example.com

...produces this:

  export type get_GetTest = {
    ...
    parameters: {
      query: Partial<{ test: Array<Test> }>;
    };
  };

...when it should produce this (note the Schemas prefix):

  export type get_GetTest = {
    ...
    parameters: {
      query: Partial<{ test: Array<Schemas.Test> }>;
    };
  };

I've spent three days trying to learn the code well enough to revise this and submit a PR, but I am feeling stuck. Seems like generator.ts is the place to do it, as that's where the Schemas namespace is being added to the body and response schemas. But I can't figure out how to use the recompute() method on the parameter Box objects. It seems like the object that's being passed to recompute() is different from the Box instance itself.

Can you offer any pointers on how the Box class works? Seems like there's lots of nesting, and I think I'm just getting lost in the weeds. Thanks.

@njbair

This comment was marked as outdated.

@astahmer
Copy link
Owner

uh honestly I haven't been in that codebase for a while, iirc the box thingy was so that the library could support multiple output (TS, zod, valibot, etc) but then I found typebox-workbench which already fulfilled that need
so I stopped working on the box stuff and left things mostly as they are and instead relied on the @sinclair/typebox-codegen for that

@njbair
Copy link
Author

njbair commented Sep 10, 2024

Thanks for the prompt reply. Seems like I might be better off using openapi-typescript. It's not perfect, but it seems like there's still a lot of active development over there.

Thanks for your work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants