Comments (7)
export class Whatever {
/** @format date-time */
aDateString: string;
}
This seems to be the way.
I don't even remember how I figured this out myself, because it is undocumented. Supported tags can be found in the source: https://github.com/vega/ts-json-schema-generator/blob/next/src/AnnotationsReader/BasicAnnotationsReader.ts
from ts-json-schema-generator.
Can you describe how that should look like in the schema? It may already be possible.
from ts-json-schema-generator.
@domoritz It would just be a string type with a format of date-string:
"properties": {
"awarded_at": {
"type": "string"
"format": "date-time"
}
},
The problem here is that in my TS file, the awarded_at
property is typed as a simple string
, not a Date
.
from ts-json-schema-generator.
Don't we have support for format already?
from ts-json-schema-generator.
Yes, but only if the type of the property in the TS file is a Date. In my case it's a string. It happens to be a string that is an iso-8601 date-time and I'd like to be able to have that fact reflected in the schema.
from ts-json-schema-generator.
Example with comments that illustrates the point:
export class Whatever {
/**
* This is a string, but it happens to be an ISO-8601 encoded time. I don't want to have to go
* through the trouble of parsing this into an actual Date instance when it comes off the wire.
* I want to leave it as a string to keep the marshaling code simple. But it would be nice if
* there were a way for me to annotate this property somehow to tell ts-json-schema-generator
* that, while this is "just" a string, it should use the date-time format in the schema.
*/
aDateString: string;
}
from ts-json-schema-generator.
Beautiful. Honestly, I can't believe I didn't just try that. Thanks!
from ts-json-schema-generator.
Related Issues (20)
- RegExp types are now emitted, breaking schema validation (v2.1.1) HOT 1
- Error when following exports?
- Dist types now require @types/ts-expose-internals HOT 9
- Fix CJS imports HOT 8
- Invalid index in type HOT 11
- CLI - ENOENT: no such file or directory, open 'package.json' HOT 3
- Error: Unknown type "undefined" HOT 2
- Required types not allowed HOT 1
- Generator crashed when no package version is set HOT 4
- Breaking changes from v1 to v2 HOT 1
- Support for `"format": "uri-reference"` HOT 3
- Incorrect typing when a type uses Omit and inherits properties from a grandparent interface
- `--expose all` breaks generation with generic types. HOT 4
- How do you use ajv with references? HOT 4
- create schema uses `anyOf` instead of `allOf` HOT 5
- When I use discriminator, I am getting an error where it can't find the specific field HOT 1
- Allow using dependencies schema on certain prop HOT 4
- Undefined reference in ObjectLiteralExpressionNodeParser when using typeof on a spread const
- Schema generator fails when nested property name is StringLiteral (kind 11) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-json-schema-generator.