Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

feat: support additionalProperties for top level entities #135

Closed will7200 closed 3 years ago

will7200 commented 3 years ago

My implementation of additional properties so they can be types.

Manweill commented 3 years ago

@will7200 Hey, can you let me see the different result of the generation before and after?

Manweill commented 3 years ago

@will7200 maybe you should show the changed after your PR.

will7200 commented 3 years ago

@Manweill Examples:

  1. If there properties defined on the model it will export an additional type with a union type.
    export type ResponseWithAdditionalParametersWithAdditionalProperties = ResponseWithAdditionalParameters & {
    };
  2. If there are no properties defined on the model:
    export interface ResponseWithOnlyAdditionalParameters {
    /**  */
    }

Now lies the problem of how to use the new type instead of the interface if the model has existing properties

Manweill commented 3 years ago

@Manweill Examples:

  1. If there properties defined on the model it will export an additional type with a union type.
export type ResponseWithAdditionalParametersWithAdditionalProperties = ResponseWithAdditionalParameters & {
  [additionalProperties: string]: object;
};
  1. If there are no properties defined on the model:
export interface ResponseWithOnlyAdditionalParameters {
  /**  */
  [additionalProperties: string]: number;
}

Now lies the problem of how to use the new type instead of the interface if the model has existing properties

It will not affect existing code?

will7200 commented 3 years ago

Yeah its an enhancement and is backwards compatible with your existing code base. If they don't define additional properties or it is set to false it will retain the current behavior.