mtennoe / swagger-typescript-codegen

A Swagger Codegenerator tailored for typescript.
Apache License 2.0
141 stars 52 forks source link

Fix an error when swagger type is object, but doesn't have the type attribute #119

Closed TimoSchoenberger closed 4 years ago

TimoSchoenberger commented 4 years ago

I fixed an error that caused me some headache, but I still don't think it's completely right now. If a swagger object has an array of strings as "required" attribute, it will result in a type that has "isRequired" set to true. That doesn't feel right.

Microsoft Reviewers: Open in CodeFlow
TimoSchoenberger commented 4 years ago

Sorry, I still need to fix the tests first

TimoSchoenberger commented 4 years ago

Okay... correct me if I'm wrong. It looks like the tests fail due to my fix. I think the snapshots where wrong. this is the test error:

  ● Should resolve protected api

    expect(value).toMatchSnapshot()

    Received value does not match stored snapshot "Should resolve protected api 1".

    - Snapshot
    + Received

    @@ -17,20 +17,20 @@
      export type ConfigureRequestHandler = (agent: SuperAgentRequest) => SuperAgentRequest;

      export type CallbackHandler = (err: any, res ? : request.Response) => void;

      export type Authentication = {
    -     'token_type' ? : "bearer";
    -     'expiration_date' ? : {};
    -     'access_token' ? : string;
    -     'refresh_token' ? : string;
    -     'project_tokens' ? : {};
    +     'token_type': "bearer";
    +     'expiration_date': {};
    +     'access_token': string;
    +     'refresh_token': string;
    +     'project_tokens': {};
      };
...

and this is the corresponding swagger file:

"definitions": {
        "Authentication": {
            "required": [
                "token_type",
                "expiration_date",
                "access_token",
                "refresh_token",
                "project_tokens"
            ],
            "properties": {
                "token_type": {
                    "type": "string",
                    "description": "The API token type",
                    "enum": [
                        "bearer"
                    ]
                },
...

In my opinion that's correct. how can I update the snapshot?

mtennoe commented 4 years ago

Hi! You are right, the snapshots definitely look wrong! Your fix looks good, so lets just get the snapshots updated, then we should be good to go 👍 I pushed a minor update to master that adds a simple updateSnapshots command to the repo. If you merge with latest master you can run npm run updateSnapshots

Thanks for fixing this!

TimoSchoenberger commented 4 years ago

All tests are green. We're good to go now. Thank you for maintaining this repo!

mtennoe commented 4 years ago

Completed and published as 3.2.0. Thanks for helping out!