fern icon indicating copy to clipboard operation
fern copied to clipboard

[Bug] Duplicate examples if summary match in request/response

Open philsturgeon opened this issue 1 year ago • 1 comments

Describe the bug

If example names match in the request and response (a convention leveraged by Microcks to help match response examples to request examples) then fern generate produces errors as it seems to want all examples to have unique names.

[api]: Found 2 errors and 0 warnings. Run fern check --warnings to print out the warnings.
[api]: payments.yml -> service -> endpoints -> create-booking-payment
       Duplicate example name: Card Payment
[api]: payments.yml -> service -> endpoints -> create-booking-payment
       Duplicate example name: Bank Account Payment

Example OpenAPI.

    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              ...
            examples:
              Card:
                summary: Card Payment
                value:
                  ...
              Bank:
                summary: Bank Account Payment
                value:
                  ...
      responses:
        '200':
          description: Payment successful
          content:
            application/json:
              schema:
                ...
              examples:
                Card:
                  summary: Card Payment
                  value:
                    ...
                Bank:
                  summary: Bank Account Payment
                  value:
                    ...

To reproduce

Steps to reproduce the behavior:

  1. Using the Bump.sh Train Travel API openapi.yaml https://github.com/bump-sh-examples/train-travel-api
  2. And using generators:
generators:
    - name: fernapi/fern-typescript-node-sdk
      version: 0.9.5
      output:
        location: local-file-system
        path: ../sdks/typescript
    - name: fernapi/fern-typescript-express
      version: 0.17.3
      output:
        location: local-file-system
        path: ../server/express
  1. Run the command fern generate
  2. See error

Expected behavior

I expect the train travel api to generate openapi without errors.

CLI Version

0.39.4

philsturgeon avatar Aug 15 '24 10:08 philsturgeon

Update, my mistake, it's not the names (the variable name in the YAML) but the summary string.

If I change the examples summary string in the response then all summaries are unique.

examples:
  Card:
    summary: Card Payment Response

  Bank:
    summary: Bank Account Payment Response

This avoids the Microcks convention as the names need to be the same but summary does not matter.

Still, I'd call this one a bit unexpected.

philsturgeon avatar Aug 15 '24 10:08 philsturgeon

I ran Travel Train spec 1.0.0 on CLI version 0.46.2 and got no error message. Resolving as the user no longer runs into an error for this.

dannysheridan avatar Dec 14 '24 20:12 dannysheridan