Shaddix / react-query-swagger

Generates react-query hooks based on Swagger API definitions
MIT License
131 stars 6 forks source link

My DTO has [key: string]: any; #32

Open eladcandroid opened 1 year ago

eladcandroid commented 1 year ago

How to prevent adding [key: string]: any; ? I want to include only my schema properties but the generator adds also the general index signature.

export interface IAlertDto {
    id: string;
    name: string;
    createdAt: Date;

    [key: string]: any;
}
Rudomitori commented 1 year ago

@eladcandroid, Can you provide the "Swagger" specification and the command line arguments that you use?

synasapmob commented 8 months ago

@eladcandroid, Can you provide the "Swagger" specification and the command line arguments that you use?

my issue as the same, can you help me


 "/something": {
      "get": {
        "operationId": "something",
        "parameters": [

        ],
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/BaseResult"
                    },
                    {
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/somethingDto"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "tags": [
          "something"
        ]
      }
    },```
Rudomitori commented 8 months ago

@synasapmob What is the definition of BaseResult? What CLI arguments do you use?

swag-overflow commented 1 month ago

any updates on that? Same here with:

react-query-swagger /tanstack /input:http://localhost:8000/v3/api-docs /output:src/entities/api.ts /template:Fetch /minimal /use-recommended-configuration

synasapmob commented 1 month ago

@synasapmob What is the definition of BaseResult? What CLI arguments do you use?

I have other ideas to instead react-query-swagger m,y comment necessary to close...

swag-overflow commented 1 month ago

I've found a solution. The issue on our side was that our swagger output has no additionalProperties: false flag. So I've customized our swagger generator to add those flags on every schema. React-query-swagger now doesn't add those [key: string]: any; option to the types and interfaces anymore.

We use Springdoc to generate our swagger. You can add this customizer to OpenApiConfig to ensure the additionalProperties flag to be set in your swagger output:

@Bean
    public OpenApiCustomizer getDefaultCustomizer() {
        return openApi -> openApi.getComponents().getSchemas().values().forEach(s -> s.setAdditionalProperties(false));
    }

And on Group Generators:

@Bean
    public GroupedOpenApi common() {
        return GroupedOpenApi.builder()
                .group("common")
                .pathsToMatch("/api/common/**")
                .addOpenApiCustomizer(getDefaultCustomizer())
                .build();
    }

Thanks to https://github.com/RicoSuter/NSwag/issues/4199#issuecomment-1318678490 And https://stackoverflow.com/a/64490457