RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.71k stars 1.24k forks source link

"additionalProperties" property is adding in my dependancy models/schema and other than non "object" type models. #2552

Open kuppamabhishek opened 4 years ago

kuppamabhishek commented 4 years ago

Hi Team,

I am generating code for resolved json for my api project using following command, "nswag run .\nswag\server.controller.nswag /runtime:NetCore21".

I have placed "additinalProperties" as 'false' for all the internal models where as it's type is, "object". This has resolved the my issue without adding additionalPropertie fields to my code. But, still it's adding for some of the models. For example,

1. 
PartCreate:
      description: Part Creation Model
      additionalProperties: false
      properties:
        partId:
          description: A unique id.
          type: string
          example: 00000000
        brandCode:
          description: 'The part''s brand code.
          type: string
          example: XXXX
        partCode:
          description: 'The part''s code.
          type: string
          example: 8765432              
        quantity:
          format: double
          description: >

            The quantity of the Part.

            > Each Part has a default `unitOfMeasure`, which indicates the
            'real' value of the numerical `quantity` field.
          type: number
          example: 1
2. For some of the models i am adding as dependencies. For this models also it's adding it in .net code.

Do, we have any option where we can able to place "additinalProperties" as false globally? Or do you guys has any solution from your side?

Regards, Abhishek

RicoSuter commented 4 years ago

The spec defines the default of additinalProperties as "true" - you cannot change that globally. The only option now is to preprocess the schema before generating the clients...