SwaggerProvider icon indicating copy to clipboard operation
SwaggerProvider copied to clipboard

Generator ignores nullability

Open xperiandri opened this issue 3 years ago • 5 comments

Description

    Service:
      type: object
      properties:
        Услуга:
          type: string
        Стоимость:
          type: number
          format: ₴
          nullable: false
        Обязательная:
          type: boolean
          nullable: false

Expected behavior

Properties of value type marked as nullable: false declared as non-nullable and has a non-nullable parameter in a constructor

Actual behavior

nullable: false is ignored

Related information

1.0.0-Beta1

xperiandri avatar Jan 31 '21 13:01 xperiandri

@sergey-tihon, please, point me where to apply fix I will code that today

xperiandri avatar Jan 31 '21 13:01 xperiandri

Sorry, I do not understand what is the issue...

Here is the property generation code for OpenApiProvider and here for SwaggerProvider.

sergey-tihon avatar Jan 31 '21 15:01 sergey-tihon

image

nullable: false

xperiandri avatar Jan 31 '21 15:01 xperiandri

Here is the line where we determine if the property is optional. https://github.com/fsprojects/SwaggerProvider/blob/net5/src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs#L202

Is easiest way to debug is to put breakpoint on this line and check how Microsoft.OpenApi.Readers passed your schema.

sergey-tihon avatar Jan 31 '21 16:01 sergey-tihon

Could that be because the fields aren't marked as required in the schema, so the generated properties have to be optional to handle them not being present in the Json data?

Numpsy avatar Apr 13 '21 22:04 Numpsy