Skip to content

Releases: acacode/swagger-typescript-api

11.1.1 Release

28 Oct 05:27
6285367
Compare
Choose a tag to compare

fix: --api-class-name option has no default value (#433)

11.1.0 Release

27 Oct 21:16
a6814dc
Compare
Choose a tag to compare

BREAKING_CHANGE: replace axios to node-fetch
feat: ability to send request options for getting swagger schema by url (requestOptions property)

11.0.0 Release

27 Oct 15:46
e64d703
Compare
Choose a tag to compare

Breaking changes

  • data-contract-jsdoc.ejs file uses new input structure. Please update your local copy.
  • new codebase (class way)
  • ability to change everything in codegen process configuration with using NodeJS Api
  • ability to call generateApi function 2 and more times per 1 NodeJS process.
  • new command generate-templates to create source templates

[feature] Ability to generate source templates

New command generate-templates which allow you to generate source templates which using with option --templates

[feature] Ability to modify internal codegen typescript structs

Everything which creates codegen about output typescript code now contains in Ts field in src/configuration.
And this thing is available for end user modifications with using NodeJS Cli option codeGenConstructs.
It contains almost all which is not contains in .eta\ .ejs templates. For example: Record<string, any>, readonly typeField?: value, etc

Structure of Ts property

 const Ts = {
    Keyword: {
      Number: "number",
      String: "string",
      Boolean: "boolean",
      Any: "any",
      Void: "void",
      Unknown: "unknown",
      Null: "null",
      Undefined: "undefined",
      Object: "object",
      File: "File",
      Date: "Date",
      Type: "type",
      Enum: "enum",
      Interface: "interface",
      Array: "Array",
      Record: "Record",
      Intersection: "&",
      Union: "|",
    },
    CodeGenKeyword: {
      UtilRequiredKeys: "UtilRequiredKeys",
    },
    /**
     * $A[] or Array<$A>
     */
    ArrayType: (content) => {
      if (this.anotherArrayType) {
        return Ts.TypeWithGeneric(Ts.Keyword.Array, [content]);
      }

      return `${Ts.ExpressionGroup(content)}[]`;
    },
    /**
     * "$A"
     */
    StringValue: (content) => `"${content}"`,
    /**
     * $A
     */
    BooleanValue: (content) => `${content}`,
    /**
     * $A
     */
    NumberValue: (content) => `${content}`,
    /**
     * $A
     */
    NullValue: (content) => content,
    /**
     * $A1 | $A2
     */
    UnionType: (contents) => _.join(_.uniq(contents), ` ${Ts.Keyword.Union} `),
    /**
     * ($A1)
     */
    ExpressionGroup: (content) => (content ? `(${content})` : ""),
    /**
     * $A1 & $A2
     */
    IntersectionType: (contents) => _.join(_.uniq(contents), ` ${Ts.Keyword.Intersection} `),
    /**
     * Record<$A1, $A2>
     */
    RecordType: (key, value) => Ts.TypeWithGeneric(Ts.Keyword.Record, [key, value]),
    /**
     * readonly $key?:$value
     */
    TypeField: ({ readonly, key, optional, value }) =>
      _.compact([readonly && "readonly ", key, optional && "?", ": ", value]).join(""),
    /**
     * [key: $A1]: $A2
     */
    InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
    /**
     * $A1 = $A2
     */
    EnumField: (key, value) => `${key} = ${value}`,
    /**
     * $A0.key = $A0.value,
     * $A1.key = $A1.value,
     * $AN.key = $AN.value,
     */
    EnumFieldsWrapper: (contents) =>
      _.map(contents, ({ key, value }) => `  ${Ts.EnumField(key, value)}`).join(",\n"),
    /**
     * {\n $A \n}
     */
    ObjectWrapper: (content) => `{\n${content}\n}`,
    /**
     * /** $A *\/
     */
    MultilineComment: (contents, formatFn) =>
      [
        ...(contents.length === 1
          ? [`/** ${contents[0]} */`]
          : ["/**", ...contents.map((content) => ` * ${content}`), " */"]),
      ].map((part) => `${formatFn ? formatFn(part) : part}\n`),
    /**
     * $A1<...$A2.join(,)>
     */
    TypeWithGeneric: (typeName, genericArgs) => {
      return `${typeName}${genericArgs.length ? `<${genericArgs.join(",")}>` : ""}`;
    },
  }

[feature] Ability to modify swagger schema type/format to typescript construction translators

Swagger schema has constructions like { "type": "string" | "integer" | etc, "format": "date-time" | "float" | "etc" } where field type is not "readable" for TypeScript.
And because of this swagger-typescript-api has key value group to translate swagger schema fields type/format to TypeScript constructions.
See more about swagger schema type/format data here
For example, current version of default configuration translates this schema

{
  "type": "string",
  "format": "date-time"
}

translates to

string

If you need to see Date instead of string you are able to change it with using primitiveTypeConstructs

generateApiForTest({
  // ...
  primitiveTypeConstructs: (construct) => ({
    string: {
        'date-time': 'Date'
    }
  })
})

Structure of primitiveTypes property

const primitiveTypes = {
    integer: () => Ts.Keyword.Number,
    number: () => Ts.Keyword.Number,
    boolean: () => Ts.Keyword.Boolean,
    object: () => Ts.Keyword.Object,
    file: () => Ts.Keyword.File,
    string: {
      $default: () => Ts.Keyword.String,

      /** formats */
      binary: () => Ts.Keyword.File,
      file: () => Ts.Keyword.File,
      "date-time": () => Ts.Keyword.String,
      time: () => Ts.Keyword.String,
      date: () => Ts.Keyword.String,
      duration: () => Ts.Keyword.String,
      email: () => Ts.Keyword.String,
      "idn-email": () => Ts.Keyword.String,
      "idn-hostname": () => Ts.Keyword.String,
      ipv4: () => Ts.Keyword.String,
      ipv6: () => Ts.Keyword.String,
      uuid: () => Ts.Keyword.String,
      uri: () => Ts.Keyword.String,
      "uri-reference": () => Ts.Keyword.String,
      "uri-template": () => Ts.Keyword.String,
      "json-pointer": () => Ts.Keyword.String,
      "relative-json-pointer": () => Ts.Keyword.String,
      regex: () => Ts.Keyword.String,
    },
    array: ({ items, ...schemaPart }, parser) => {
      const content = parser.getInlineParseContent(items);
      return parser.checkAndAddNull(schemaPart, Ts.ArrayType(content));
    },
  }

Other

feat: --another-array-type cli option (#414)
fix: path params with dot style (truck.id) (#413)

10.0.3 Release

21 Oct 21:34
e8ffa3f
Compare
Choose a tag to compare

fix: CRLF -> LF (#423)
docs: add docs for addReadonly nodeJS api flag (#425)
chore: remove useless trailing whitespaces which make test edit harder (thanks @qboot, #422)
internal: add test snapshots (git diff + nodejs assertions)
chore: add logging (project version, node version, npm version)

10.0.2 Release

15 Oct 23:40
e8ffa3f
Compare
Choose a tag to compare

fix: problem with default http request headers in axios client
fix: host.fileExists is not a function
fix: other problems linked with new typescript version (4.8.*) (thanks @elkeis, @Jnig)
fix: problem with required nested properties based on root required properties list
fix: fetch http client headers content type priority
fix: fs.rmSync (thanks @smorimoto)
fix: locally overridden security schemes (security flag) (#418, thanks @EdwardSalter)
docs: add documentation for unwrapResponseData nodejs option (thanks @simowe)
BREAKING_CHANGE: rename .eta file extensions to .ejs. Backward capability should be existed.
fix: problem with --sort-types option

9.2.0 Release

14 Jul 10:57
7df956c
Compare
Choose a tag to compare

Features:

  • full response typing for status code, data and headers. (#272, thanks @rustyconover)
  • --unwrap-response-data to unwrap the data item from the response (#268, thanks @laktak)

Fixes:

9.1.2 Release

08 Jun 07:57
189dec0
Compare
Choose a tag to compare

Fixes:

  • Bug with --single-http-client and private http property

9.1.1 Release

04 Jun 07:52
7db7785
Compare
Choose a tag to compare

Fixes:

  • Critical bug linked with templateRequire in ETA templates
  • Critical bugs linked with --type-prefix, --type-suffix
  • Bug with nested objects in FormData (issue #262, thanks @avlnche64)

Internal:

  • Improve manual testing scripts

9.0.2 Release

03 May 17:06
0cbcbba
Compare
Choose a tag to compare

Fixes:

  • 9.0.1 won't build with tsc when imported (thanks @mastermatt)

9.0.1 Release

01 May 10:43
0272739
Compare
Choose a tag to compare

Fixes:

  • Can't compile 9.0.0 version (thanks @Nihisil )