swagger-api / swagger-api/swagger-codegen

[Python-flask] Issue with code generation for swagger models with array of referenced items

Open
#10,860 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Hello,

we want to use swagger-codegen to generate python3 models from swagger 2.0 specification
received from Go server code.
The problem is that models which includes array of other items inlined by reference lead to unusable python code genereted for models(result models https://gist.github.com/IgorSysoev73/b7a9cd9e91844d30e9d0584843c28f54).

Is there any way to make it works or it is unsupported in python-flask code generator?

Swagger-codegen version

3.0.24

Swagger declaration file content
{
  "produces": [
    "application/json"
  ],
  "schemes": [
    "http",
    "https"
  ],
  "swagger": "2.0",
  "info": {
    "description": "Description",
    "title": "Some API",
    "version": "v1.2"
  },
  "basePath": "/api/v2",
  "paths": {
  },
  "definitions": {
    "ArrayOfItems": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/ArrayItem"
      },
      "x-go-package": "nc/pkg/models"
    },
    "ArrayItem": {
      "type": "object",
      "properties": {
        "id": {
          "description": "id",
          "type": "integer",
          "format": "int32",
          "x-go-name": "ID"
        }
      },
      "x-go-package": "nc/pkg/models"
    }
  }
}
Command line used for generation

swagger-codegen generate -i swagger.spec.json -l python-flask -o out_code_dir

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 by running the provided swagger-codegen 3.0.24 command with the inline Swagger 2.0 definitions and compare the generated Python models with the linked example. Trace the python-flask generator templates or model-generation entry point responsible for arrays whose items use $ref; done means the generated models are usable Python and correctly represent ArrayOfItems containing ArrayItem objects.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.