fern icon indicating copy to clipboard operation
fern copied to clipboard

[Bug] internal audience on property not respected inside external audience endpoint

Open daniilrrr opened this issue 1 year ago • 2 comments

Describe the bug

I want to have an external audience for an endpoint, but on the endpoint request one of the fields should be internal. When I then generate the docs for the external audience, that field still gets included in the OpenAPI spec when i dont want it to.

To reproduce

Steps to reproduce the behavior:

  1. Create a Fern def that looks something like the following, with an external endpoint containing an internal property:
service:
  auth: true
  base-path: /transact
  endpoints:
    sendTransaction:
      audiences:
        - internal-docs
        - external
        - external-docs
      docs: Send transaction to blockchain
      method: POST
      path: /sendTransaction
      request: SendTransactionRequest
...

types:
  ErrorBody:
    properties:
      message: string

  SendTransactionRequest:
    properties:
      requestId:
        docs: (Optional) ID of the request. Needs to be a valid UUID. If provided, it will be saved and returned as the transactionId of the response. If not provided, we will generate one for you and return it as the transactionId.
        type: optional<uuid>
      projectId:
        docs: ID of the project you want this request to be sent from
        type: uuid
      contractAddress:
        docs: The contract address to send request to
        type: string
      chainId:
        docs: The chain ID for the network (e.g. 1 for Ethereum Mainnet, 137 for Polygon Mainnet, 80001 for Polygon Mumbai). For a complete list of chain IDs, see [ChainList](https://chainlist.org/?search=&testnets=true).
        type: long
      functionSignature:
        docs: The human readable signature to call on the contract
        type: string
      args:
        docs: (Optional) The function arguments for the transaction if any. The keys are the argument names or index from the provided function signature and the values are the argument values.
        type: optional<map<string, unknown>>
      organizationId:
        type: string
        audiences:
          - internal-docs
  1. Run the command fern register
  2. Run the command fern generate --group external-docs
  3. The fields marked internal-docs are still included in the produced OpenAPI spec.
  4. NOTE: might need to have 2 services. See comment below

If relevant, provide a minimal API definition (OpenAPI or Fern Definition) or Docs configuration (docs.yml) that can be used to reproduce the error.

Expected behavior

The internal-docs fields organizationId are not included in the produced openapi.yml file.

Screenshots

If applicable, add screenshots to help explain your problem.

Version

Fern Version: 0.14.3

Additional context

Add any other context about the problem here.

daniilrrr avatar Dec 15 '23 22:12 daniilrrr

Investigated a little bit with a colleague and there might be some non-determinism at play.

  1. Scenario # 1 - 1 external endpoint, 1 internal property He had the following:
service:
  auth: true
  base-path: /transact
  endpoints:
    sendTransaction:
      audiences:
        - internal-docs
        - external
        - external-docs
      docs: Send transaction to blockchain
      method: POST
      path: /sendTransaction
      request: SendTransactionRequest
...

types:
  ErrorBody:
    properties:
      message: string

  SendTransactionRequest:
    properties:
      requestId:
        docs: (Optional) ID of the request. Needs to be a valid UUID. If provided, it will be saved and returned as the transactionId of the response. If not provided, we will generate one for you and return it as the transactionId.
        type: optional<uuid>
      projectId:
        docs: ID of the project you want this request to be sent from
        type: uuid
      contractAddress:
        docs: The contract address to send request to
        type: string
      chainId:
        docs: The chain ID for the network (e.g. 1 for Ethereum Mainnet, 137 for Polygon Mainnet, 80001 for Polygon Mumbai). For a complete list of chain IDs, see [ChainList](https://chainlist.org/?search=&testnets=true).
        type: long
      functionSignature:
        docs: The human readable signature to call on the contract
        type: string
      args:
        docs: (Optional) The function arguments for the transaction if any. The keys are the argument names or index from the provided function signature and the values are the argument values.
        type: optional<map<string, unknown>>
      isInternalOnly:
        type: boolean
        audiences:
          - internal-docs

And it worked initially for him. OrganizationId was not in the external OpenAPI def, only the internal one.

However, turns out what we really have is

  1. Scenario # 2 (simplified) - 1 external endpoint, 1 internal endpoint, 1 internal property on each that shares the same name
service:
  auth: true
  base-path: /transact
  endpoints:
    sendTransaction1:
      audiences:
        - internal-docs
        - external
        - external-docs
    sendTransaction2:
      audiences:
        - internal
...

types:
  ErrorBody:
    properties:
      message: string

  SendTransactionRequest1:
    properties:
      otherParam: string
      organizationId:
        type: string
        audiences:
          - internal-docs

  SendTransactionRequest2:
    properties:
      otherParam: string
      organizationId:
        type: string
        audiences:
          - internal-docs

and in this scenario it didn't work, and the internal property organizationId was included in the external docs.

What was really weird is that he then reverted his Fern def back to Scenario 1 exactly, and it now did not work! So maybe something is up with the shared property name organizationId between the external and internal endpoint?

daniilrrr avatar Dec 15 '23 23:12 daniilrrr

@daniilrrr I am just merging https://github.com/fern-api/fern/pull/2526; I think this should start to address your issues? The only thing worth calling out is that you will need to mark both external and internal properties for filtering to work

  # Only organizationId is included when you filter to `internal-docs` audience
  SendTransactionRequest2:
    properties:
      otherParam: string
      organizationId:
        type: string
        audiences:
          - internal-docs

dsinghvi avatar Dec 21 '23 11:12 dsinghvi