Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to introduce inheritance in spec to replace polymorphism in NumberVerificationRequestBody #48

Closed
patrice-conil opened this issue Jul 5, 2023 · 4 comments · Fixed by #52

Comments

@patrice-conil
Copy link

Problem description
As PhoneNumber and HashedPhoneNumber don't extends NumberVerificationRequestBody a client using strongly typed language must have to serialize its request by hand.

Expected behavior
I want to be able to inject my PhoneNumber or HashedPhoneNumber as NumberVerificationRequestBody

Alternative solution

    NumberVerificationRequestBody:
      allOf:
        - $ref: '#/components/schemas/PhoneNumber'
      description: Payload to verify the phone number
      example:
        phoneNumberType: RegularPhoneNumber
        phoneNumber: "+33601020304"
    PhoneNumber:
      type: object
      properties:
        phoneNumberType:
          type: string
      discriminator:
        propertyName: phoneNumberType
        mapping:
          RegularPhoneNumber: '#/components/schemas/RegularPhoneNumber'
          HashedPhoneNumber: '#/components/schemas/HashedPhoneNumber'

    RegularPhoneNumber:
      allOf:
        - $ref: '#/components/schemas/PhoneNumber'
        - type: object
          properties:
            phoneNumber:
              description: A phone number belonging to the user in **E.164 format (starting with country code)**. Optionally prefixed with '+'.
              type: string
              example: '+346661113334'
    HashedPhoneNumber:
      allOf:
        - $ref: '#/components/schemas/PhoneNumber'
        - type: object
          properties:
            hashedPhoneNumber:
              description: Hashed phone number. SHA-256 (in hexadecimal representation) of the mobile phone number in **E.164 format (starting with country code)**. Optionally prefixed with '+'.
              type: string
              example: 32f67ab4e4312618b09cd23ed8ce41b13e095fe52b73b2e8da8ef49830e50dba

Additional context
This evolution is conform to PR #22 in commonallities

@jlurien
Copy link
Collaborator

jlurien commented Aug 23, 2023

I understand the issue. If the aim is to send one or the other, an alternative may be to define them as optional properties, indicating that one and only one is expected:

  schemas:
    NumberVerificationRequestBody:
      type: object
      description: Payload to verify the phone number
      minProperties: 1
      maxProperties: 1
      properties:
        phoneNumber:
          description: A phone number belonging to the user in **E.164 format (starting with country code)**. Optionally prefixed with '+'.
          type: string
          example: '+346661113334'
        hashedPhoneNumber:
          description: Hashed phone number. SHA-256 (in hexadecimal representation) of the mobile phone number in **E.164 format (starting with country code)**. Optionally prefixed with '+'.
          type: string
          example: 32f67ab4e4312618b09cd23ed8ce41b13e095fe52b73b2e8da8ef49830e50dba

@patrice-conil
Copy link
Author

Hi @jlurien,
Nice solution and because simpler is better, I vote for 😄

@jlurien
Copy link
Collaborator

jlurien commented Aug 25, 2023

If OK, I can do a PR

@patrice-conil
Copy link
Author

Hi @jlurien it's ok for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants