Closed terary closed 3 years ago
index.ts
export interface Bar {
name: 'bar';
}
export interface Foo {
bar: Bar;
}
typeconv -f ts -t oapi --oapi-format yaml --oapi-version 3 './**/*.ts'
Converted 2 types in 1 files, in 0.0s
openapi: 3.0.0
info:
title: Converted from index.yaml with typeconv
version: '3'
paths: {}
$id: index.yaml
$comment: >-
Generated from index.ts by core-types-json-schema
(https://github.com/grantila/core-types-json-schema) on behalf of typeconv
(https://github.com/grantila/typeconv)
components:
schemas:
Bar:
properties:
name:
const: bar
type: string
required:
- name
additionalProperties: false
type: object
Foo:
properties:
bar:
$ref: '#/components/schema/Bar'
required:
- bar
additionalProperties: false
type: object
openapi: 3.0.0
info:
title: Converted from index.yaml with typeconv
version: '3'
paths: {}
$id: index.yaml
$comment: >-
Generated from index.ts by core-types-json-schema
(https://github.com/grantila/core-types-json-schema) on behalf of typeconv
(https://github.com/grantila/typeconv)
components:
schemas:
Bar:
properties:
name:
const: bar
type: string
required:
- name
additionalProperties: false
type: object
Foo:
properties:
bar:
$ref: '#/components/schemas/Bar'
required:
- bar
additionalProperties: false
type: object
find . -type f -name '*.yaml' -print0 | xargs -0 sed -i '' -e 's/components\/schema/components\/schemas/g'
Just wanted to say that I think this library it a really awesome piece of code. Its saved me hours and hours so far.
Ive also noticed this problem, and a little further one as well (but I think related)
references from other files dont have the filename.
if I have
//foo.d.ts
export type Thingy = {
a: number
}
//top-level.d.ts
import {Thingy} from './foo.d.ts'
export Flubber = {
flub: Thingy
}
when these are converted to openAPI schema the reference within Flubber is
bar:
$ref: '#/components/schema/Thingy'
but I expect it should be
bar:
$ref: 'foo.yaml#/components/schema/Thingy'
Interesting, I'll certainly look into this.
The last example, I'm afraid there's no plan to support typescript referencing other files. That escalates quickly into something pretty complex, needing to really understand how TypeScript handles types, rather than "just" extracting them from a single-file AST. Perhaps there are tools that can bundle this for you as a pre-processing step?
:tada: This issue has been resolved in version 1.5.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Schema ref are missing "s"
- $ref: '#/components/schema/TJunctionOperator'
Its a minor thing with a big impact.