Skip to content

0.7.0

Choose a tag to compare

@github-actions github-actions released this 31 May 15:51
29a4368

Breaking Changes

Code Generation Changes

  • Shadowed imports no longer use aliases - Generated code that previously aliased conflicting imports (e.g., from datetime import date as date_aliased) now uses the direct type reference (e.g., from datetime import date). Function signatures also change accordingly (e.g., date_aliaseddate). Users who regenerate code may see different output, and downstream code referencing aliased names will need updating. (#589)
  • 204 no-content endpoints now include explicit status_code=204 - Previously, endpoints with only a 204 response in the OpenAPI spec generated without a status_code parameter (defaulting to HTTP 200 at runtime). Now the generated code includes status_code=204 in the route decorator. Users who regenerate code from specs containing 204 responses will see different output and may need to update snapshots or tests that compare generated code. (#601)
  • Removed automatic status_code=204 from generated route decorators - Previously, when an endpoint had a 204 response (with no 200 response), the generated code included status_code=204 in the @app.post(...) decorator. This parameter is no longer emitted, changing generated output for any spec using 204 No Content responses. (#595)
  • Header and cookie parameters now use FastAPI dependency injection - Parameters with in: header or in: cookie in OpenAPI specs are now generated with Header(...) and Cookie(...) wrappers instead of plain function parameters. Regenerating code from specs that include header or cookie parameters will produce different output. For example, a header parameter trace_id previously generated as trace_id: str will now generate as trace_id: str = Header(..., alias='trace_id'). This also adds new from fastapi import Header, Cookie imports to generated files. (#602)
  • Non-200 success status codes now included in route decorators - Operations whose only success response is a non-200 code (e.g., 204 No Content) now generate status_code=204 in the @app.get(...) decorator. Previously this was omitted. Regenerated code for such endpoints will differ. (#602)
  • Vendor extensions filtered from info block - Keys starting with x- in the OpenAPI info object are now stripped from the generated FastAPI() constructor arguments. Previously these were passed through, which could cause runtime errors in FastAPI. (#602)

Python or Dependency Support Changes

  • datamodel-code-generator minimum version raised from 0.56.1 to 0.59 - The required version of datamodel-code-generator[http] changed from >=0.56.1,<0.57 to >=0.59,<0.60, dropping support for versions 0.56.x through 0.58.x. Users pinned to older versions of datamodel-code-generator will need to upgrade. (#589)

Custom Template Update Required

  • New operation.status_code field available in templates - A new status_code attribute (Optional[int]) has been added to the Operation model passed to Jinja2 templates. Users with custom templates who want correct 204 handling should add the following block after response_model={{operation.response}}:
    {% if operation.status_code %}
    , status_code={{operation.status_code}}
    {% endif %}

Existing custom templates will continue to work without this addition but will not emit the status_code parameter for no-content endpoints. (#601)

  • Removed operation.status_code field from the Operation model - Custom Jinja2 templates referencing operation.status_code (e.g., {% if operation.status_code %}, status_code={{operation.status_code}}{% endif %}) must remove those references, as the field no longer exists on the Operation class. (#595)
  • Default templates now include status_code conditional - The built-in main.jinja2 and routers.jinja2 templates now emit status_code={{operation.status_code}} when set. Users with custom copies of these templates should add the following block after the response_model= line to get equivalent behavior:
    {% if operation.status_code %}
        , status_code={{operation.status_code}}
    {% endif %}
    Custom templates that do not add this block will still work but will not emit status codes for 204 endpoints. (#602)

What's Changed

Full Changelog: 0.6.0...0.7.0