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

convertV2: different example for ENUM #817

Open
thim81 opened this issue Jul 25, 2024 · 5 comments
Open

convertV2: different example for ENUM #817

thim81 opened this issue Jul 25, 2024 · 5 comments

Comments

@thim81
Copy link
Contributor

thim81 commented Jul 25, 2024

I have this request body & query param Components with an ENUM, which chooses a different value everytime, while I was expecting that the example would be taken always.

This only happens when using the convertV2, with the convert it always returned type: "<string>"

Request body component:

    Website:
      type: object
      required:
        - url
      properties:
        id:
          type: string
          example: '12345'
          nullable: true
        url:
          type: string
          example: 'http://example.com'
          minLength: 1
        type:
          type: string
          enum:
            - primary
            - secondary
            - work
            - personal
            - other
          example: primary

Expected depending on the parametersResolution: type: primary or type: "<string>" but every time got a different ENUM value like type: secondary, type: work

Query param component:

    ContactsSort:
      type: object
      x-graphql-type-name: ContactsSort
      example:
        by: created_at
        direction: desc
      properties:
        by:
          type: string
          description: The field on which to sort the Contacts
          enum:
            - created_at
            - updated_at
            - name
            - first_name
            - last_name
            - email
          example: created_at
        direction:
          type: string
          description: The direction in which to sort the Contacts
          enum:
            - asc
            - desc
          default: asc
      required:
        - by
      additionalProperties: false

depending on the parametersResolution: by: created_at or by: "<string>" but every time got a different ENUM value like by: first_name, by: updated_at

@thim81
Copy link
Contributor Author

thim81 commented Jul 26, 2024

hi @VShingala

I have added tests to show that "Schema" resolution is not respected for ENUM values. It takes any random ENUM value.

Or is this the expected behaviour?

@VShingala
Copy link
Member

@thim81 Seems like unexpected behavior to me if it's working correctly in v1 but not in v2. We should respect parametersResolution correctly even for enum.

Here's a fix we did for somewhat related issue in v1. Might help. #682

@thim81
Copy link
Contributor Author

thim81 commented Jul 26, 2024

So the default behaviour would be like the tests:

  • No "parametersResolution" => becomes the default "Schema" and the value will be <string>
  • "Schema" "parametersResolution" => value will be <string>
  • "Example" "parametersResolution" => value will be the actual example as set in OpenAPI or faker generated when no example value is set

If this is correct, I'll try to find the cause.

@VShingala
Copy link
Member

@thim81 Yes, that's correct. A bit of correction in case of ENUM for 3rd point is that, when enum is present, we pick one of values form it while parametersResolution=Example. And, thanks for looking into this.

@thim81
Copy link
Contributor Author

thim81 commented Jul 30, 2024

@VShingala If you have some time, could you have a look at the PR 818 and share your feedback, so I can wrap-up the PR.

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

No branches or pull requests

2 participants