Coder Social home page Coder Social logo

TS to OAPI about typeconv HOT 4 CLOSED

grantila avatar grantila commented on June 4, 2024 1
TS to OAPI

from typeconv.

Comments (4)

github-actions avatar github-actions commented on June 4, 2024 2

🎉 This issue has been resolved in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

from typeconv.

marcin-wlodarczyk avatar marcin-wlodarczyk commented on June 4, 2024

Input:

index.ts

export interface Bar {
    name: 'bar';
}

export interface Foo {
    bar: Bar;
}

Command:

typeconv -f ts -t oapi --oapi-format yaml --oapi-version 3 './**/*.ts'

Converted 2 types in 1 files, in 0.0s

Output (Wrong):

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

Expected Output:

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

Temporary solution:

find . -type f -name '*.yaml' -print0 | xargs -0 sed -i '' -e 's/components\/schema/components\/schemas/g'

from typeconv.

chrismatheson avatar chrismatheson commented on June 4, 2024

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'

from typeconv.

grantila avatar grantila commented on June 4, 2024

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?

from typeconv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.