OpenAPITools / OpenAPITools/openapi-generator
[BUG][Python-Fastapi] Path parameters when schema type is number causes the url to not be callable as it generates the type as strict float which can't be called by curl/browser
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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?
Current Output:
async def order_order_id_get(
order_id: Union[StrictFloat, StrictInt] = Path(..., description="")) -> str:
Expected Output
async def order_order_id_get(
order_id: float = Path(..., description="")) -> str:
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
For Python Fastapi path parameter, when type is number it set it to StrictFloat which isn't good for making calls to the path parameter as when you send a url it gives you an error back as it can't convert the string value to a float. I think it would be more suitable for this value to be a float as it would allow type conversion from a curl or browser call to the server.
openapi-generator version
openapi-generator v7.10.0 and master
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Order API
version: 1.0.0
paths:
/order/{order_id}:
parameters:
- name: order_id
in: path
required: true
schema:
type: number
get:
responses:
'200':
description: Successfully retrieved
content:
application/json:
schema:
type: string
servers:
- url: http://localhost:3020
Generation Details
openapi-generator generate -g python-fastapi -i in.json
Steps to reproduce
- Run
openapi-generator generate -g python-fastapi -i in.json - Open src/openapi_server/apis/default_api.py
- See function with path param order_id
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/20316
Suggest a fix
Set the number value to generate as float and not strict float
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the documented openapi-generator command with the supplied OpenAPI declaration, then inspect src/openapi_server/apis/default_api.py and the generated order_id signature. Compare the current StrictFloat output with the expected float behavior and verify the generated endpoint can accept a URL value from curl or a browser.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100