[BUG][rust-axum] Range response codes (4XX, 5XX) generate code that does not compile

Aberta
#25,293 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

  • #25294 de @teovillanueva — fechado sem integrar

Avaliação

Dificuldade
3/5
Tempo estimado
Meio dia
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
rust
Domínio
tooling

Direção de pesquisa

Start with server-operation.mustache and the generated response enum for the provided OpenAPI declaration, then reproduce the failures by generating the rust-axum server and running cargo check in out. Done means ranged response variants preserve a concrete u16 status with optional body/headers as appropriate, and generated servers compile and build responses using the status() builder.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Description

When an operation declares a range response code (4XX, 5XX, ...), the rust-axum server generator emits code that does not compile. For range responses, server-operation.mustache renders

response.status::<u16>(body.code.parse().unwrap());  // 4XX

which assumes the response body has a code field (error[E0609]: no field 'code' on type 'models::Error'), fails when the response has no body (error[E0425]: cannot find value 'body' in this scope), and drops the builder returned by status() (error[E0382] once the other errors are worked around). The generated response enum also has no way for the implementation to choose the concrete status within the range.

openapi-generator version

master (7.27.0-SNAPSHOT, commit 30f13393)

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Range responses
  version: 1.0.0
paths:
  /pets/{petId}:
    get:
      operationId: getPet
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: integer
            format: int64
      responses:
        "200":
          description: The pet
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
        "4XX":
          description: Client error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "5XX":
          description: Server error
components:
  schemas:
    Pet:
      type: object
      properties:
        name:
          type: string
    Error:
      type: object
      properties:
        message:
          type: string
Generation Details
java -jar openapi-generator-cli.jar generate -g rust-axum -i spec.yaml -o out
Steps to reproduce
  1. Generate the server with the spec above.
  2. Run cargo check in out.
  3. Compilation fails with E0609 (no field 'code' on type 'models::Error') for the 4XX arm and E0425 (cannot find value 'body') for the 5XX arm.
Related issues/PRs

None found.

Suggest a fix

Have range responses carry the status code: generate them as struct variants with a status: u16 field (plus body and headers as usual), e.g. Status4XX_ClientError { status: u16, body: models::Error }. The server then sets response.status(status), so the implementation picks the concrete code within the range.

Linguagem predominante
Java
Estrelas
26.9k
Forks
7.8k
Merge médio
2d 23min
PRs com merge (30d)
177

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de OpenAPITools/openapi-generator

Todas as issues de OpenAPITools/openapi-generator

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.