openapi-typescript-codegen
openapi-typescript-codegen copied to clipboard
$ref: ./file.yaml: can't resolve components defined in a different file
Hey,
I want to use components that are defined in different file, but it's impossible to share let's say enum (or any other component).
This makes $ref: files
unusable (except to few top level fields like paths
or componetns
)
package.json
{
"devDependencies": {
"openapi-typescript-codegen": "^0.23.0"
}
}
spec.yaml
openapi: 3.0.0
info:
version: 0.0.1
paths:
/a:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/TypeA'
components:
schemas:
# I want to store component type per file
# but it's impossible to use a component defined
# in different file
SharedEnumType:
type: string
enum: ['PENDING', 'DONE']
TypeA:
$ref: './type_a.yaml'
TypeB:
type: object
properties:
b:
$ref: '#/components/schemas/SharedEnumType'
type_a.yaml
type: object
properties:
a:
$ref: '#/components/schemas/SharedEnumType' # works with type: string or if this is include in spec.yaml directly
cmd to run:
npx openapi -i spec.yaml -o gen -c axios
result:
// ....
code: 'EMISSINGPOINTER',
message: 'Token "components" does not exist.',
source: '/home/user/src/openapi-test/type_a.yaml',
path: null,
toJSON: [Function: toJSON],
name: 'MissingPointerError',
footprint: 'null+/home/user/src/openapi-test/type_a.yaml+EMISSINGPOINTER+Token "components" does not exist.',
toString: [Function: toString]
Any updates on this ? I am facing similar issue.
Also facing this issue, any update or work around?
I'm having the same problem.
Same here. Version 0.25.0
same issue 0.28.0
@anatolii-yemets @derekdkim @joaoflaviosantos @tiny-dancer @lubosnik @krhubert Hey, I am taking a look at this issue. I would just say to check out @hey-api/openapi-ts which was originally a fork of this repository but will be maintained and updated (DISCLAIMER: I am a contributor).
Are you all managing your openapi specs manually? I have been able to modify the specs and get it working:
spec.yaml
:
openapi: 3.0.0
info:
version: 0.0.1
paths:
/a:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/TypeA'
components:
schemas:
# I want to store component type per file
# but it's impossible to use a component defined
# in different file
SharedEnumType:
type: string
enum: ['PENDING', 'DONE']
TypeA:
$ref: 'type_a.yaml#/components/schemas/TypeA'
TypeB:
type: object
properties:
b:
$ref: '#/components/schemas/SharedEnumType'
type_a.yaml
:
components:
schemas:
TypeA:
type: object
properties:
a:
$ref: 'spec.yaml#/components/schemas/SharedEnumType'
I made these changes based on this documentation here. If you want to update to use our repository (@hey-api/openapi-ts) feel free to do so! and open any issues there or let me know if you are still running into this problem.
Thanks!