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

Feature clarification request: multiple schemas

Open melissag opened this issue 1 year ago • 5 comments

Hoping to clarify the documentation at https://openapi-ts.pages.dev/cli#multiple-schemas; the example provided in the section specifies the output for both apis to be ./openapi/openapi.ts, which implies to me that both api schemas would be merged into a single file. However, when I try this with my own api schemas, the output file is overwritten by each subsequent api declaration - the api which is alphabetically last will "win" the output file. Is this the expected behavior? If so, should the documentation be corrected to have distinct output paths?

melissag avatar Dec 29 '23 18:12 melissag

Ah if you’re looking to bundle schemas, then you should use the Redocly CLI bundle command. That needs to be run before openapi-typescript.

I’d welcome an addition to the docs that clarifies this (perhaps something like a tip added):

::: tip

This will preserve schemas 1:1 input:output. To bundle multiple schemas into one, use Redocly’s [bundle command](https://redocly.com/docs/resources/multi-file-definitions/#bundle)

:::

Feel free to adjust the wording 🙂

drwpow avatar Jan 19 '24 05:01 drwpow

On the same topic what if we have:

  • reference.json - which contains $defs
  • openapi.yaml file that references the defs from the reference.json file

Is it possible to make it work? I don't see an example of this use case in the docs.

mariusflorescu avatar Jan 19 '24 15:01 mariusflorescu

@drwpow Thanks for your response. In particular your call out that This will preserve schemas 1:1 input:output suggests to me that the existing documentation example should be updated in the following way:

Current

apis:
  core@v2:
    root: ./openapi/openapi.yaml
    x-openapi-ts:
      output: ./openapi/openapi.ts
  external@v1:
    root: ./openapi/external.yaml
    x-openapi-ts:
      output: ./openapi/openapi.ts

Updated

apis:
  core@v2:
    root: ./openapi/openapi.yaml
    x-openapi-ts:
      output: ./openapi/openapi.ts
  external@v1:
    root: ./openapi/external.yaml
    x-openapi-ts:
      output: ./openapi/external.ts  # note updated name

Does this make sense to you, or am I still confused on how this is meant to work?

melissag avatar Jan 31 '24 23:01 melissag

@melissag yes! Apologies for not even noticing the typo in the docs. Yes that’s confusing, and your proposal is exactly how it should work. Would welcome a PR if you have time!

drwpow avatar Jan 31 '24 23:01 drwpow

Done, thanks for the guidance! Let me know if I goofed on anything in the PR process, not super familiar.

melissag avatar Feb 01 '24 17:02 melissag

This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

github-actions[bot] avatar Aug 06 '24 12:08 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

github-actions[bot] avatar Aug 14 '24 02:08 github-actions[bot]