fern-api / fern

Input OpenAPI. Output SDKs and Docs.
https://buildwithfern.com
Apache License 2.0
2.58k stars 134 forks source link

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

Open philsturgeon opened 4 weeks ago

philsturgeon commented 4 weeks ago

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
  3. Run the command fern generate
  4. See error

Expected behavior

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

CLI Version

0.39.4

philsturgeon commented 4 weeks ago

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.