-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Feature request: support for external files in $ref #892
Comments
This does support remote But perhaps there’s some feature of remote |
Are local $refs also supported? |
In-document |
My colleagues mentioned that much-desired feature didn't work for them. I'll test it out myself soon and report back. :) |
@drwpow can you please give me a tip on what needs to be fixed here? root.yaml responses:
'200':
content:
application/json:
schema: { $ref: 'coupon_response.yaml#/CouponResponse' } coupon_response.yaml CouponResponse:
type: array
items: { $ref: 'coupon.yaml#/Coupon' } Skipping Coupon for now. Generated: 'application/json': external['coupon_response.yaml']['CouponResponse']; and export interface external {
'coupon_response.yaml': {
paths: {};
components: {};
operations: {};
};
I'm ignore the coupon file to try to simplify this example but happy to provide it. |
@joshunger Have you tried using paths like |
Anyway I had forgotten to report back as promised. The feature does work even locally, the only issue is that I had to keep the api paths in the central yaml file, so i could only split the components out of it. |
@berzi still empty can you share a snippet you're using? Thanks. |
# openapi.yaml
# ...
paths:
/users/{userId}:
parameters:
- $ref: './users.yaml#/components/parameters/UserParameter'
get:
description: |
Information about the currently logged in user.
responses:
'200':
content:
application/json:
schema:
$ref: './users.yaml#/components/schemas/User' # users.yaml
# ...
components:
parameters:
UserParameter:
name: userId
in: path
schema:
type: string
required: true
schemas:
User:
type: object
required:
- id
properties:
id:
type: number
name:
type: string |
@berzi thanks, putting it under |
In my case, Like paths:
/users:
$ref: '../resources/users.yaml'
/users/{userId}:
$ref: '../resources/users-by-id.yaml' src: https://swagger.io/docs/specification/using-ref/#allowed-places It fails to generate valid typescript code
|
You're right, that is currently unsupported. Unfortunately I don't have the time to implement this right now though, maybe some other contributor can? The code is in this function and should simply be instructed to resolve the reference if it is one. |
Update: a recent update did fix some bugs with external $refs. I’m going to close the issue as I believe this has been resolved, but please let me know if anyone is experiencing further issues. |
The OpenAPI specification explicitly declares support for splitting specification files into multiple files, referencing the pieces through
$ref
.As far as I know, this is not supported by openapi-typescript, and as a result any user of this utility must forgo the ability to split up their API spec file, which for larger applications can result in files spanning multiple thousands of lines.
I think this feature would be a very important addition, not to mention that ideally, the utility should support everything that the OpenAPI specification allows to avoid forcing users out of desirable features.
The text was updated successfully, but these errors were encountered: