You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generated code lacks import of typing.cast for required const properties #1150
Describe the bug
When an input schema has a required const property, the generated code does makes calls to typing.cast, but does not import it, leading to failures when trying to run ruff over the generated code.
OpenAPI Spec File
openapi: 3.1.0
info:
title: Pets Example
version: 1.0.0
paths:
/pets:
post:
requestBody:
description: Create a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"200":
description: Return a 200 status to indicate that the pet was created successfully
components:
schemas:
Pet:
required:
- type
properties:
type:
const: cat
Desktop (please complete the following information):
OS: macOS 14.6.1
Python Version: 3.12.6
openapi-python-client version: latest main (also present in latest release, 0.21.6)
Additional context
Removing type from the required field list in the example above makes the problem disappear - in this case, cast is still used, but is properly imported.
Activity
fix: import cast for required const properties, since it's used in th…
fix: import cast for required const properties, since it's used in th…
fix: import cast for required const properties, since it's used in th…
fix: import cast for required const properties, since it's used in th…