oxidecomputer / oxidecomputer/progenitor

Cannot use different type for HTTP 404.

Open
#928 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
136
Avg merge
8h 36m
Merged PRs (30d)
14

Description

I want to use progenitor, but generated client uses same response type for HTTP 404 as it has for HTTP 200.

Here is the most simple reproducible spec:

openapi: "3.0.2"
info:
  title: Demo That Triggers It
  version: 0.1.0
  description: "Here you go"
  contact:
    name: Demo
servers:
  - url: http://localhost:12346/
paths:
  /items/{key}:
    get:
      summary: get_state_element
      operationId: get_state_element
      tags: [ "hi-there" ]
      parameters:
        - name: key
          in: path
          required: true
          schema:
            type: string
      responses:
        200:
          $ref: "#/components/responses/StateMapElementResponse2"
        404:
          "$ref": "#/components/responses/NotFound"
components:
  parameters:
    rollup_height:
      name: rollup_height
      in: query
      description: The height of the rollup to query. If not provided, the rollup head is used.
      required: false
      schema:
        type: integer
        minimum: 0
  responses:
    StateMapElementResponse2:
      description: Response containing the value of a `StateMap` element.
      content:
        application/json:
          schema:
            type: object
            properties:
              data:
                type: object
                properties:
                  key:
                    $ref: "#/components/schemas/AnyJsonValue"
                  value:
                    $ref: "#/components/schemas/AnyJsonValue"
                required:
                  - key
                  - value
              meta:
                $ref: "#/components/schemas/AnyJsonValue"
            required:
              - data
    NotFound:
      description: The requested resource was not found.
      content:
        application/json:
          schema:
            type: object
            properties:
              errors:
                type: array
                items:
                  $ref: "#/components/schemas/Error"
              meta:
                $ref: "#/components/schemas/AnyJsonValue"
            required:
              - errors
  schemas:
    AnyJsonValue:
      description: "Any JSON type, including null."
      nullable: true
      oneOf:
        - type: string
          title: "String"
        - type: number
          title: "Number"
        - type: boolean
          title: "Boolean"
        - type: array
          title: "Array"
          items:
            x-stainless-any: true
        - type: object
          title: "Object"
          additionalProperties: true
    Error:
      type: object
      properties:
        status:
          type: integer
          format: int32
          description: HTTP status code related to this error
        title:
          type: string
        details:
          $ref: "#/components/schemas/AnyJsonValue"
      required:
        - status
        - title
        - details

Here is part of the codegen.rs:

impl Client {
    pub async fn get_state_element<'a>(
        &'a self,
        key: &'a str,
    ) -> Result<
        ResponseValue<types::GetStateElementResponse>,
        Error<types::GetStateElementResponse>,
    > { todo!("omitted"); }
}    

I am struggling to find what causes the problem, that Error variant is the same as success.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with codegen.rs and generate a client from the minimal OpenAPI spec in the issue, focusing on how the 200 and 404 responses are represented. Done means the generated get_state_element method distinguishes the 404 response type from the 200 response type; no specific test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.