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

[Bug] Response status-code is not reflected in generated openapi spec #4777

Closed
marcklingen opened this issue Sep 30, 2024 · 7 comments · Fixed by #5722
Closed

[Bug] Response status-code is not reflected in generated openapi spec #4777

marcklingen opened this issue Sep 30, 2024 · 7 comments · Fixed by #5722
Assignees
Labels
language/openapi Exporting OpenAPI from Fern Defintion

Comments

@marcklingen
Copy link

Describe the Bug

When defining an api in fern with a custom response status code (docs), this status code is not reflected in the generated openapi spec.

Information to Reproduce

CLI Version

0.43.7

Generator Version

0.0.31

Custom Config

Any custom configuration requires to r
eproduce the bug (found in generators.yml).

- name: fernapi/fern-openapi
        version: 0.0.31
        output:
          location: local-file-system
          path: ../../../web/public/generated/api

Fern Definition

The minimal fern definition required to reproduce the bug.

endpoints:
    batch:
      docs: |
        Batched ingestion for Langfuse Tracing. If you want to use tracing via the API, such as to build your own Langfuse client implementation, this is the only API route you need to implement.

        Notes:
        - Batch sizes are limited to 3.5 MB in total. You need to adjust the number of events per batch accordingly.
        - The API does not return a 4xx status code for input errors. Instead, it responds with a 207 status code, which includes a list of the encountered errors.
      method: POST
      path: /ingestion
      request:
        name: IngestionRequest
        body:
          properties:
            batch:
              type: list<IngestionEvent>
              docs: "Batch of tracing events to be ingested. Discriminated by attribute `type`."
            metadata:
              type: optional<unknown>
              docs: Optional. Metadata field used by the Langfuse SDKs for debugging.
      response:
        type: IngestionResponse
        status-code: 207

Actual OpenAPI

The buggy OpenAPI document that is produced:

/api/public/ingestion:
    post:
      description: >-
        Batched ingestion for Langfuse Tracing. If you want to use tracing via
        the API, such as to build your own Langfuse client implementation, this
        is the only API route you need to implement.


        Notes:


        - Batch sizes are limited to 3.5 MB in total. You need to adjust the
        number of events per batch accordingly.

        - The API does not return a 4xx status code for input errors. Instead,
        it responds with a 207 status code, which includes a list of the
        encountered errors.
      operationId: ingestion_batch
      tags:
        - Ingestion
      parameters: []
      responses:
        '200':     <--- This part is buggy
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestionResponse'
        '400':
          description: ''
          content:
            application/json:
              schema: {}
        '401':
          description: ''
          content:
            application/json:
              schema: {}
        '403':
          description: ''
          content:
            application/json:
              schema: {}
        '404':
          description: ''
          content:
            application/json:
              schema: {}
        '405':
          description: ''
          content:
            application/json:
              schema: {}
      security:
        - BasicAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                batch:
                  type: array
                  items:
                    $ref: '#/components/schemas/IngestionEvent'
                  description: >-
                    Batch of tracing events to be ingested. Discriminated by
                    attribute `type`.
                metadata:
                  nullable: true
                  description: >-
                    Optional. Metadata field used by the Langfuse SDKs for
                    debugging.
              required:
                - batch

Expected OpenAPI

The buggy OpenAPI document that is produced:

/api/public/ingestion:
    post:
      description: >-
        Batched ingestion for Langfuse Tracing. If you want to use tracing via
        the API, such as to build your own Langfuse client implementation, this
        is the only API route you need to implement.


        Notes:


        - Batch sizes are limited to 3.5 MB in total. You need to adjust the
        number of events per batch accordingly.

        - The API does not return a 4xx status code for input errors. Instead,
        it responds with a 207 status code, which includes a list of the
        encountered errors.
      operationId: ingestion_batch
      tags:
        - Ingestion
      parameters: []
      responses:
        '207':     <--- This is the fix
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestionResponse'
        '400':
          description: ''
          content:
            application/json:
              schema: {}
        '401':
          description: ''
          content:
            application/json:
              schema: {}
        '403':
          description: ''
          content:
            application/json:
              schema: {}
        '404':
          description: ''
          content:
            application/json:
              schema: {}
        '405':
          description: ''
          content:
            application/json:
              schema: {}
      security:
        - BasicAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                batch:
                  type: array
                  items:
                    $ref: '#/components/schemas/IngestionEvent'
                  description: >-
                    Batch of tracing events to be ingested. Discriminated by
                    attribute `type`.
                metadata:
                  nullable: true
                  description: >-
                    Optional. Metadata field used by the Langfuse SDKs for
                    debugging.
              required:
                - batch

Additional Context

Repo is public:

Let me know if any additional context is helpful!

@marcklingen
Copy link
Author

@dannysheridan is there some sort of workaround for this?

@marcklingen
Copy link
Author

@dannysheridan, I just remembered this issue. Is there any way to resolve it? I completely understand if not; I just want to ensure I'm not overlooking anything.

@gustavkauman
Copy link
Contributor

We seem to be hitting the same issue.

The intermediate representation looks fine (at least with my basic understanding of it):

[...]
          "response": {
            "status-code": 201,
            "body": {
              "type": "json",
              "value": {
                "type": "response",
                "responseBodyType": {
                  "_type": "named",
                  "name": {
                    "originalName": "ExternalPOSSale",
[...]

but the generated openapi json just says 200 instead of 201:

[...]
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/externalposExternalPOSSale"
                },
                "examples": {
                  // example omitted
                }
              }
            }
          }
        },
[...]

@dannysheridan
Copy link
Member

@marcklingen no, you're not overlooking anything. This is a change that needs to be made to our OpenAPI spec converter: https://github.com/fern-api/fern/blob/main/generators/openapi/src/convertToOpenApi.ts

@gustavkauman what's the use case for needing an OpenAPI spec for your team?

@dannysheridan dannysheridan added the language/openapi Exporting OpenAPI from Fern Defintion label Jan 21, 2025
@gustavkauman
Copy link
Contributor

gustavkauman commented Jan 23, 2025

@dannysheridan We have a consumer of the API that's using OpenAPI spec to generate code stubs from.

I did a patch for this issue, would you be open to accepting?

@dannysheridan
Copy link
Member

@gustavkauman up to open up a PR on the /fern-api/fern repo? Would love to show you as a contributor!

@gustavkauman
Copy link
Contributor

@dannysheridan sure thing! Opened the PR #5722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/openapi Exporting OpenAPI from Fern Defintion
Development

Successfully merging a pull request may close this issue.

4 participants