openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] component that refs another component doesn't work

Open spacether opened this issue 2 years ago • 2 comments

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

component that refs another component doesn't work This came up when working on https://github.com/OpenAPITools/openapi-generator/pull/12619

Feature: jsonschema.$ref

openapi-generator version

6.0.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: openapi 3.0.3 sample spec
  description: sample spec for testing openapi functionality, built from json schema
    tests for draft6
  version: 0.0.1
paths: {}
components:
  schemas:
    PropertyNamedRefThatIsNotAReference:
      properties:
        $ref:
          type: string
    ComponentRefsAnotherComponent:
      $ref: '#/components/schemas/PropertyNamedRefThatIsNotAReference'
Generation Details

Generate with python-experimental

Steps to reproduce

See above

Related issues/PRs

N/A

Suggest a fix

An import should be generated I think that this used to work

spacether avatar Jun 28 '22 22:06 spacether

EDIT: moved to https://github.com/OpenAPITools/openapi-json-schema-generator/issues/3 as my original comment is in fact a separate, unrelated issue and I don't want to cause confusion to anyone else reading this.

mikeknep avatar Jun 29 '22 01:06 mikeknep

@mikeknep can you make a separate issue for that? The property that you mention is a codegenProperty whereas the one that I am mentioning is a codegenModel so they work differently. Hmm this may be because Animal sees Age as an AnyTypeSchema but a Dog instance is a DynamicSchema instance but it should be let through because Age is a DictSchema. Why are you AllOf including Animal in Dog and Cat? Doing that is not adding any useful validation.

spacether avatar Jun 29 '22 02:06 spacether

This bug is also tracked here: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator/issues/126

spacether avatar Jan 23 '23 04:01 spacether

FYi if you want to use this it is working in the v2.0.0 release of openapi-json-schema-generator. That is where further development is being done on the python generator. Here is the definition of the component schema RefPet

    RefPet:
      $ref: '#/components/schemas/Pet'

And here is the generated class

from petstore_api.components.schema import pet
RefPet = pet.Pet

spacether avatar Apr 11 '23 07:04 spacether

If you want this to work use it from the new location

spacether avatar Jun 17 '23 01:06 spacether