react-query-swagger icon indicating copy to clipboard operation
react-query-swagger copied to clipboard

My DTO has [key: string]: any;

Open eladcandroid opened this issue 1 year ago • 6 comments

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;
}

eladcandroid avatar Sep 27 '23 07:09 eladcandroid

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

Rudomitori avatar Oct 04 '23 04:10 Rudomitori

@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"
        ]
      }
    },```

synasapmob avatar Feb 22 '24 09:02 synasapmob

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

Rudomitori avatar Feb 22 '24 09:02 Rudomitori

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

swag-overflow avatar Sep 25 '24 13:09 swag-overflow

@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...

synasapmob avatar Sep 25 '24 14:09 synasapmob

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

swag-overflow avatar Sep 26 '24 08:09 swag-overflow