Swagger-codegen: [Typescript-node] Online editor works as expected, swagger-codgen CLI does not

Created on 1 Mar 2019  Â·  1Comment  Â·  Source: swagger-api/swagger-codegen

Description

I'm seeing a discrepancy between using swagger-codegen in the online editor (http://editor.swagger.io/) to generate a client with typescript-node, which works as expected, and locally, which does not.

Specifically, when running locally using swagger-codgen all parameters are designated as required in the Typescript class definitions. PR #7849 looks it addressed this exact problem some time back, and it works as expected from the online editor, so I can't figure out what my issue running locally is. Using the latest homebrew swagger-codegen formula on macOS High Sierra

Apologies for creating an issue on what is presumably a simple oversight on my part, but I haven't been able to make progress.

Typescript output:

export class ApiUser {
    'email': string;
    'userId': string;
    // ...
}
Swagger-codegen version


3.0.5

Swagger declaration file content or url
{
  "swagger": "2.0",
  "host": "api.sample.com",
  "basePath": "/",
  "paths": {},
  "securityDefinitions": {},
  "definitions": {
    "ApiUser": {
        "type": "object",
        "required": [ "email" ],
        "properties": {
            "email": { "type": "string" },
            "userId": { "type": "string" }
        }
    }
  }
}
Command line used for generation
swagger-codegen generate -i <my_json_doc> -l typescript-node -o <my_output_file>

Language: typescript-node
Local installation: macOS High Sierra with homebrew

brew info swagger-codegen
swagger-codegen: stable 3.0.5 (bottled), HEAD
Generate clients, server stubs, and docs from an OpenAPI spec
https://swagger.io/swagger-codegen/
/usr/local/Cellar/swagger-codegen/2.3.1 (6 files, 13.7MB) *
  Poured from bottle on 2018-08-08 at 08:58:07
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/swagger-codegen.rb
==> Dependencies
Build: maven ✘
==> Requirements
Required: java = 1.8 ✔
==> Options
--HEAD
    Install HEAD version
Steps to reproduce
  1. Save sample json snippet as "sample-api-docs.json"
    2.
brew install swagger-codegen
swagger-codegen generate -i sample-api-docs.json -l typescript-node -o ./
Related issues/PRs

7849

Suggest a fix/enhancement

Most helpful comment

Solved, issue with homebrew formula (can even see the problem in my brew info swagger-codegen output)

Related to #9171. Default swagger-codegen brew formula falls back to version 2.3.1 for typescript-node, which does not include PR #7849

Manual workaround is to just use v2

brew install swagger-codegen@2
brew unlink swagger-codegen
brew link swagger-codegen@2  --force

>All comments

Solved, issue with homebrew formula (can even see the problem in my brew info swagger-codegen output)

Related to #9171. Default swagger-codegen brew formula falls back to version 2.3.1 for typescript-node, which does not include PR #7849

Manual workaround is to just use v2

brew install swagger-codegen@2
brew unlink swagger-codegen
brew link swagger-codegen@2  --force
Was this page helpful?
0 / 5 - 0 ratings