Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6711
Closed
Open
Issue created Jun 18, 2020 by Administrator@rootContributor

[BUG] [Server: Python] Incorrect parameter example used for requestBody parameters

Created by: pavlot

Bug Report Checklist

  • [ x ] Have you provided a full/minimal spec to reproduce the issue?
  • [ x ] Have you validated the input using an OpenAPI validator (example)?
  • [ x ] Have you search for related issues/PRs?
  • [ x ] What's the actual output vs expected output?
Description

As mentioned incorrect example taken for requestBody parameters when generated code by python-flask generator

openapi-generator version

v4.3.1

OpenAPI declaration file content or url
---
openapi: 3.0.2
info:
  title: OpenApiGeneratorTest
  version: 1.0.0
paths:
  /example:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/ExampleComplexType'
            examples:
              Random request data:
                value:
                - id: 19
                  text: some text
                - id: 63
                  text: some text
      responses:
        "200":
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ExampleComplexType'
              examples:
                Random results:
                  value:
                  - id: 50
                    text: some text
                  - id: 3
                    text: some text
          description: Responce description text
components:
  schemas:
    ExampleComplexType:
      title: Root Type for ExampleComplexType
      description: ""
      type: object
      properties:
        id:
          format: int32
          type: integer
        text:
          type: string
      example:
        id: 0
        text: Some text

expected: python test must contain example like:

[{"id":19, "text":"some text"},{"id":63, "text":"some text"}]

Actual

{"id":0, "text":"some text"}
Command line used for generation

openapi-generator generate -g python-flask -i OpenApiGeneratorTest.yaml

Steps to reproduce
  1. Generate python-flask code using given commandline
  2. Check test_default_controller.py for example used in test_example_post test
  3. Rut tox - it will be failed with message
E   AssertionError: 400 != 200 : Response body is : {
E     "detail": "{'id': 0, 'text': 'Some text'} is not of type 'array'",
E     "status": 400,
E     "title": "Bad Request",
E     "type": "about:blank"
E   }
Related issues/PRs

Not found

Suggest a fix

Issue is in /openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java:postProcessOperationsWithModels:

.....
operation.bodyParam.example = example.get("example");
.....

This call overwrite example already exists in body param and assign example from operation object

Possible solution: add check whether bodyParam.example not empty:

                    if (operation.bodyParam.example == null &&
                    		example.get("contentType") != null 
                    		&& example.get("contentType").equals("application/json")
                    		) {
                        operation.bodyParam.example = example.get("example");
                    }
Assignee
Assign to
Time tracking