Haskell-OpenAPI-Code-Generator / Haskell-OpenAPI-Client-Code-Generator

Generate Haskell client code from an OpenAPI 3 specification
46 stars 19 forks source link

Do not generate optional fields #73

Closed s9gf4ult closed 2 years ago

s9gf4ult commented 2 years ago

The idea behind this PR is that instead of generating null values for Nothing values on optional fields of JSON-objects we do not add the these fields at all.

NorfairKing commented 2 years ago

@s9gf4ult I have no opinion on this per-se, but are we sure that null and "missing key" are semantically equal?

s9gf4ult commented 2 years ago

@NorfairKing They are not. That is the point. If you have schema like this

    Delay:
      description: "response delay"
      type: object
      additionalProperties: false
      properties:
        timeUnit:
          type: string
        value:
          type: integer

the object {value: 10} will follow the schema, but {timeUnit: null, value: 10} will not (because null is not a string, appearantly). But actually it depends on schema validator. The validator form mock-server does not allow the former.

joel-bach commented 2 years ago

Thank you for the PR @s9gf4ult! I like this change as this is definitely closer to the OpenAPI spec than before. Would you mind update the golden tests and fix the broken level 2 tests in .circleci/testing/level2/petstore-running-example/test/Spec.hs? If you need help to do this, please shout.

s9gf4ult commented 2 years ago

Sure, will do in few days

joel-bach commented 2 years ago

Hey @s9gf4ult, are you okay to close this PR in favor of https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/pull/75? It includes your changes but extends them for deserialization and nullable support with tests. Thank you for your input, it was valuable!

s9gf4ult commented 2 years ago

@joelfisch sure. Your request works just fine. Thanks.