Skip to content

Releases: acacode/swagger-typescript-api

12.0.0 Release

13 Nov 07:41
e3e0e6e
Compare
Choose a tag to compare

new hooks:

/** calls before parse\process route path */
onPreBuildRoutePath: (routePath: string) => string | void;
/** calls after parse\process route path */
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath | void;
/** calls before insert path param name into string path interpolation */
onInsertPathParam: (paramName: string, index: number, arr: BuildRouteParam[], resultRoute: string) => string | void;
/** calls before parse any kind of schema */
onPreParseSchema: (originalSchema: any, typeName: string, schemaType: string) => any;

BREAKING_CHANGE: add ability to custom prefix for autofix invalid enum keys, invalid type names with nodejs options (fixInvalidTypeNamePrefix: string, fixInvalidEnumKeyPrefix: string)
BREAKING_CHANGE: by default all component enum schemas (even numeric) extracting as enum TS constructions (#344)
feature: ability to extract all enums from nested types\interfaces to enum TS construction using --extract-enums option (#344)
feature: ability to modify route path params before insert them into string (request url, #446, with using hook onInsertPathParam)
feature: (nodejs) ability to add prefix\suffix for type names and enum keys

typePrefix?: string;
typeSuffix?: string;
enumKeyPrefix?: string;
enumKeySuffix?: string;

feature: ability to customize resolving process of the extracting type names (extractingOptions nodejs option)

extractingOptions = {
  // requestBodySuffix: ["Payload", "Body", "Input"],
  // or
  // requestBodyNameResolver: (typeName, reservedNames) => string;

  // requestParamsSuffix: ["Params"],
  // or
  // requestParamsNameResolver: (typeName, reservedNames) => string;

  // responseBodySuffix: ["Data", "Result", "Output"],
  // or
  // responseBodyNameResolver: (typeName, reservedNames) => string;

  // responseErrorSuffix: ["Error", "Fail", "Fails", "ErrorData", "HttpError", "BadResponse"],
  // or
  // responseErrorNameResolver: (typeName, reservedNames) => string;
}

docs: update docs for extraTemplates option
fix: problem with default name of single api file (Api.ts)
fix: problem based with tuple types (#445)
fix: problem with defaultResponseType declaration type

11.1.3 Release

05 Nov 18:28
a0174e9
Compare
Choose a tag to compare

fix: problems with text/* content types (axios, fetch http clients) (thanks @JochenDiekenbrock, #312, #443)
fix: problem with application/json* content type (thanks @JochenDiekenbrock, #440, #441)
fix: different query type parameters declarations (in route name {?accountStatus,createdT, #439)

11.1.2 Release

30 Oct 09:29
3417bf3
Compare
Choose a tag to compare

fix: problems with missing type imports in .d.ts files with using option --js
internal: add extra spec tests
fix: additionalProperties management problem in Swagger 2 (#343)
fix: hanging cli after execution finished (#436, thanks @Soarc)

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