question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not inherit all the classes mentioned in `allOf`

See original GitHub issue

Describe the bug It is not extending all the mentioned classes in the allOf attribute of the schema.

To Reproduce I am running this on the directory: https://github.com/AnalyticalGraphicsInc/czml-writer/tree/master/Schema. But it does not inherit all the classes as I mentioned above. For example, one of the schemas is as follows,

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://analyticalgraphicsinc.github.io/czml-writer/Schema/Color.json",
    "title": "Color",
    "description": "A color. The color can optionally vary over time.",
    "allOf": [
        { "$ref": "InterpolatableProperty.json" },
        { "$ref": "DeletableProperty.json" },
        { "$ref": "ValueProperties/RgbaValueProperty.json" },
        { "$ref": "ValueProperties/RgbafValueProperty.json" },
        { "$ref": "ValueProperties/ReferenceValueProperty.json" }
    ],
    "type": [
        "array",
        "object"
    ],
    "items": {
        "$ref": "#"
    },
    "properties": {
        "rgba": {
            "$ref": "Values/RgbaValue.json",
            "description": "The color specified as an array of color components `[Red, Green, Blue, Alpha]` where each component is an integer in the range 0-255."
        },
        "rgbaf": {
            "$ref": "Values/RgbafValue.json",
            "description": "The color specified as an array of color components `[Red, Green, Blue, Alpha]` where each component is a double in the range 0.0-1.0."
        },
        "reference": {
            "$ref": "Values/ReferenceValue.json",
            "description": "The color specified as a reference to another property."
        }
    }
}

It generates the class as follows:

# generated by datamodel-codegen:
#   filename:  Color.json
#   timestamp: 2021-03-29T05:46:25+00:00

from __future__ import annotations

from typing import Optional

from pydantic import BaseModel, Field

from . import Cylinder, LabelStyle


class Color(BaseModel):
    """
    A color. The color can optionally vary over time.
    """

    rgba: Optional[Cylinder.RgbaValue] = Field(
        None,
        description='The color specified as an array of color components `[Red, Green, Blue, Alpha]` where each component is an integer in the range 0-255.',
    )
    rgbaf: Optional[Cylinder.RgbafValue] = Field(
        None,
        description='The color specified as an array of color components `[Red, Green, Blue, Alpha]` where each component is a double in the range 0.0-1.0.',
    )
    reference: Optional[LabelStyle.ReferenceValue] = Field(
        None, description='The color specified as a reference to another property.'
    )

Expected behavior It should have inherited the classes DeletableProperty and InterpolatableProperty

Additional context Those classes have been generated and are residing in the same directory. It’s just that they are not being imported and inherited.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
rushabh-vcommented, Apr 4, 2021

Hi, works like a charm now 💯

Thanks for fixing it 😃

Is the naming to the extra class given by one of these PRs. For example Color1 in this comment. If yes, then in my opinion we can name it like _ClassName instead of ClassName1.

It’s only a suggestion, it’s okay if you think ClassName1 is better, it was just my opinion.

3reactions
rushabh-vcommented, Mar 31, 2021

Thanks for the super quick fix @koxudaxi 😃

Sure, just give me a minute, I’ll test it and come back to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to inherit in OpenAPI 3 using allOf in java
Although now that Foo class will contain all the properties of Bar, Foo isn't actually inheriting when we look at the java code...
Read more >
"extends"/"allOf" and schema inheritance - Google Groups
My view is that the "extends"/"allOf" behaviour is completely appropriate, and is inheritance in the purest sense. Any other behaviour added in the...
Read more >
Inheritance and Polymorphism - Swagger
In OpenAPI version 3, you do this with the allOf keyword: ... It is important that all the models mentioned below anyOf or...
Read more >
Inheritance - - OpenAlchemy
For columns, the main purpose of using inheritance through allOf is to re-use elements of a base column definition but customize certain properties....
Read more >
FileNet P8 5.5.x - Inheritance between classes - IBM
A subclass always inherits all of the properties of its superclass. You can add custom properties to the default superclass, such as document...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found