swagger-api / swagger-api/swagger-codegen

[Python] Add support for POST-Redirect-GET with Deserialization

Open
#3,558 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Enhancement: Feature help wanted
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Hello, we've been testing the swagger-codegen from editor.swagger.io for Python Client and we noticed that a POST-Redirect-GET generates the Client Stub with response_type=None instead of the correct type.

I don't know if this is by design or if it's a bug

Swagger-codegen version

2.2.0

Swagger declaration file content or url

---
swagger: "2.0"
info:
  description: "Foo"
  version: "v1"
  title: "Bar"
  termsOfService: "http://terms"
host: "localhost:8080"
basePath: "/api"
tags:
- name: "foo"
  description: "bar"
schemes:
- "http"
- "https"
paths:
  /foo:
    post:
      tags:
      - "foo"
      summary: "Creates a new Foo Object"
      description: ""
      operationId: "createFoo"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - in: "body"
        name: "Foo"
        description: "Foo Data for creation"
        required: true
        schema:
          $ref: "#/definitions/FooBarData"
      responses:
        303:
          description: "Redirects to created Foo URL"
        404:
          description: "Invalid data"
  /foo/{id}:
    get:
      tags:
      - "foo"
      summary: "Gets a Foo entry by Id"
      description: ""
      operationId: "getFooById"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "id"
        in: "path"
        description: "id"
        required: true
        type: "string"
        format: "uuid"
      responses:
        200:
          description: "The Foo"
          schema:
            $ref: "#/definitions/FooResult"
        400:
          description: "Invalid UUID format"
        404:
          description: "Foo not found"
definitions:
  FooBarData:
    type: "object"
    properties:
      name:
        type: "string"
        minLength: 1
        maxLength: 256
      description:
        type: "string"
  FooResult:
    type: "object"
    properties:
      id:
        type: "string"
        format: "uuid"
      name:
        type: "string"
      description:
        type: "string"
Command line used for generation

swagger-codegen generate -i swagger.yaml -l python -o /tmp/test

Steps to reproduce

Just call FooApi.create_foo() with FooData() and you'll notice that on the self.api_client.call_api within the create_foo_with_http_info method the response_type=None

Related issues
Suggest a Fix

If it's redirected to another known Endpoint, it should Infer the returned Types/Deserialized Objects

Contributor guide

Open the contributing guide

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 the generated FooApi.create_foo_with_http_info method and its self.api_client.call_api invocation, using the supplied Swagger declaration and generation command as the reproduction. Trace how the 303 response is represented and determine how the redirected endpoint's response type should be selected; done means the generated client passes the correct type and deserializes the redirected FooResult.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.