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
  • #10765
Closed
Open
Issue created Nov 02, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [python-flask] x-openapi-router-controller and defaultController are ignored

Created by: stopmachine

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

There are two issues when generating server python-flask code:

  • When setting the defaultController additional property, it still generates default_controller.py instead of the given name.
  • When setting x-openapi-router-controller for a method in the OpenAPI yaml, the generated handler function is created inside default_controller.py, although x-openapi-router-controller does not point there, resulting in a runtime import error.
openapi-generator version

5.3.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Petstore API
  description: Petstore
  version: 0.1.0
servers:
  - url: https://pet.example.com/v0
    description: Base endpoint

paths:
  /feed:
    post:
      summary: Feed a pet
      description: Feed a pet
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                brand:
                  type: string
                  example: acme_pet_food
              required:
                - brand
      responses:
        '204':
          description: Fed
      x-openapi-router-controller: pet_food_handler
Steps to reproduce
java -jar openapi-generator-cli.jar generate --input-spec example_issue/exampleapi.yaml --generator-name python-flask --additional-properties controllerPackage=handlers,defaultController=misc_handlers,disallowAdditionalPropertiesIfNotPresent=false,featureCORS=true,packageName=pet_server --output example_issue/build/python_3

Controllers in the controller package (which we named handlers):

$ ll example_issue/build/python_3/pet_server/handlers/
total 6
drwxr-xr-x 1 user 197609   0 Nov  2 20:39 ./
drwxr-xr-x 1 user 197609   0 Nov  2 20:39 ../
-rw-r--r-- 1 user 197609   0 Nov  2 20:39 __init__.py
-rw-r--r-- 1 user 197609 466 Nov  2 20:39 default_controller.py
-rw-r--r-- 1 user 197609  25 Nov  2 20:39 security_controller_.py

The default controller is still named default_controller.py despite passing defaultController=misc_handlers.

More importantly, the x-openapi-router-controller for the method is the non-existent pet_food_handler:

$ tail -20 example_issue/build/python_3/pet_server/openapi/openapi.yaml | head -5
          description: Fed
      summary: Feed a pet
      x-openapi-router-controller: pet_food_handler
components:
  requestBodies:

Tests fail:

$ tox
... pytest output...
>       return _bootstrap._gcd_import(name[level:], package, level)
E       ModuleNotFoundError: No module named 'pet_food_handler'

/usr/lib/python3.8/importlib/__init__.py:127: ModuleNotFoundError
... output continues ...
Assignee
Assign to
Time tracking