Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

[BUG][python] Reference Error when using schema with optional properties #415

Closed
5 of 6 tasks
Marcelo00 opened this issue Apr 8, 2024 · 2 comments · Fixed by #416
Closed
5 of 6 tasks

[BUG][python] Reference Error when using schema with optional properties #415

Marcelo00 opened this issue Apr 8, 2024 · 2 comments · Fixed by #416
Labels
bug Something isn't working

Comments

@Marcelo00
Copy link

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
Description

When transforming the schema that have a additional properties, the created python file will have unresolved references in the TypedDict for the optional properties.

Given the yaml file below, the created multi_properties_schema.py file will have following definition for the optional properties:

MultiPropertiesSchemaOptionalDictInput = typing.TypedDict(
    'MultiPropertiesSchemaOptionalDictInput',
    {
        "data": typing.Union[
            DataTupleInput,
            DataTuple
        ],
        "message": str,
    },
    total=False
)

However, the DataTupleInput and DataTuple can not be referenced which lead to an error NameError: name 'DataTupleInput' is not defined during runtime.

openapi-json-schema-generator version

Version 4.1.2

OpenAPI declaration file content or url
openapi: 3.0.0
components:
    examples: {}
    headers: {}
    parameters: {}
    requestBodies: {}
    responses: {}
    schemas:
        MultiPropertiesSchema:
            properties:
                status:
                    type: integer
                    format: int32
                data:
                    items:
                        $ref: '#/components/schemas/ItemsSchema'
                    type: array
                message:
                    type: string
            type: object
            required:
                - status
            additionalProperties: false
        ItemsSchema:
            properties:
                name:
                    type: string
                additionalProperty:
                    type: string
                secondAdditionalProperty:
                    type: string
info:
    title: the test title
    version: '1'
    description: 'The test REST API'
    contact: {}
paths:
    '/example/get':
        get:
            operationId: GetExample
            responses:
                '200':
                    description: Ok
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
@spacether
Copy link
Contributor

Thank you for reporting this bug. Will ItemsSchema always be type object?
In your definition, when it is type object, the properties constraints apply, and if not then it can be any other type.

@spacether spacether linked a pull request Apr 8, 2024 that will close this issue
3 tasks
@spacether
Copy link
Contributor

This has been fixed in version 4.1.3

@spacether spacether added the bug Something isn't working label Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants