Git Product home page Git Product logo

Comments (7)

janruo avatar janruo commented on July 28, 2024 1
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.

domoritz avatar domoritz commented on July 28, 2024

Can you describe how that should look like in the schema? It may already be possible.

from ts-json-schema-generator.

mikesnare avatar mikesnare commented on July 28, 2024

@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.

domoritz avatar domoritz commented on July 28, 2024

Don't we have support for format already?

from ts-json-schema-generator.

mikesnare avatar mikesnare commented on July 28, 2024

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.

mikesnare avatar mikesnare commented on July 28, 2024

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.

mikesnare avatar mikesnare commented on July 28, 2024

Beautiful. Honestly, I can't believe I didn't just try that. Thanks!

from ts-json-schema-generator.

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.