grantila / typeconv

Convert between JSON Schema, TypeScript, GraphQL, Open API and SureType
MIT License
421 stars 8 forks source link

Add option to read stdin #23

Open notpushkin opened 2 years ago

notpushkin commented 2 years ago

There's already -O -. typeconv could take - as input, too. (It would probably imply writing to stdout as well, since filename can't be determined automatically)

Use case

We already can do this:

npx typeconv -f ts -t jsc -O - models.ts | datamodel-codegen > models.py

Why not the other way around?

# generate_jsonschema.py

import json
from pydantic.schema import schema
from models import *

print(json.dumps(schema([MyModel, ...]), indent=2))
python generate_jsonschema.py | npx typeconv -f jsc -t ts - > models.ts